~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/loader/xnu.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
static int driverspackagenum = 0;
45
45
static int driversnum = 0;
46
46
int grub_xnu_is_64bit = 0;
 
47
int grub_xnu_darwin_version = 0;
47
48
 
48
49
grub_addr_t grub_xnu_heap_target_start = 0;
49
50
grub_size_t grub_xnu_heap_size = 0;
50
51
struct grub_relocator *grub_xnu_relocator;
51
52
 
52
53
static grub_err_t
53
 
grub_xnu_register_memory (char *prefix, int *suffix,
 
54
grub_xnu_register_memory (const char *prefix, int *suffix,
54
55
                          grub_addr_t addr, grub_size_t size);
55
56
grub_err_t
56
57
grub_xnu_heap_malloc (int size, void **src, grub_addr_t *target)
103
104
 
104
105
/* Compute the size of device tree in xnu format. */
105
106
static grub_size_t
106
 
grub_xnu_writetree_get_size (struct grub_xnu_devtree_key *start, char *name)
 
107
grub_xnu_writetree_get_size (struct grub_xnu_devtree_key *start,
 
108
                             const char *name)
107
109
{
108
110
  grub_size_t ret;
109
111
  struct grub_xnu_devtree_key *cur;
134
136
/* Write devtree in XNU format at curptr assuming the head is named NAME.*/
135
137
static void *
136
138
grub_xnu_writetree_toheap_real (void *curptr,
137
 
                                struct grub_xnu_devtree_key *start, char *name)
 
139
                                struct grub_xnu_devtree_key *start,
 
140
                                const char *name)
138
141
{
139
142
  struct grub_xnu_devtree_key *cur;
140
143
  int nkeys = 0, nvals = 0;
187
190
  /* And then the keys. Recursively use this function. */
188
191
  for (cur = start; cur; cur = cur->next)
189
192
    if (cur->datasize == -1)
190
 
      if (!(curptr = grub_xnu_writetree_toheap_real (curptr,
191
 
                                                     cur->first_child,
192
 
                                                     cur->name)))
193
 
        return 0;
 
193
      {
 
194
        curptr = grub_xnu_writetree_toheap_real (curptr,
 
195
                                                 cur->first_child,
 
196
                                                 cur->name);
 
197
        if (!curptr)
 
198
          return 0;
 
199
      }
194
200
  return curptr;
195
201
}
196
202
 
219
225
 
220
226
  driverkey = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*driverkey));
221
227
  if (! driverkey)
222
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't write device tree");
 
228
    return grub_errno;
223
229
  driverkey->name = grub_strdup ("DeviceTree");
224
230
  if (! driverkey->name)
225
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't write device tree");
 
231
    return grub_errno;
226
232
  driverkey->datasize = sizeof (*extdesc);
227
233
  driverkey->next = memorymap->first_child;
228
234
  memorymap->first_child = driverkey;
229
235
  driverkey->data = extdesc
230
236
    = (struct grub_xnu_extdesc *) grub_malloc (sizeof (*extdesc));
231
237
  if (! driverkey->data)
232
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't write device tree");
 
238
    return grub_errno;
233
239
 
234
240
  /* Allocate the space based on the size with dummy value. */
235
241
  *size = grub_xnu_writetree_get_size (grub_xnu_devtree_root, "/");
249
255
 
250
256
/* Find a key or value in parent key. */
251
257
struct grub_xnu_devtree_key *
252
 
grub_xnu_find_key (struct grub_xnu_devtree_key *parent, char *name)
 
258
grub_xnu_find_key (struct grub_xnu_devtree_key *parent, const char *name)
253
259
{
254
260
  struct grub_xnu_devtree_key *cur;
255
261
  for (cur = parent; cur; cur = cur->next)
259
265
}
260
266
 
261
267
struct grub_xnu_devtree_key *
262
 
grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
 
268
grub_xnu_create_key (struct grub_xnu_devtree_key **parent, const char *name)
263
269
{
264
270
  struct grub_xnu_devtree_key *ret;
265
271
  ret = grub_xnu_find_key (*parent, name);
267
273
    return ret;
268
274
  ret = (struct grub_xnu_devtree_key *) grub_zalloc (sizeof (*ret));
269
275
  if (! ret)
270
 
    {
271
 
      grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create key %s", name);
272
 
      return 0;
273
 
    }
 
276
    return 0;
274
277
  ret->name = grub_strdup (name);
275
278
  if (! ret->name)
276
279
    {
277
280
      grub_free (ret);
278
 
      grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create key %s", name);
279
281
      return 0;
280
282
    }
281
283
  ret->datasize = -1;
285
287
}
286
288
 
287
289
struct grub_xnu_devtree_key *
288
 
grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
 
290
grub_xnu_create_value (struct grub_xnu_devtree_key **parent, const char *name)
289
291
{
290
292
  struct grub_xnu_devtree_key *ret;
291
293
  ret = grub_xnu_find_key (*parent, name);
301
303
    }
302
304
  ret = (struct grub_xnu_devtree_key *) grub_zalloc (sizeof (*ret));
303
305
  if (! ret)
304
 
    {
305
 
      grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
306
 
      return 0;
307
 
    }
 
306
    return 0;
308
307
  ret->name = grub_strdup (name);
309
308
  if (! ret->name)
310
309
    {
311
310
      grub_free (ret);
312
 
      grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
313
311
      return 0;
314
312
    }
315
313
  ret->next = *parent;
349
347
  grub_addr_t loadaddr_target;
350
348
 
351
349
  if (argc < 1)
352
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
 
350
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
353
351
 
354
352
  grub_xnu_unload ();
355
353
 
356
 
  macho = grub_macho_open (args[0]);
 
354
  macho = grub_macho_open (args[0], 0);
357
355
  if (! macho)
358
356
    return grub_errno;
359
 
  if (! grub_macho_contains_macho32 (macho))
360
 
    {
361
 
      grub_macho_close (macho);
362
 
      return grub_error (GRUB_ERR_BAD_OS,
363
 
                         "kernel doesn't contain suitable 32-bit architecture");
364
 
    }
365
357
 
366
 
  err = grub_macho_size32 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS);
 
358
  err = grub_macho_size32 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS,
 
359
                           args[0]);
367
360
  if (err)
368
361
    {
369
362
      grub_macho_close (macho);
389
382
    }
390
383
 
391
384
  /* Load kernel. */
392
 
  err = grub_macho_load32 (macho, (char *) loadaddr - startcode,
393
 
                           GRUB_MACHO_NOBSS);
 
385
  err = grub_macho_load32 (macho, args[0], (char *) loadaddr - startcode,
 
386
                           GRUB_MACHO_NOBSS, &grub_xnu_darwin_version);
394
387
  if (err)
395
388
    {
396
389
      grub_macho_close (macho);
398
391
      return err;
399
392
    }
400
393
 
401
 
  grub_xnu_entry_point = grub_macho_get_entry_point32 (macho);
 
394
  grub_xnu_entry_point = grub_macho_get_entry_point32 (macho, args[0]);
402
395
  if (! grub_xnu_entry_point)
403
396
    {
404
397
      grub_macho_close (macho);
459
452
  grub_addr_t loadaddr_target;
460
453
 
461
454
  if (argc < 1)
462
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
 
455
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
463
456
 
464
457
  grub_xnu_unload ();
465
458
 
466
 
  macho = grub_macho_open (args[0]);
 
459
  macho = grub_macho_open (args[0], 1);
467
460
  if (! macho)
468
461
    return grub_errno;
469
 
  if (! grub_macho_contains_macho64 (macho))
470
 
    {
471
 
      grub_macho_close (macho);
472
 
      return grub_error (GRUB_ERR_BAD_OS,
473
 
                         "kernel doesn't contain suitable 64-bit architecture");
474
 
    }
475
462
 
476
 
  err = grub_macho_size64 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS);
 
463
  err = grub_macho_size64 (macho, &startcode, &endcode, GRUB_MACHO_NOBSS,
 
464
                           args[0]);
477
465
  if (err)
478
466
    {
479
467
      grub_macho_close (macho);
502
490
    }
503
491
 
504
492
  /* Load kernel. */
505
 
  err = grub_macho_load64 (macho, (char *) loadaddr - startcode,
506
 
                           GRUB_MACHO_NOBSS);
 
493
  err = grub_macho_load64 (macho, args[0], (char *) loadaddr - startcode,
 
494
                           GRUB_MACHO_NOBSS, &grub_xnu_darwin_version);
507
495
  if (err)
508
496
    {
509
497
      grub_macho_close (macho);
511
499
      return err;
512
500
    }
513
501
 
514
 
  grub_xnu_entry_point = grub_macho_get_entry_point64 (macho) & 0x0fffffff;
 
502
  grub_xnu_entry_point = grub_macho_get_entry_point64 (macho, args[0])
 
503
    & 0x0fffffff;
515
504
  if (! grub_xnu_entry_point)
516
505
    {
517
506
      grub_macho_close (macho);
562
551
/* Register a memory in a memory map under name PREFIXSUFFIX
563
552
   and increment SUFFIX. */
564
553
static grub_err_t
565
 
grub_xnu_register_memory (char *prefix, int *suffix,
 
554
grub_xnu_register_memory (const char *prefix, int *suffix,
566
555
                          grub_addr_t addr, grub_size_t size)
567
556
{
568
557
  struct grub_xnu_devtree_key *chosen;
571
560
  struct grub_xnu_extdesc *extdesc;
572
561
 
573
562
  if (! grub_xnu_heap_size)
574
 
    return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
 
563
    return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
575
564
 
576
565
  chosen = grub_xnu_create_key (&grub_xnu_devtree_root, "chosen");
577
566
  if (! chosen)
582
571
 
583
572
  driverkey = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*driverkey));
584
573
  if (! driverkey)
585
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't register memory");
 
574
    return grub_errno;
586
575
  if (suffix)
587
 
    {
588
 
      driverkey->name = grub_xasprintf ("%s%d", prefix, (*suffix)++);
589
 
      if (!driverkey->name)
590
 
        return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't register memory");
591
 
    }
 
576
    driverkey->name = grub_xasprintf ("%s%d", prefix, (*suffix)++);
592
577
  else
593
578
    driverkey->name = grub_strdup (prefix);
594
 
  if (! driverkey->name)
595
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't register extension");
 
579
  if (!driverkey->name)
 
580
    {
 
581
      grub_free (driverkey);
 
582
      return grub_errno;
 
583
    }
596
584
  driverkey->datasize = sizeof (*extdesc);
597
585
  driverkey->next = memorymap->first_child;
598
 
  memorymap->first_child = driverkey;
599
586
  driverkey->data = extdesc
600
587
    = (struct grub_xnu_extdesc *) grub_malloc (sizeof (*extdesc));
601
588
  if (! driverkey->data)
602
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't register extension");
 
589
    {
 
590
      grub_free (driverkey->name);
 
591
      grub_free (driverkey);
 
592
      return grub_errno;
 
593
    }
 
594
  memorymap->first_child = driverkey;
603
595
  extdesc->addr = addr;
604
596
  extdesc->size = (grub_uint32_t) size;
605
597
  return GRUB_ERR_NONE;
635
627
 
636
628
/* Load .kext. */
637
629
static grub_err_t
638
 
grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile)
 
630
grub_xnu_load_driver (char *infoplistname, grub_file_t binaryfile,
 
631
                      const char *filename)
639
632
{
640
633
  grub_macho_t macho;
641
634
  grub_err_t err;
660
653
  neededspace += namelen + 1;
661
654
 
662
655
  if (! grub_xnu_heap_size)
663
 
    return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
 
656
    return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
664
657
 
665
658
  /* Compute the needed space. */
666
659
  if (binaryfile)
667
660
    {
668
 
      macho = grub_macho_file (binaryfile);
669
 
      if (! macho || ! grub_macho_contains_macho32 (macho))
 
661
      macho = grub_macho_file (binaryfile, filename, grub_xnu_is_64bit);
 
662
      if (!macho)
 
663
        grub_file_close (binaryfile);
 
664
      else
670
665
        {
671
 
          if (macho)
672
 
            grub_macho_close (macho);
673
 
          return grub_error (GRUB_ERR_BAD_OS,
674
 
                             "extension doesn't contain suitable architecture");
 
666
          if (grub_xnu_is_64bit)
 
667
            machosize = grub_macho_filesize64 (macho);
 
668
          else
 
669
            machosize = grub_macho_filesize32 (macho);
675
670
        }
676
 
      if (grub_xnu_is_64bit)
677
 
        machosize = grub_macho_filesize64 (macho);
678
 
      else
679
 
        machosize = grub_macho_filesize32 (macho);
680
671
      neededspace += machosize;
681
672
    }
682
673
  else
714
705
      exthead->binaryaddr = buf_target + (buf - (grub_uint8_t *) buf0);
715
706
      exthead->binarysize = machosize;
716
707
      if (grub_xnu_is_64bit)
717
 
        err = grub_macho_readfile64 (macho, buf);
 
708
        err = grub_macho_readfile64 (macho, filename, buf);
718
709
      else
719
 
        err = grub_macho_readfile32 (macho, buf);
 
710
        err = grub_macho_readfile32 (macho, filename, buf);
720
711
      if (err)
721
712
        {
722
713
          grub_macho_close (macho);
736
727
          != (grub_ssize_t) (infoplistsize))
737
728
        {
738
729
          grub_file_close (infoplist);
739
 
          grub_error_push ();
740
 
          return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s: ",
741
 
                             infoplistname);
 
730
          if (!grub_errno)
 
731
            grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
 
732
                        infoplistname);
 
733
          return grub_errno;
742
734
        }
743
735
      grub_file_close (infoplist);
744
736
      buf[infoplistsize] = 0;
773
765
  int narchs, i;
774
766
 
775
767
  if (argc != 1)
776
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
 
768
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
777
769
 
778
770
  if (! grub_xnu_heap_size)
779
 
    return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
 
771
    return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
780
772
 
781
773
  file = grub_file_open (args[0]);
782
774
  if (! file)
783
 
    return grub_error (GRUB_ERR_FILE_NOT_FOUND,
784
 
                       "couldn't load driver package");
 
775
    return grub_errno;
785
776
 
786
777
  /* Sometimes caches are fat binary. Errgh. */
787
778
  if (grub_file_read (file, &head, sizeof (head))
790
781
      /* I don't know the internal structure of package but
791
782
         can hardly imagine a valid package shorter than 20 bytes. */
792
783
      grub_file_close (file);
793
 
      grub_error_push ();
794
 
      return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
 
784
      if (!grub_errno)
 
785
        grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
 
786
      return grub_errno;
795
787
    }
796
788
 
797
789
  /* Find the corresponding architecture. */
802
794
      if (! archs)
803
795
        {
804
796
          grub_file_close (file);
805
 
          grub_error_push ();
806
 
          return grub_error (GRUB_ERR_OUT_OF_MEMORY,
807
 
                             "couldn't read file %s", args[0]);
 
797
          return grub_errno;
808
798
 
809
799
        }
810
800
      if (grub_file_read (file, archs,
812
802
          != (grub_ssize_t) sizeof(struct grub_macho_fat_arch) * narchs)
813
803
        {
814
804
          grub_free (archs);
815
 
          grub_error_push ();
816
 
          return grub_error (GRUB_ERR_READ_ERROR, "cannot read fat header");
 
805
          if (!grub_errno)
 
806
            grub_error (GRUB_ERR_READ_ERROR, N_("premature end of file %s"),
 
807
                        args[0]);
 
808
          return grub_errno;
817
809
        }
818
810
      for (i = 0; i < narchs; i++)
819
811
        {
865
857
  if (grub_file_read (file, loadto, readlen) != (grub_ssize_t) (readlen))
866
858
    {
867
859
      grub_file_close (file);
868
 
      grub_error_push ();
869
 
      return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
 
860
      if (!grub_errno)
 
861
        grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
 
862
      return grub_errno;
870
863
    }
871
864
  grub_file_close (file);
872
865
 
886
879
  grub_size_t size;
887
880
 
888
881
  if (argc != 1)
889
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
 
882
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
890
883
 
891
884
  if (! grub_xnu_heap_size)
892
 
    return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
 
885
    return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
893
886
 
894
887
  file = grub_file_open (args[0]);
895
888
  if (! file)
896
 
    return grub_error (GRUB_ERR_FILE_NOT_FOUND,
897
 
                       "couldn't load ramdisk");
 
889
    return grub_errno;
898
890
 
899
891
  err = grub_xnu_align_heap (GRUB_XNU_PAGESIZE);
900
892
  if (err)
905
897
  err = grub_xnu_heap_malloc (size, &loadto, &loadto_target);
906
898
  if (err)
907
899
    return err;
908
 
  if (grub_file_read (file, loadto, size)
909
 
      != (grub_ssize_t) (size))
 
900
  if (grub_file_read (file, loadto, size) != (grub_ssize_t) (size))
910
901
    {
911
902
      grub_file_close (file);
912
 
      grub_error_push ();
913
 
      return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[0]);
 
903
      if (!grub_errno)
 
904
        grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), args[0]);
 
905
      return grub_errno;
914
906
    }
915
907
  return grub_xnu_register_memory ("RAMDisk", 0, loadto_target, size);
916
908
}
918
910
/* Returns true if the kext should be loaded according to plist
919
911
   and osbundlereq. Also fill BINNAME. */
920
912
static int
921
 
grub_xnu_check_os_bundle_required (char *plistname, char *osbundlereq,
 
913
grub_xnu_check_os_bundle_required (char *plistname,
 
914
                                   const char *osbundlereq,
922
915
                                   char **binname)
923
916
{
924
917
  grub_file_t file;
933
926
 
934
927
  file = grub_file_open (plistname);
935
928
  if (! file)
936
 
    {
937
 
      grub_file_close (file);
938
 
      grub_error_push ();
939
 
      grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", plistname);
940
 
      return 0;
941
 
    }
 
929
    return 0;
942
930
 
943
931
  size = grub_file_size (file);
944
932
  buf = grub_malloc (size);
945
933
  if (! buf)
946
934
    {
947
935
      grub_file_close (file);
948
 
      grub_error_push ();
949
 
      grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't read file %s", plistname);
950
936
      return 0;
951
937
    }
952
938
  if (grub_file_read (file, buf, size) != (grub_ssize_t) (size))
953
939
    {
954
940
      grub_file_close (file);
955
 
      grub_error_push ();
956
 
      grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", plistname);
 
941
      if (!grub_errno)
 
942
        grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), plistname);
957
943
      return 0;
958
944
    }
959
945
  grub_file_close (file);
1033
1019
 
1034
1020
/* Load all loadable kexts placed under DIRNAME and matching OSBUNDLEREQUIRED */
1035
1021
grub_err_t
1036
 
grub_xnu_scan_dir_for_kexts (char *dirname, char *osbundlerequired,
 
1022
grub_xnu_scan_dir_for_kexts (char *dirname, const char *osbundlerequired,
1037
1023
                             int maxrecursion)
1038
1024
{
1039
1025
  grub_device_t dev;
1075
1061
  }
1076
1062
 
1077
1063
  if (! grub_xnu_heap_size)
1078
 
    return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
 
1064
    return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
1079
1065
 
1080
1066
  device_name = grub_file_get_device_name (dirname);
1081
1067
  dev = grub_device_open (device_name);
1099
1085
 
1100
1086
/* Load extension DIRNAME. (extensions are directories in xnu) */
1101
1087
grub_err_t
1102
 
grub_xnu_load_kext_from_dir (char *dirname, char *osbundlerequired,
 
1088
grub_xnu_load_kext_from_dir (char *dirname, const char *osbundlerequired,
1103
1089
                             int maxrecursion)
1104
1090
{
1105
1091
  grub_device_t dev;
1147
1133
 
1148
1134
  newdirname = grub_malloc (grub_strlen (dirname) + 20);
1149
1135
  if (! newdirname)
1150
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY, "couldn't allocate buffer");
 
1136
    return grub_errno;
1151
1137
  grub_strcpy (newdirname, dirname);
1152
1138
  newdirname[grub_strlen (dirname)] = '/';
1153
1139
  newdirname[grub_strlen (dirname) + 1] = 0;
1193
1179
                grub_errno = GRUB_ERR_NONE;
1194
1180
 
1195
1181
              /* Load the extension. */
1196
 
              grub_xnu_load_driver (plistname, binfile);
 
1182
              grub_xnu_load_driver (plistname, binfile,
 
1183
                                    binname);
1197
1184
              grub_free (binname);
1198
1185
              grub_free (binsuffix);
1199
1186
            }
1200
1187
          else
1201
1188
            {
1202
1189
              grub_dprintf ("xnu", "%s:0\n", plistname);
1203
 
              grub_xnu_load_driver (plistname, 0);
 
1190
              grub_xnu_load_driver (plistname, 0, 0);
1204
1191
            }
1205
1192
        }
1206
1193
      grub_free (plistname);
1223
1210
  grub_file_t binfile = 0;
1224
1211
 
1225
1212
  if (! grub_xnu_heap_size)
1226
 
    return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
 
1213
    return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
1227
1214
 
1228
1215
  if (argc == 2)
1229
1216
    {
1232
1219
        {
1233
1220
          binfile = grub_file_open (args[1]);
1234
1221
          if (! binfile)
1235
 
            {
1236
 
              grub_error (GRUB_ERR_BAD_OS, "can't open file");
1237
 
              return GRUB_ERR_NONE;
1238
 
            }
 
1222
            return grub_errno;
1239
1223
        }
1240
1224
      return grub_xnu_load_driver (grub_strcmp (args[0], "-") ? args[0] : 0,
1241
 
                                   binfile);
 
1225
                                   binfile, args[1]);
1242
1226
    }
1243
1227
 
1244
1228
  /* load kext normally. */
1245
1229
  if (argc == 1)
1246
1230
    return grub_xnu_load_kext_from_dir (args[0], 0, 10);
1247
1231
 
1248
 
  return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
 
1232
  return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
1249
1233
}
1250
1234
 
1251
1235
/* Load a directory containing kexts. */
1257
1241
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "directory name required");
1258
1242
 
1259
1243
  if (! grub_xnu_heap_size)
1260
 
    return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
 
1244
    return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
1261
1245
 
1262
1246
  if (argc == 1)
1263
1247
    return grub_xnu_scan_dir_for_kexts (args[0],
1268
1252
      char *osbundlerequired = grub_strdup (args[1]), *ptr;
1269
1253
      grub_err_t err;
1270
1254
      if (! osbundlerequired)
1271
 
        return grub_error (GRUB_ERR_OUT_OF_MEMORY,
1272
 
                           "couldn't allocate string temporary space");
 
1255
        return grub_errno;
1273
1256
      for (ptr = osbundlerequired; *ptr; ptr++)
1274
1257
        *ptr = grub_tolower (*ptr);
1275
1258
      err = grub_xnu_scan_dir_for_kexts (args[0], osbundlerequired, 10);
1387
1370
 
1388
1371
static const struct grub_arg_option xnu_splash_cmd_options[] =
1389
1372
  {
1390
 
    {"mode", 'm', 0, "Background image mode.", "stretch|normal",
 
1373
    {"mode", 'm', 0, N_("Background image mode."), N_("stretch|normal"),
1391
1374
     ARG_TYPE_STRING},
1392
1375
    {0, 0, 0, 0, 0, 0}
1393
1376
  };
1398
1381
{
1399
1382
  grub_err_t err;
1400
1383
  if (argc != 1)
1401
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
 
1384
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
1402
1385
 
1403
1386
  if (! grub_xnu_heap_size)
1404
 
    return grub_error (GRUB_ERR_BAD_OS, "no xnu kernel loaded");
 
1387
    return grub_error (GRUB_ERR_BAD_OS, N_("you need to load the kernel first"));
1405
1388
 
1406
1389
  if (ctxt->state[XNU_SPLASH_CMD_ARGINDEX_MODE].set &&
1407
1390
      grub_strcmp (ctxt->state[XNU_SPLASH_CMD_ARGINDEX_MODE].arg,
1424
1407
                     int argc, char *args[])
1425
1408
{
1426
1409
  if (argc != 1)
1427
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
 
1410
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
1428
1411
 
1429
1412
  return grub_xnu_resume (args[0]);
1430
1413
}
1461
1444
  cmd_kext = grub_register_command ("xnu_kext", grub_cmd_xnu_kext, 0,
1462
1445
                                    N_("Load XNU extension."));
1463
1446
  cmd_kextdir = grub_register_command ("xnu_kextdir", grub_cmd_xnu_kextdir,
 
1447
                                       /* TRANSLATORS: OSBundleRequired is a
 
1448
                                          variable name in xnu extensions
 
1449
                                          manifests. It behaves mostly like
 
1450
                                          GNU/Linux runlevels.
 
1451
                                       */
1464
1452
                                       N_("DIRECTORY [OSBundleRequired]"),
 
1453
                                       /* TRANSLATORS: There are many extensions
 
1454
                                          in extension directory.  */
1465
1455
                                       N_("Load XNU extension directory."));
1466
1456
  cmd_ramdisk = grub_register_command ("xnu_ramdisk", grub_cmd_xnu_ramdisk, 0,
1467
 
                                       "Load XNU ramdisk. "
1468
 
                                       "It will be seen as md0.");
 
1457
   /* TRANSLATORS: ramdisk here isn't identifier. It can be translated.  */
 
1458
                                       N_("Load XNU ramdisk. "
 
1459
                                          "It will be available in OS as md0."));
1469
1460
  cmd_splash = grub_register_extcmd ("xnu_splash",
1470
1461
                                     grub_cmd_xnu_splash, 0, 0,
1471
1462
                                     N_("Load a splash image for XNU."),
1473
1464
 
1474
1465
#ifndef GRUB_MACHINE_EMU
1475
1466
  cmd_resume = grub_register_command ("xnu_resume", grub_cmd_xnu_resume,
1476
 
                                      0, N_("Load XNU hibernate image."));
 
1467
                                      0, N_("Load an image of hibernated"
 
1468
                                            " XNU."));
1477
1469
#endif
1478
1470
 
1479
1471
  grub_cpu_xnu_init ();