Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / util / grub-mkrescue.c
blobe02340f06f0000381686429665b42a7f87fad2a5
1 /*
2 * Make GRUB rescue image
4 * GRUB -- GRand Unified Bootloader
5 * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
7 * GRUB is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * GRUB is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 #include <config.h>
23 #include <grub/util/install.h>
24 #include <grub/util/misc.h>
25 #include <grub/emu/exec.h>
26 #include <grub/emu/config.h>
27 #include <grub/emu/hostdisk.h>
28 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
29 #pragma GCC diagnostic ignored "-Wmissing-declarations"
30 #include <argp.h>
31 #pragma GCC diagnostic error "-Wmissing-prototypes"
32 #pragma GCC diagnostic error "-Wmissing-declarations"
34 #include <sys/types.h>
35 #include <sys/wait.h>
37 #include <string.h>
38 #include <time.h>
40 static char *source_dirs[GRUB_INSTALL_PLATFORM_MAX];
41 static char *rom_directory;
42 static char *label_font;
43 static char *label_color;
44 static char *label_bgcolor;
45 static char *product_name;
46 static char *product_version;
47 static int xorriso_tail_argc;
48 static int xorriso_tail_arg_alloc;
49 static char **xorriso_tail_argv;
50 static char *output_image;
51 static char *xorriso;
52 static char *boot_grub;
53 static int xorriso_argc;
54 static int xorriso_arg_alloc;
55 static char **xorriso_argv;
56 static char *iso_uuid;
57 static char *iso9660_dir;
59 static void
60 xorriso_push (const char *val)
62 if (xorriso_arg_alloc <= xorriso_argc + 1)
64 xorriso_arg_alloc = 2 * (4 + xorriso_argc);
65 xorriso_argv = xrealloc (xorriso_argv,
66 sizeof (xorriso_argv[0])
67 * xorriso_arg_alloc);
69 xorriso_argv[xorriso_argc++] = xstrdup (val);
72 static void
73 xorriso_link (const char *from, const char *to)
75 char *tof = grub_util_path_concat (2, iso9660_dir, to);
76 char *val = xasprintf ("%s=%s", from, tof);
77 xorriso_push (val);
78 free (val);
79 free (tof);
82 enum
84 OPTION_OUTPUT = 'o',
85 OPTION_ROM_DIRECTORY = 0x301,
86 OPTION_XORRISO,
87 OPTION_GLUE_EFI,
88 OPTION_RENDER_LABEL,
89 OPTION_LABEL_FONT,
90 OPTION_LABEL_COLOR,
91 OPTION_LABEL_BGCOLOR,
92 OPTION_PRODUCT_NAME,
93 OPTION_PRODUCT_VERSION,
94 OPTION_SPARC_BOOT,
95 OPTION_ARCS_BOOT
98 static struct argp_option options[] = {
99 GRUB_INSTALL_OPTIONS,
100 {"output", 'o', N_("FILE"),
101 0, N_("save output in FILE [required]"), 2},
102 {"rom-directory", OPTION_ROM_DIRECTORY, N_("DIR"),
103 0, N_("save ROM images in DIR [optional]"), 2},
104 {"xorriso", OPTION_XORRISO, N_("FILE"),
105 /* TRANSLATORS: xorriso is a program for creating ISOs and burning CDs. */
106 0, N_("use FILE as xorriso [optional]"), 2},
107 {"grub-glue-efi", OPTION_GLUE_EFI, N_("FILE"), OPTION_HIDDEN, 0, 2},
108 {"grub-render-label", OPTION_RENDER_LABEL, N_("FILE"), OPTION_HIDDEN, 0, 2},
109 {"label-font", OPTION_LABEL_FONT, N_("FILE"), 0, N_("use FILE as font for label"), 2},
110 {"label-color", OPTION_LABEL_COLOR, N_("COLOR"), 0, N_("use COLOR for label"), 2},
111 {"label-bgcolor", OPTION_LABEL_BGCOLOR, N_("COLOR"), 0, N_("use COLOR for label background"), 2},
112 {"product-name", OPTION_PRODUCT_NAME, N_("STRING"), 0, N_("use STRING as product name"), 2},
113 {"product-version", OPTION_PRODUCT_VERSION, N_("STRING"), 0, N_("use STRING as product version"), 2},
114 {"sparc-boot", OPTION_SPARC_BOOT, 0, 0, N_("enable sparc boot. Disables HFS+, APM, ARCS and boot as disk image for i386-pc"), 2},
115 {"arcs-boot", OPTION_ARCS_BOOT, 0, 0, N_("enable ARCS (big-endian mips machines, mostly SGI) boot. Disables HFS+, APM, sparc64 and boot as disk image for i386-pc"), 2},
116 {0, 0, 0, 0, 0, 0}
119 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
121 static char *
122 help_filter (int key, const char *text, void *input __attribute__ ((unused)))
124 switch (key)
126 case ARGP_KEY_HELP_PRE_DOC:
127 /* TRANSLATORS: it generates one single image which is bootable through any method. */
128 return strdup (_("Make GRUB CD-ROM, disk, pendrive and floppy bootable image."));
129 case ARGP_KEY_HELP_POST_DOC:
131 char *p1, *out;
133 p1 = xasprintf (_("Generates a bootable CD/USB/floppy image. Arguments other than options to this program"
134 " are passed to xorriso, and indicate source files, source directories, or any of the "
135 "mkisofs options listed by the output of `%s'."), "xorriso -as mkisofs -help");
136 out = xasprintf ("%s\n\n%s\n\n%s", p1,
137 _("Option -- switches to native xorriso command mode."),
138 _("Mail xorriso support requests to <bug-xorriso@gnu.org>."));
139 free (p1);
140 return out;
142 default:
143 return grub_install_help_filter (key, text, input);
147 #pragma GCC diagnostic error "-Wformat-nonliteral"
149 enum {
150 SYS_AREA_AUTO,
151 SYS_AREA_COMMON,
152 SYS_AREA_SPARC,
153 SYS_AREA_ARCS
154 } system_area = SYS_AREA_AUTO;
156 static error_t
157 argp_parser (int key, char *arg, struct argp_state *state)
159 if (grub_install_parse (key, arg))
160 return 0;
161 switch (key)
163 case OPTION_OUTPUT:
164 free (output_image);
165 output_image = xstrdup (arg);
166 return 0;
167 case OPTION_ROM_DIRECTORY:
168 free (rom_directory);
169 rom_directory = xstrdup (arg);
170 return 0;
173 FIXME:
174 # Intentionally undocumented
175 --grub-mkimage-extra)
176 mkimage_extra_arg="$mkimage_extra_arg `argument $option "$@"`"; shift ;;
177 --grub-mkimage-extra=*)
178 mkimage_extra_arg="$mkimage_extra_arg `echo "$option" | sed 's/--grub-mkimage-extra=//'`" ;;
180 case OPTION_SPARC_BOOT:
181 system_area = SYS_AREA_SPARC;
182 return 0;
183 case OPTION_ARCS_BOOT:
184 system_area = SYS_AREA_ARCS;
185 return 0;
186 case OPTION_PRODUCT_NAME:
187 free (product_name);
188 product_name = xstrdup (arg);
189 return 0;
190 case OPTION_PRODUCT_VERSION:
191 free (product_version);
192 product_version = xstrdup (arg);
193 return 0;
194 /* Accept and ignore for compatibility. */
195 case OPTION_GLUE_EFI:
196 case OPTION_RENDER_LABEL:
197 return 0;
198 case OPTION_LABEL_FONT:
199 free (label_font);
200 label_font = xstrdup (arg);
201 return 0;
203 case OPTION_LABEL_COLOR:
204 free (label_color);
205 label_color = xstrdup (arg);
206 return 0;
208 case OPTION_LABEL_BGCOLOR:
209 free (label_bgcolor);
210 label_bgcolor = xstrdup (arg);
211 return 0;
213 case OPTION_XORRISO:
214 free (xorriso);
215 xorriso = xstrdup (arg);
216 return 0;
218 case ARGP_KEY_ARG:
219 if (xorriso_tail_arg_alloc <= xorriso_tail_argc)
221 xorriso_tail_arg_alloc = 2 * (4 + xorriso_tail_argc);
222 xorriso_tail_argv = xrealloc (xorriso_tail_argv,
223 sizeof (xorriso_tail_argv[0])
224 * xorriso_tail_arg_alloc);
226 xorriso_tail_argv[xorriso_tail_argc++] = xstrdup (arg);
227 return 0;
228 default:
229 return ARGP_ERR_UNKNOWN;
233 struct argp argp = {
234 options, argp_parser, N_("[OPTION] SOURCE..."),
235 NULL, NULL, help_filter, NULL
238 static void
239 write_part (FILE *f, const char *srcdir)
241 FILE *in;
242 char *inname = grub_util_path_concat (2, srcdir, "partmap.lst");
243 char buf[260];
244 in = grub_util_fopen (inname, "rb");
245 if (!in)
246 return;
247 while (fgets (buf, 256, in))
249 char *ptr;
250 for (ptr = buf + strlen (buf) - 1;
251 ptr >= buf && (*ptr == '\n' || *ptr == '\r');
252 ptr--);
253 ptr[1] = '\0';
254 fprintf (f, "insmod %s\n", buf);
256 fclose (in);
259 static void
260 make_image_abs (enum grub_install_plat plat,
261 const char *mkimage_target,
262 const char *output)
264 char *load_cfg;
265 FILE *load_cfg_f;
267 if (!source_dirs[plat])
268 return;
270 grub_util_info (N_("enabling %s support ..."),
271 mkimage_target);
273 load_cfg = grub_util_make_temporary_file ();
275 load_cfg_f = grub_util_fopen (load_cfg, "wb");
276 fprintf (load_cfg_f, "search --fs-uuid --set=root %s\n", iso_uuid);
277 fprintf (load_cfg_f, "set prefix=(${root})/boot/grub\n");
279 write_part (load_cfg_f, source_dirs[plat]);
280 fclose (load_cfg_f);
282 grub_install_push_module ("search");
283 grub_install_push_module ("iso9660");
284 grub_install_make_image_wrap (source_dirs[plat], "/boot/grub", output,
285 0, load_cfg,
286 mkimage_target, 0);
287 grub_install_pop_module ();
288 grub_install_pop_module ();
289 grub_util_unlink (load_cfg);
292 static void
293 make_image (enum grub_install_plat plat,
294 const char *mkimage_target,
295 const char *output_sub)
297 char *out = grub_util_path_concat (2, boot_grub, output_sub);
298 make_image_abs (plat, mkimage_target, out);
299 free (out);
302 static void
303 make_image_fwdisk_abs (enum grub_install_plat plat,
304 const char *mkimage_target,
305 const char *output)
307 char *load_cfg;
308 FILE *load_cfg_f;
310 if (!source_dirs[plat])
311 return;
313 grub_util_info (N_("enabling %s support ..."),
314 mkimage_target);
316 load_cfg = grub_util_make_temporary_file ();
318 load_cfg_f = grub_util_fopen (load_cfg, "wb");
319 write_part (load_cfg_f, source_dirs[plat]);
320 fclose (load_cfg_f);
322 grub_install_push_module ("iso9660");
323 grub_install_make_image_wrap (source_dirs[plat], "()/boot/grub", output,
324 0, load_cfg, mkimage_target, 0);
325 grub_install_pop_module ();
328 static int
329 check_xorriso (const char *val)
331 const char *argv[5];
332 int fd;
333 pid_t pid;
334 FILE *mdadm;
335 char *buf = NULL;
336 size_t len = 0;
337 int ret = 0;
339 argv[0] = xorriso;
340 argv[1] = "-as";
341 argv[2] = "mkisofs";
342 argv[3] = "-help";
343 argv[4] = NULL;
345 pid = grub_util_exec_pipe_stderr (argv, &fd);
347 if (!pid)
348 return 0;
350 /* Parent. Read mdadm's output. */
351 mdadm = fdopen (fd, "r");
352 if (! mdadm)
353 return 0;
355 while (getline (&buf, &len, mdadm) > 0)
357 if (grub_strstr (buf, val))
358 ret = 1;
361 close (fd);
362 waitpid (pid, NULL, 0);
363 free (buf);
364 return ret;
367 static void
368 make_image_fwdisk (enum grub_install_plat plat,
369 const char *mkimage_target,
370 const char *output_sub)
372 char *out = grub_util_path_concat (2, boot_grub, output_sub);
373 make_image_fwdisk_abs (plat, mkimage_target, out);
374 free (out);
378 main (int argc, char *argv[])
380 char *romdir;
381 char *sysarea_img = NULL;
382 const char *pkgdatadir;
384 grub_util_host_init (&argc, &argv);
385 grub_util_disable_fd_syncs ();
387 pkgdatadir = grub_util_get_pkgdatadir ();
389 product_name = xstrdup (PACKAGE_NAME);
390 product_version = xstrdup (PACKAGE_VERSION);
391 xorriso = xstrdup ("xorriso");
392 label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2");
394 argp_parse (&argp, argc, argv, 0, 0, 0);
396 if (!output_image)
397 grub_util_error ("%s", _("output file must be specified"));
399 grub_init_all ();
400 grub_hostfs_init ();
401 grub_host_init ();
403 xorriso_push (xorriso);
404 xorriso_push ("-as");
405 xorriso_push ("mkisofs");
406 xorriso_push ("-graft-points");
408 iso9660_dir = grub_util_make_temporary_dir ();
409 grub_util_info ("temporary iso9660 dir is `%s'", iso9660_dir);
410 boot_grub = grub_util_path_concat (3, iso9660_dir, "boot", "grub");
411 grub_install_mkdir_p (boot_grub);
412 romdir = grub_util_path_concat (2, boot_grub, "roms");
413 grub_util_mkdir (romdir);
415 if (!grub_install_source_directory)
417 const char *pkglibdir = grub_util_get_pkglibdir ();
418 enum grub_install_plat plat;
420 for (plat = 0; plat < GRUB_INSTALL_PLATFORM_MAX; plat++)
422 char *platdir = grub_util_path_concat (2, pkglibdir,
423 grub_install_get_platform_name (plat));
425 if (!grub_util_is_directory (platdir))
427 free (platdir);
428 continue;
430 source_dirs[plat] = platdir;
431 grub_install_copy_files (platdir,
432 boot_grub, plat);
435 else
437 enum grub_install_plat plat;
438 plat = grub_install_get_target (grub_install_source_directory);
439 grub_install_copy_files (grub_install_source_directory,
440 boot_grub, plat);
441 source_dirs[plat] = xstrdup (grub_install_source_directory);
443 if (system_area == SYS_AREA_AUTO || grub_install_source_directory)
445 if (source_dirs[GRUB_INSTALL_PLATFORM_I386_PC]
446 || source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275]
447 || source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
448 || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
449 || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
450 || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
451 || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
452 system_area = SYS_AREA_COMMON;
453 else if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275])
454 system_area = SYS_AREA_SPARC;
455 else if (source_dirs[GRUB_INSTALL_PLATFORM_MIPS_ARC])
456 system_area = SYS_AREA_ARCS;
459 /* obtain date-based UUID. */
461 time_t tim;
462 struct tm *tmm;
463 tim = time (NULL);
464 tmm = gmtime (&tim);
465 iso_uuid = xmalloc (55);
466 grub_snprintf (iso_uuid, 50,
467 "%04d-%02d-%02d-%02d-%02d-%02d-00",
468 tmm->tm_year + 1900,
469 tmm->tm_mon + 1,
470 tmm->tm_mday,
471 tmm->tm_hour,
472 tmm->tm_min,
473 tmm->tm_sec);
476 char *uuid_out = xmalloc (strlen (iso_uuid) + 1 + 40);
477 char *optr;
478 const char *iptr;
479 optr = grub_stpcpy (uuid_out, "--modification-date=");
480 for (iptr = iso_uuid; *iptr; iptr++)
481 if (*iptr != '-')
482 *optr++ = *iptr;
483 *optr = '\0';
484 xorriso_push (uuid_out);
485 free (uuid_out);
488 /* build BIOS core.img. */
489 if (source_dirs[GRUB_INSTALL_PLATFORM_I386_PC])
491 char *load_cfg;
492 FILE *load_cfg_f;
493 char *output = grub_util_path_concat (3, boot_grub, "i386-pc", "eltorito.img");
494 load_cfg = grub_util_make_temporary_file ();
496 grub_util_info (N_("enabling %s support ..."), "BIOS");
497 load_cfg_f = grub_util_fopen (load_cfg, "wb");
498 write_part (load_cfg_f, source_dirs[GRUB_INSTALL_PLATFORM_I386_PC]);
499 fclose (load_cfg_f);
501 grub_install_push_module ("biosdisk");
502 grub_install_push_module ("iso9660");
503 grub_install_make_image_wrap (source_dirs[GRUB_INSTALL_PLATFORM_I386_PC],
504 "/boot/grub", output,
505 0, load_cfg,
506 "i386-pc-eltorito", 0);
508 xorriso_push ("-b");
509 xorriso_push ("boot/grub/i386-pc/eltorito.img");
510 xorriso_push ("-no-emul-boot");
511 xorriso_push ("-boot-load-size");
512 xorriso_push ("4");
513 xorriso_push ("-boot-info-table");
514 if (system_area == SYS_AREA_COMMON)
516 if (check_xorriso ("grub2-boot-info"))
518 char *boot_hybrid = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_I386_PC],
519 "boot_hybrid.img");
520 xorriso_push ("--grub2-boot-info");
521 xorriso_push ("--grub2-mbr");
522 xorriso_push (boot_hybrid);
524 else
526 FILE *sa, *bi;
527 size_t sz;
528 char buf[512];
529 char *bin = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_I386_PC],
530 "boot.img");
531 grub_util_warn ("%s", _("Your xorriso doesn't support `--grub2-boot-info'. Some features are disabled. Please use xorriso 1.2.9 or later."));
532 sysarea_img = grub_util_make_temporary_file ();
533 sa = grub_util_fopen (sysarea_img, "wb");
534 if (!sa)
535 grub_util_error (_("cannot open `%s': %s"), sysarea_img,
536 strerror (errno));
537 bi = grub_util_fopen (bin, "rb");
538 if (!bi)
539 grub_util_error (_("cannot open `%s': %s"), bin,
540 strerror (errno));
541 if (fread (buf, 1, 512, bi) != 512)
542 grub_util_error (_("cannot read `%s': %s"), bin,
543 strerror (errno));
544 fclose (bi);
545 fwrite (buf, 1, 512, sa);
547 grub_install_make_image_wrap_file (source_dirs[GRUB_INSTALL_PLATFORM_I386_PC],
548 "/boot/grub", sa, sysarea_img,
549 0, load_cfg,
550 "i386-pc", 0);
551 sz = ftello (sa);
552 fflush (sa);
553 grub_util_fd_sync (fileno (sa));
554 fclose (sa);
556 if (sz > 32768)
558 grub_util_warn ("%s", _("Your xorriso doesn't support `--grub2-boot-info'. Your core image is too big. Boot as disk is disabled. Please use xorriso 1.2.9 or later."));
560 else
562 xorriso_push ("-G");
563 xorriso_push (sysarea_img);
567 grub_install_pop_module ();
568 grub_install_pop_module ();
571 /** build multiboot core.img */
572 grub_install_push_module ("pata");
573 grub_install_push_module ("ahci");
574 grub_install_push_module ("at_keyboard");
575 make_image (GRUB_INSTALL_PLATFORM_I386_MULTIBOOT, "i386-multiboot", "i386-multiboot/core.elf");
576 grub_install_pop_module ();
577 grub_install_pop_module ();
578 grub_install_pop_module ();
580 make_image_fwdisk (GRUB_INSTALL_PLATFORM_I386_IEEE1275, "i386-ieee1275", "ofwx86.elf");
582 char *core_services = NULL;
584 if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
585 || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]
586 || source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275])
588 char *mach_ker, *sv, *label, *label_text;
589 FILE *f;
590 core_services = grub_util_path_concat (4, iso9660_dir, "System", "Library", "CoreServices");
591 grub_install_mkdir_p (core_services);
593 mach_ker = grub_util_path_concat (2, iso9660_dir, "mach_kernel");
594 f = grub_util_fopen (mach_ker, "wb");
595 fclose (f);
596 free (mach_ker);
598 sv = grub_util_path_concat (2, core_services, "SystemVersion.plist");
599 f = grub_util_fopen (sv, "wb");
600 fprintf (f, "<plist version=\"1.0\">\n"
601 "<dict>\n"
602 " <key>ProductBuildVersion</key>\n"
603 " <string></string>\n"
604 " <key>ProductName</key>\n"
605 " <string>%s</string>\n"
606 " <key>ProductVersion</key>\n"
607 " <string>%s</string>\n"
608 "</dict>\n"
609 "</plist>\n", product_name, product_version);
610 fclose (f);
611 free (sv);
612 label = grub_util_path_concat (2, core_services, ".disk_label");
613 char *label_string = xasprintf ("%s %s", product_name, product_version);
614 grub_util_render_label (label_font, label_bgcolor ? : "white",
615 label_color ? : "black", label_string, label);
616 free (label);
617 label_text = grub_util_path_concat (2, core_services, ".disk_label.contentDetails");
618 f = grub_util_fopen (label_text, "wb");
619 fprintf (f, "%s\n", label_string);
620 fclose (f);
621 free (label_string);
622 free (label_text);
623 if (system_area == SYS_AREA_COMMON)
625 xorriso_push ("-hfsplus");
626 xorriso_push ("-apm-block-size");
627 xorriso_push ("2048");
628 xorriso_push ("-hfsplus-file-creator-type");
629 xorriso_push ("chrp");
630 xorriso_push ("tbxj");
631 xorriso_push ("/System/Library/CoreServices/.disk_label");
633 if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
634 || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
636 xorriso_push ("-hfs-bless-by");
637 xorriso_push ("i");
638 xorriso_push ("/System/Library/CoreServices/boot.efi");
643 if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
644 || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]
645 || source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
646 || source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
647 || source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI])
649 char *efidir = grub_util_make_temporary_dir ();
650 char *efidir_efi = grub_util_path_concat (2, efidir, "efi");
651 char *efidir_efi_boot = grub_util_path_concat (3, efidir, "efi", "boot");
652 char *imgname, *img32, *img64, *img_mac = NULL;
653 char *efiimgfat;
654 grub_install_mkdir_p (efidir_efi_boot);
656 grub_install_push_module ("part_gpt");
657 grub_install_push_module ("part_msdos");
659 imgname = grub_util_path_concat (2, efidir_efi_boot, "bootia64.efi");
660 make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_IA64_EFI, "ia64-efi", imgname);
661 free (imgname);
663 grub_install_push_module ("part_apple");
664 img64 = grub_util_path_concat (2, efidir_efi_boot, "bootx64.efi");
665 make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_X86_64_EFI, "x86_64-efi", img64);
666 grub_install_pop_module ();
668 grub_install_push_module ("part_apple");
669 img32 = grub_util_path_concat (2, efidir_efi_boot, "bootia32.efi");
670 make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_I386_EFI, "i386-efi", img32);
671 grub_install_pop_module ();
673 imgname = grub_util_path_concat (2, efidir_efi_boot, "bootarm.efi");
674 make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_ARM_EFI, "arm-efi", imgname);
675 free (imgname);
677 imgname = grub_util_path_concat (2, efidir_efi_boot, "bootaa64.efi");
678 make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_ARM64_EFI, "arm64-efi",
679 imgname);
680 free (imgname);
682 if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI])
684 imgname = grub_util_path_concat (2, efidir_efi_boot, "boot.efi");
685 /* For old macs. Suggested by Peter Jones. */
686 grub_install_copy_file (img32, imgname, 1);
689 if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
690 || source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
691 img_mac = grub_util_path_concat (2, core_services, "boot.efi");
693 if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
694 && source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
695 grub_util_glue_efi (img32, img64, img_mac);
696 else if (source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
697 grub_install_copy_file (img64, img_mac, 1);
698 else if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI])
699 grub_install_copy_file (img32, img_mac, 1);
701 free (img_mac);
702 free (img32);
703 free (img64);
704 free (efidir_efi_boot);
706 efiimgfat = grub_util_path_concat (2, iso9660_dir, "efi.img");
707 grub_util_exec ((const char * []) { "mformat", "-C", "-f", "2880", "-L", "16", "-i",
708 efiimgfat, "::", NULL });
709 grub_util_exec ((const char * []) { "mcopy", "-s", "-i", efiimgfat, efidir_efi, "::/", NULL });
710 xorriso_push ("--efi-boot");
711 xorriso_push ("efi.img");
712 xorriso_push ("-efi-boot-part");
713 xorriso_push ("--efi-boot-image");
715 grub_util_unlink_recursive (efidir);
716 free (efiimgfat);
717 free (efidir_efi);
718 free (efidir);
719 grub_install_pop_module ();
720 grub_install_pop_module ();
723 grub_install_push_module ("part_apple");
724 make_image_fwdisk (GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275, "powerpc-ieee1275", "powerpc-ieee1275/core.elf");
725 grub_install_pop_module ();
727 if (source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275])
729 char *grub_chrp = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275],
730 "grub.chrp");
731 char *bisrc = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275],
732 "bootinfo.txt");
733 char *bootx = grub_util_path_concat (2, core_services, "BootX");
734 char *ppc_chrp = grub_util_path_concat (3, iso9660_dir, "ppc", "chrp");
735 char *bitgt = grub_util_path_concat (3, iso9660_dir, "ppc", "bootinfo.txt");
736 grub_install_copy_file (grub_chrp, bootx, 1);
737 grub_install_mkdir_p (ppc_chrp);
738 grub_install_copy_file (bisrc, bitgt, 1);
739 xorriso_link ("/System/Library/CoreServices/grub.elf", "/boot/grub/powerpc-ieee1275/core.elf");
740 xorriso_link ("/boot/grub/powerpc.elf", "/boot/grub/powerpc-ieee1275/core.elf");
741 /* FIXME: add PreP */
742 if (system_area == SYS_AREA_COMMON)
744 xorriso_push ("-hfsplus-file-creator-type");
745 xorriso_push ("chrp");
746 xorriso_push ("tbxi");
747 xorriso_push ("/System/Library/CoreServices/BootX");
748 xorriso_push ("-hfs-bless-by");
749 xorriso_push ("p");
750 xorriso_push ("/System/Library/CoreServices");
752 xorriso_push ("-sysid");
753 xorriso_push ("PPC");
756 make_image_fwdisk (GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275,
757 "sparc64-ieee1275-cdcore", "sparc64-ieee1275/core.img");
759 if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275]
760 && system_area == SYS_AREA_SPARC)
762 char *cdboot;
763 FILE *in, *out;
764 char buf[512];
765 sysarea_img = grub_util_make_temporary_file ();
766 cdboot = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275],
767 "cdboot.img");
768 in = grub_util_fopen (cdboot, "rb");
769 if (!in)
770 grub_util_error (_("cannot open `%s': %s"), cdboot,
771 strerror (errno));
772 out = grub_util_fopen (sysarea_img, "wb");
773 if (!out)
774 grub_util_error (_("cannot open `%s': %s"), sysarea_img,
775 strerror (errno));
776 memset (buf, 0, 512);
777 fwrite (buf, 1, 512, out);
778 if (fread (buf, 1, 512, in) != 512)
779 grub_util_error (_("cannot read `%s': %s"), cdboot,
780 strerror (errno));
781 fwrite (buf, 1, 512, out);
782 fclose (in);
783 fclose (out);
784 xorriso_push ("-G");
785 xorriso_push (sysarea_img);
786 xorriso_push ("-B");
787 xorriso_push (",");
788 xorriso_push ("--grub2-sparc-core");
789 xorriso_push ("/boot/grub/sparc64-ieee1275/core.img");
792 make_image_fwdisk (GRUB_INSTALL_PLATFORM_MIPS_ARC, "mips-arc", "mips-arc/core.img");
794 if (source_dirs[GRUB_INSTALL_PLATFORM_MIPS_ARC])
796 xorriso_link ("/boot/grub/mips-arc/grub", "/boot/grub/mips-arc/core.img");
797 xorriso_link ("/boot/grub/mips-arc/sashARCS", "/boot/grub/mips-arc/core.img");
798 xorriso_link ("/boot/grub/mips-arc/sash", "/boot/grub/mips-arc/core.img");
800 if (source_dirs[GRUB_INSTALL_PLATFORM_MIPS_ARC] && system_area == SYS_AREA_ARCS)
802 xorriso_push ("-mips-boot");
803 xorriso_push ("/boot/grub/mips-arc/sashARCS");
804 xorriso_push ("-mips-boot");
805 xorriso_push ("/boot/grub/mips-arc/sash");
806 xorriso_push ("-mips-boot");
807 xorriso_push ("/boot/grub/mips-arc/grub");
810 make_image_fwdisk (GRUB_INSTALL_PLATFORM_MIPSEL_ARC, "mipsel-arc", "arc.exe");
812 grub_install_push_module ("pata");
813 make_image (GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS, "mipsel-qemu_mips-elf", "roms/mipsel-qemu_mips.elf");
815 make_image (GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "mipsel-loongson-elf", "loongson.elf");
817 make_image (GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "mipsel-yeeloong-flash", "mipsel-yeeloong.bin");
818 make_image (GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "mipsel-fuloong2f-flash", "mipsel-fuloong2f.bin");
820 make_image (GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS, "mips-qemu_mips-elf", "roms/mips-qemu_mips.elf");
822 grub_install_push_module ("at_keyboard");
824 make_image (GRUB_INSTALL_PLATFORM_I386_QEMU, "i386-qemu", "roms/qemu.img");
826 grub_install_push_module ("ahci");
828 make_image (GRUB_INSTALL_PLATFORM_I386_COREBOOT, "i386-coreboot", "roms/coreboot.elf");
829 grub_install_pop_module ();
830 grub_install_pop_module ();
831 grub_install_pop_module ();
833 if (rom_directory)
835 const struct
837 enum grub_install_plat plat;
838 const char *from, *to;
839 } roms[] =
841 {GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS, "roms/mipsel-qemu_mips.elf", "mipsel-qemu_mips.elf"},
842 {GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "loongson.elf", "mipsel-loongson.elf"},
843 {GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "roms/mipsel-yeeloong.bin", "mipsel-yeeloong.bin"},
844 {GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "roms/mipsel-fulong.bin", "mipsel-fulong.bin"},
845 {GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS, "roms/mips-qemu_mips.elf", "mips-qemu_mips.elf"},
846 {GRUB_INSTALL_PLATFORM_I386_QEMU, "roms/qemu.img", "qemu.img"},
847 {GRUB_INSTALL_PLATFORM_I386_COREBOOT, "roms/coreboot.elf", "coreboot.elf"},
849 grub_size_t i;
850 for (i = 0; i < ARRAY_SIZE (roms); i++)
852 char *from = grub_util_path_concat (2, boot_grub, roms[i].from);
853 char *to = grub_util_path_concat (2, rom_directory, roms[i].to);
854 grub_install_copy_file (from, to, 0);
858 xorriso_push ("--protective-msdos-label");
859 xorriso_push ("-o");
860 xorriso_push (output_image);
861 xorriso_push ("-r");
862 xorriso_push (iso9660_dir);
863 xorriso_push ("--sort-weight");
864 xorriso_push ("0");
865 xorriso_push ("/");
866 xorriso_push ("--sort-weight");
867 xorriso_push ("1");
868 xorriso_push ("/boot");
869 int i;
870 for (i = 0; i < xorriso_tail_argc; i++)
871 xorriso_push (xorriso_tail_argv[i]);
873 xorriso_argv[xorriso_argc] = NULL;
875 grub_util_exec ((const char *const *)xorriso_argv);
877 grub_util_unlink_recursive (iso9660_dir);
879 if (sysarea_img)
880 grub_util_unlink (sysarea_img);
882 free (core_services);
883 free (romdir);
884 return 0;