Commit b63ce2a3 authored by longpanda's avatar longpanda
Browse files

experimental support for loongson mips64el uefi

parent bb7e10d9
/*
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2013 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/util/install.h>
#include <grub/emu/config.h>
#include <grub/util/misc.h>
#include <string.h>
#include <errno.h>
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#include <argp.h>
#pragma GCC diagnostic error "-Wmissing-prototypes"
#pragma GCC diagnostic error "-Wmissing-declarations"
static char *rootdir = NULL, *subdir = NULL;
static char *debug_image = NULL;
enum
{
OPTION_NET_DIRECTORY = 0x301,
OPTION_SUBDIR,
OPTION_DEBUG,
OPTION_DEBUG_IMAGE
};
static struct argp_option options[] = {
GRUB_INSTALL_OPTIONS,
{"net-directory", OPTION_NET_DIRECTORY, N_("DIR"),
0, N_("root directory of TFTP server"), 2},
{"subdir", OPTION_SUBDIR, N_("DIR"),
0, N_("relative subdirectory on network server"), 2},
{"debug", OPTION_DEBUG, 0, OPTION_HIDDEN, 0, 2},
{"debug-image", OPTION_DEBUG_IMAGE, N_("STRING"), OPTION_HIDDEN, 0, 2},
{0, 0, 0, 0, 0, 0}
};
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
{
if (grub_install_parse (key, arg))
return 0;
switch (key)
{
case OPTION_NET_DIRECTORY:
free (rootdir);
rootdir = xstrdup (arg);
return 0;
case OPTION_SUBDIR:
free (subdir);
subdir = xstrdup (arg);
return 0;
/* This is an undocumented feature... */
case OPTION_DEBUG:
verbosity++;
return 0;
case OPTION_DEBUG_IMAGE:
free (debug_image);
debug_image = xstrdup (arg);
return 0;
case ARGP_KEY_ARG:
default:
return ARGP_ERR_UNKNOWN;
}
}
struct argp argp = {
options, argp_parser, NULL,
"\v"N_("Prepares GRUB network boot images at net_directory/subdir "
"assuming net_directory being TFTP root."),
NULL, grub_install_help_filter, NULL
};
static char *base;
static const struct
{
const char *mkimage_target;
const char *netmodule;
const char *ext;
} targets[GRUB_INSTALL_PLATFORM_MAX] =
{
[GRUB_INSTALL_PLATFORM_I386_PC] = { "i386-pc-pxe", "pxe", ".0" },
[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275] = { "sparc64-ieee1275-aout", "ofnet", ".img" },
[GRUB_INSTALL_PLATFORM_I386_IEEE1275] = { "i386-ieee1275", "ofnet", ".elf" },
[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275] = { "powerpc-ieee1275", "ofnet", ".elf" },
[GRUB_INSTALL_PLATFORM_I386_EFI] = { "i386-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_X86_64_EFI] = { "x86_64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_IA64_EFI] = { "ia64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_ARM_EFI] = { "arm-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_ARM64_EFI] = { "arm64-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_MIPS64EL_EFI] = { "mips64el-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_RISCV32_EFI] = { "riscv32-efi", "efinet", ".efi" },
[GRUB_INSTALL_PLATFORM_RISCV64_EFI] = { "riscv64-efi", "efinet", ".efi" },
};
static void
process_input_dir (const char *input_dir, enum grub_install_plat platform)
{
char *platsub = grub_install_get_platform_name (platform);
char *grubdir = grub_util_path_concat (3, rootdir, subdir, platsub);
char *load_cfg = grub_util_path_concat (2, grubdir, "load.cfg");
char *prefix;
char *output;
char *grub_cfg;
FILE *cfg;
grub_install_copy_files (input_dir, base, platform);
grub_util_unlink (load_cfg);
if (debug_image)
{
FILE *f = grub_util_fopen (load_cfg, "wb");
if (!f)
grub_util_error (_("cannot open `%s': %s"), load_cfg,
strerror (errno));
fprintf (f, "set debug='%s'\n", debug_image);
fclose (f);
}
else
{
free (load_cfg);
load_cfg = 0;
}
prefix = xasprintf ("/%s", subdir);
if (!targets[platform].mkimage_target)
grub_util_error (_("unsupported platform %s"), platsub);
grub_cfg = grub_util_path_concat (2, grubdir, "grub.cfg");
cfg = grub_util_fopen (grub_cfg, "wb");
if (!cfg)
grub_util_error (_("cannot open `%s': %s"), grub_cfg,
strerror (errno));
fprintf (cfg, "source %s/grub.cfg", subdir);
fclose (cfg);
grub_install_push_module (targets[platform].netmodule);
output = grub_util_path_concat_ext (2, grubdir, "core", targets[platform].ext);
grub_install_make_image_wrap (input_dir, prefix, output,
0, load_cfg,
targets[platform].mkimage_target, 0);
grub_install_pop_module ();
/* TRANSLATORS: First %s is replaced by platform name. Second one by filename. */
printf (_("Netboot directory for %s created. Configure your DHCP server to point to %s\n"),
platsub, output);
free (platsub);
free (output);
free (prefix);
free (grub_cfg);
free (grubdir);
}
int
main (int argc, char *argv[])
{
const char *pkglibdir;
grub_util_host_init (&argc, &argv);
grub_util_disable_fd_syncs ();
rootdir = xstrdup ("/srv/tftp");
pkglibdir = grub_util_get_pkglibdir ();
subdir = grub_util_path_concat (2, GRUB_BOOT_DIR_NAME, GRUB_DIR_NAME);
argp_parse (&argp, argc, argv, 0, 0, 0);
base = grub_util_path_concat (2, rootdir, subdir);
/* Create the GRUB directory if it is not present. */
grub_install_mkdir_p (base);
grub_install_push_module ("tftp");
if (!grub_install_source_directory)
{
enum grub_install_plat plat;
for (plat = 0; plat < GRUB_INSTALL_PLATFORM_MAX; plat++)
if (targets[plat].mkimage_target)
{
char *platdir = grub_util_path_concat (2, pkglibdir,
grub_install_get_platform_name (plat));
grub_util_info ("Looking for `%s'", platdir);
if (!grub_util_is_directory (platdir))
{
free (platdir);
continue;
}
process_input_dir (platdir, plat);
}
}
else
{
enum grub_install_plat plat;
plat = grub_install_get_target (grub_install_source_directory);
process_input_dir (grub_install_source_directory, plat);
}
return 0;
}
/*
* Make GRUB rescue image
*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/util/install.h>
#include <grub/util/misc.h>
#include <grub/emu/exec.h>
#include <grub/emu/config.h>
#include <grub/emu/hostdisk.h>
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#include <argp.h>
#pragma GCC diagnostic error "-Wmissing-prototypes"
#pragma GCC diagnostic error "-Wmissing-declarations"
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <time.h>
static char *source_dirs[GRUB_INSTALL_PLATFORM_MAX];
static char *rom_directory;
static char *label_font;
static char *label_color;
static char *label_bgcolor;
static char *product_name;
static char *product_version;
static char *output_image;
static char *xorriso;
static char *boot_grub;
static int xorriso_argc;
static int xorriso_arg_alloc;
static char **xorriso_argv;
static char *iso_uuid;
static char *iso9660_dir;
static void
xorriso_push (const char *val)
{
if (xorriso_arg_alloc <= xorriso_argc + 1)
{
xorriso_arg_alloc = 2 * (4 + xorriso_argc);
xorriso_argv = xrealloc (xorriso_argv,
sizeof (xorriso_argv[0])
* xorriso_arg_alloc);
}
xorriso_argv[xorriso_argc++] = xstrdup (val);
}
static void
xorriso_link (const char *from, const char *to)
{
char *tof = grub_util_path_concat (2, iso9660_dir, to);
char *val = xasprintf ("%s=%s", from, tof);
xorriso_push (val);
free (val);
free (tof);
}
enum
{
OPTION_OUTPUT = 'o',
OPTION_ROM_DIRECTORY = 0x301,
OPTION_XORRISO,
OPTION_GLUE_EFI,
OPTION_RENDER_LABEL,
OPTION_LABEL_FONT,
OPTION_LABEL_COLOR,
OPTION_LABEL_BGCOLOR,
OPTION_PRODUCT_NAME,
OPTION_PRODUCT_VERSION,
OPTION_SPARC_BOOT,
OPTION_ARCS_BOOT
};
static struct argp_option options[] = {
GRUB_INSTALL_OPTIONS,
{"output", 'o', N_("FILE"),
0, N_("save output in FILE [required]"), 2},
{"rom-directory", OPTION_ROM_DIRECTORY, N_("DIR"),
0, N_("save ROM images in DIR [optional]"), 2},
{"xorriso", OPTION_XORRISO, N_("FILE"),
/* TRANSLATORS: xorriso is a program for creating ISOs and burning CDs. */
0, N_("use FILE as xorriso [optional]"), 2},
{"grub-glue-efi", OPTION_GLUE_EFI, N_("FILE"), OPTION_HIDDEN, 0, 2},
{"grub-render-label", OPTION_RENDER_LABEL, N_("FILE"), OPTION_HIDDEN, 0, 2},
{"label-font", OPTION_LABEL_FONT, N_("FILE"), 0, N_("use FILE as font for label"), 2},
{"label-color", OPTION_LABEL_COLOR, N_("COLOR"), 0, N_("use COLOR for label"), 2},
{"label-bgcolor", OPTION_LABEL_BGCOLOR, N_("COLOR"), 0, N_("use COLOR for label background"), 2},
{"product-name", OPTION_PRODUCT_NAME, N_("STRING"), 0, N_("use STRING as product name"), 2},
{"product-version", OPTION_PRODUCT_VERSION, N_("STRING"), 0, N_("use STRING as product version"), 2},
{"sparc-boot", OPTION_SPARC_BOOT, 0, 0, N_("enable sparc boot. Disables HFS+, APM, ARCS and boot as disk image for i386-pc"), 2},
{"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},
{0, 0, 0, 0, 0, 0}
};
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
static char *
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
{
switch (key)
{
case ARGP_KEY_HELP_PRE_DOC:
/* TRANSLATORS: it generates one single image which is bootable through any method. */
return strdup (_("Make GRUB CD-ROM, disk, pendrive and floppy bootable image."));
case ARGP_KEY_HELP_POST_DOC:
{
char *p1, *out;
p1 = xasprintf (_("Generates a bootable CD/USB/floppy image. Arguments other than options to this program"
" are passed to xorriso, and indicate source files, source directories, or any of the "
"mkisofs options listed by the output of `%s'."), "xorriso -as mkisofs -help");
out = xasprintf ("%s\n\n%s\n\n%s", p1,
_("Option -- switches to native xorriso command mode."),
_("Mail xorriso support requests to <bug-xorriso@gnu.org>."));
free (p1);
return out;
}
default:
return grub_install_help_filter (key, text, input);
}
}
#pragma GCC diagnostic error "-Wformat-nonliteral"
enum {
SYS_AREA_AUTO,
SYS_AREA_COMMON,
SYS_AREA_SPARC,
SYS_AREA_ARCS
} system_area = SYS_AREA_AUTO;
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
{
if (grub_install_parse (key, arg))
return 0;
switch (key)
{
case OPTION_OUTPUT:
free (output_image);
output_image = xstrdup (arg);
return 0;
case OPTION_ROM_DIRECTORY:
free (rom_directory);
rom_directory = xstrdup (arg);
return 0;
/*
FIXME:
# Intentionally undocumented
--grub-mkimage-extra)
mkimage_extra_arg="$mkimage_extra_arg `argument $option "$@"`"; shift ;;
--grub-mkimage-extra=*)
mkimage_extra_arg="$mkimage_extra_arg `echo "$option" | sed 's/--grub-mkimage-extra=//'`" ;;
*/
case OPTION_SPARC_BOOT:
system_area = SYS_AREA_SPARC;
return 0;
case OPTION_ARCS_BOOT:
system_area = SYS_AREA_ARCS;
return 0;
case OPTION_PRODUCT_NAME:
free (product_name);
product_name = xstrdup (arg);
return 0;
case OPTION_PRODUCT_VERSION:
free (product_version);
product_version = xstrdup (arg);
return 0;
/* Accept and ignore for compatibility. */
case OPTION_GLUE_EFI:
case OPTION_RENDER_LABEL:
return 0;
case OPTION_LABEL_FONT:
free (label_font);
label_font = xstrdup (arg);
return 0;
case OPTION_LABEL_COLOR:
free (label_color);
label_color = xstrdup (arg);
return 0;
case OPTION_LABEL_BGCOLOR:
free (label_bgcolor);
label_bgcolor = xstrdup (arg);
return 0;
case OPTION_XORRISO:
free (xorriso);
xorriso = xstrdup (arg);
return 0;
default:
return ARGP_ERR_UNKNOWN;
}
}
struct argp argp = {
options, argp_parser, N_("[OPTION] SOURCE..."),
NULL, NULL, help_filter, NULL
};
static void
write_part (FILE *f, const char *srcdir)
{
FILE *in;
char *inname = grub_util_path_concat (2, srcdir, "partmap.lst");
char buf[260];
in = grub_util_fopen (inname, "rb");
if (!in)
return;
while (fgets (buf, 256, in))
{
char *ptr;
for (ptr = buf + strlen (buf) - 1;
ptr >= buf && (*ptr == '\n' || *ptr == '\r');
ptr--);
ptr[1] = '\0';
fprintf (f, "insmod %s\n", buf);
}
fclose (in);
}
static void
make_image_abs (enum grub_install_plat plat,
const char *mkimage_target,
const char *output)
{
char *load_cfg;
FILE *load_cfg_f;
if (!source_dirs[plat])
return;
grub_util_info (N_("enabling %s support ..."),
mkimage_target);
load_cfg = grub_util_make_temporary_file ();
load_cfg_f = grub_util_fopen (load_cfg, "wb");
fprintf (load_cfg_f, "search --fs-uuid --set=root %s\n", iso_uuid);
fprintf (load_cfg_f, "set prefix=(${root})/boot/grub\n");
write_part (load_cfg_f, source_dirs[plat]);
fclose (load_cfg_f);
grub_install_push_module ("search");
grub_install_push_module ("iso9660");
grub_install_make_image_wrap (source_dirs[plat], "/boot/grub", output,
0, load_cfg,
mkimage_target, 0);
grub_install_pop_module ();
grub_install_pop_module ();
grub_util_unlink (load_cfg);
}
static void
make_image (enum grub_install_plat plat,
const char *mkimage_target,
const char *output_sub)
{
char *out = grub_util_path_concat (2, boot_grub, output_sub);
make_image_abs (plat, mkimage_target, out);
free (out);
}
static void
make_image_fwdisk_abs (enum grub_install_plat plat,
const char *mkimage_target,
const char *output)
{
char *load_cfg;
FILE *load_cfg_f;
if (!source_dirs[plat])
return;
grub_util_info (N_("enabling %s support ..."),
mkimage_target);
load_cfg = grub_util_make_temporary_file ();
load_cfg_f = grub_util_fopen (load_cfg, "wb");
write_part (load_cfg_f, source_dirs[plat]);
fclose (load_cfg_f);
grub_install_push_module ("iso9660");
grub_install_make_image_wrap (source_dirs[plat], "()/boot/grub", output,
0, load_cfg, mkimage_target, 0);
grub_install_pop_module ();
grub_util_unlink (load_cfg);
}
static int
check_xorriso (const char *val)
{
const char *argv[5];
int fd;
pid_t pid;
FILE *mdadm;
char *buf = NULL;
size_t len = 0;
int ret = 0;
int wstatus = 0;
argv[0] = xorriso;
argv[1] = "-as";
argv[2] = "mkisofs";
argv[3] = "-help";
argv[4] = NULL;
pid = grub_util_exec_pipe_stderr (argv, &fd);
if (!pid)
return 0;
/* Parent. Read mdadm's output. */
mdadm = fdopen (fd, "r");
if (! mdadm)
return 0;
while (getline (&buf, &len, mdadm) > 0)
{
if (grub_strstr (buf, val))
ret = 1;
}
close (fd);
waitpid (pid, &wstatus, 0);
free (buf);
if (!WIFEXITED (wstatus) || WEXITSTATUS(wstatus) != 0)
return 0;
return ret;
}
static void
make_image_fwdisk (enum grub_install_plat plat,
const char *mkimage_target,
const char *output_sub)
{
char *out = grub_util_path_concat (2, boot_grub, output_sub);
make_image_fwdisk_abs (plat, mkimage_target, out);
free (out);
}
static int
option_is_end (const struct argp_option *opt)
{
return !opt->key && !opt->name && !opt->doc && !opt->group;
}
static int
args_to_eat (const char *arg)
{
int j;
if (arg[0] != '-')
return 0;
if (arg[1] == '-')
{
for (j = 0; !option_is_end(&options[j]); j++)
{
size_t len = strlen (options[j].name);
if (strncmp (arg + 2, options[j].name, len) == 0)
{
if (arg[2 + len] == '=')
return 1;
if (arg[2 + len] == '\0' && options[j].arg)
return 2;
if (arg[2 + len] == '\0')
return 1;
}
}
if (strcmp (arg, "--help") == 0)
return 1;
if (strcmp (arg, "--usage") == 0)
return 1;
if (strcmp (arg, "--version") == 0)
return 1;
return 0;
}
if (arg[2] && arg[3])
return 0;
for (j = 0; !option_is_end(&options[j]); j++)
{
if (options[j].key > 0 && options[j].key < 128 && arg[1] == options[j].key)
{
if (options[j].arg)
return 2;
return 1;
}
if (arg[1] == '?')
return 1;
}
return 0;
}
int
main (int argc, char *argv[])
{
char *romdir;
char *sysarea_img = NULL;
const char *pkgdatadir;
int argp_argc;
char **argp_argv;
int xorriso_tail_argc;
char **xorriso_tail_argv;
int rv;
grub_util_host_init (&argc, &argv);
grub_util_disable_fd_syncs ();
pkgdatadir = grub_util_get_pkgdatadir ();
product_name = xstrdup (PACKAGE_NAME);
product_version = xstrdup (PACKAGE_VERSION);
xorriso = xstrdup ("xorriso");
label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2");
argp_argv = xmalloc (sizeof (argp_argv[0]) * argc);
xorriso_tail_argv = xmalloc (sizeof (argp_argv[0]) * argc);
xorriso_tail_argc = 0;
/* Program name */
argp_argv[0] = argv[0];
argp_argc = 1;
/* argp doesn't allow us to catch unknwon arguments,
so catch them before passing to argp
*/
{
int i;
for (i = 1; i < argc; i++)
{
if (strcmp (argv[i], "-output") == 0) {
argp_argv[argp_argc++] = (char *) "--output";
i++;
argp_argv[argp_argc++] = argv[i];
continue;
}
switch (args_to_eat (argv[i]))
{
case 2:
argp_argv[argp_argc++] = argv[i++];
/* Fallthrough */
case 1:
argp_argv[argp_argc++] = argv[i];
break;
case 0:
xorriso_tail_argv[xorriso_tail_argc++] = argv[i];
break;
}
}
}
argp_parse (&argp, argp_argc, argp_argv, 0, 0, 0);
if (!output_image)
grub_util_error ("%s", _("output file must be specified"));
if (!check_xorriso ("graft-points")) {
grub_util_error ("%s", _("xorriso not found"));
}
grub_init_all ();
grub_hostfs_init ();
grub_host_init ();
xorriso_push (xorriso);
xorriso_push ("-as");
xorriso_push ("mkisofs");
xorriso_push ("-graft-points");
iso9660_dir = grub_util_make_temporary_dir ();
grub_util_info ("temporary iso9660 dir is `%s'", iso9660_dir);
boot_grub = grub_util_path_concat (3, iso9660_dir, "boot", "grub");
grub_install_mkdir_p (boot_grub);
romdir = grub_util_path_concat (2, boot_grub, "roms");
grub_util_mkdir (romdir);
if (!grub_install_source_directory)
{
const char *pkglibdir = grub_util_get_pkglibdir ();
enum grub_install_plat plat;
for (plat = 0; plat < GRUB_INSTALL_PLATFORM_MAX; plat++)
{
char *platdir = grub_util_path_concat (2, pkglibdir,
grub_install_get_platform_name (plat));
if (!grub_util_is_directory (platdir))
{
free (platdir);
continue;
}
source_dirs[plat] = platdir;
grub_install_copy_files (platdir,
boot_grub, plat);
}
}
else
{
enum grub_install_plat plat;
plat = grub_install_get_target (grub_install_source_directory);
grub_install_copy_files (grub_install_source_directory,
boot_grub, plat);
source_dirs[plat] = xstrdup (grub_install_source_directory);
}
if (system_area == SYS_AREA_AUTO || grub_install_source_directory)
{
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_PC]
|| source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275]
|| source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_MIPS64EL_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
system_area = SYS_AREA_COMMON;
else if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275])
system_area = SYS_AREA_SPARC;
else if (source_dirs[GRUB_INSTALL_PLATFORM_MIPS_ARC])
system_area = SYS_AREA_ARCS;
}
/* obtain date-based UUID. */
{
time_t tim;
struct tm *tmm;
tim = time (NULL);
tmm = gmtime (&tim);
iso_uuid = xmalloc (55);
grub_snprintf (iso_uuid, 50,
"%04d-%02d-%02d-%02d-%02d-%02d-00",
tmm->tm_year + 1900,
tmm->tm_mon + 1,
tmm->tm_mday,
tmm->tm_hour,
tmm->tm_min,
tmm->tm_sec);
}
{
char *uuid_out = xmalloc (strlen (iso_uuid) + 1 + 40);
char *optr;
const char *iptr;
optr = grub_stpcpy (uuid_out, "--modification-date=");
for (iptr = iso_uuid; *iptr; iptr++)
if (*iptr != '-')
*optr++ = *iptr;
*optr = '\0';
xorriso_push (uuid_out);
free (uuid_out);
}
/* build BIOS core.img. */
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_PC])
{
char *load_cfg;
FILE *load_cfg_f;
char *output = grub_util_path_concat (3, boot_grub, "i386-pc", "eltorito.img");
load_cfg = grub_util_make_temporary_file ();
grub_util_info (N_("enabling %s support ..."), "BIOS");
load_cfg_f = grub_util_fopen (load_cfg, "wb");
write_part (load_cfg_f, source_dirs[GRUB_INSTALL_PLATFORM_I386_PC]);
fclose (load_cfg_f);
grub_install_push_module ("biosdisk");
grub_install_push_module ("iso9660");
grub_install_make_image_wrap (source_dirs[GRUB_INSTALL_PLATFORM_I386_PC],
"/boot/grub", output,
0, load_cfg,
"i386-pc-eltorito", 0);
xorriso_push ("-b");
xorriso_push ("boot/grub/i386-pc/eltorito.img");
xorriso_push ("-no-emul-boot");
xorriso_push ("-boot-load-size");
xorriso_push ("4");
xorriso_push ("-boot-info-table");
if (system_area == SYS_AREA_COMMON)
{
if (check_xorriso ("grub2-boot-info"))
{
char *boot_hybrid = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_I386_PC],
"boot_hybrid.img");
xorriso_push ("--grub2-boot-info");
xorriso_push ("--grub2-mbr");
xorriso_push (boot_hybrid);
}
else
{
FILE *sa, *bi;
size_t sz;
char buf[512];
char *bin = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_I386_PC],
"boot.img");
grub_util_warn ("%s", _("Your xorriso doesn't support `--grub2-boot-info'. Some features are disabled. Please use xorriso 1.2.9 or later."));
sysarea_img = grub_util_make_temporary_file ();
sa = grub_util_fopen (sysarea_img, "wb");
if (!sa)
grub_util_error (_("cannot open `%s': %s"), sysarea_img,
strerror (errno));
bi = grub_util_fopen (bin, "rb");
if (!bi)
grub_util_error (_("cannot open `%s': %s"), bin,
strerror (errno));
if (fread (buf, 1, 512, bi) != 512)
grub_util_error (_("cannot read `%s': %s"), bin,
strerror (errno));
fclose (bi);
fwrite (buf, 1, 512, sa);
grub_install_make_image_wrap_file (source_dirs[GRUB_INSTALL_PLATFORM_I386_PC],
"/boot/grub", sa, sysarea_img,
0, load_cfg,
"i386-pc", 0);
sz = ftello (sa);
fflush (sa);
grub_util_fd_sync (fileno (sa));
fclose (sa);
if (sz > 32768)
{
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."));
}
else
{
xorriso_push ("-G");
xorriso_push (sysarea_img);
}
}
}
grub_install_pop_module ();
grub_install_pop_module ();
grub_util_unlink (load_cfg);
}
/** build multiboot core.img */
grub_install_push_module ("pata");
grub_install_push_module ("ahci");
grub_install_push_module ("at_keyboard");
make_image (GRUB_INSTALL_PLATFORM_I386_MULTIBOOT, "i386-multiboot", "i386-multiboot/core.elf");
grub_install_pop_module ();
grub_install_pop_module ();
grub_install_pop_module ();
make_image_fwdisk (GRUB_INSTALL_PLATFORM_I386_IEEE1275, "i386-ieee1275", "ofwx86.elf");
char *core_services = NULL;
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275])
{
char *mach_ker, *sv, *label, *label_text;
FILE *f;
core_services = grub_util_path_concat (4, iso9660_dir, "System", "Library", "CoreServices");
grub_install_mkdir_p (core_services);
mach_ker = grub_util_path_concat (2, iso9660_dir, "mach_kernel");
f = grub_util_fopen (mach_ker, "wb");
fclose (f);
free (mach_ker);
sv = grub_util_path_concat (2, core_services, "SystemVersion.plist");
f = grub_util_fopen (sv, "wb");
fprintf (f, "<plist version=\"1.0\">\n"
"<dict>\n"
" <key>ProductBuildVersion</key>\n"
" <string></string>\n"
" <key>ProductName</key>\n"
" <string>%s</string>\n"
" <key>ProductVersion</key>\n"
" <string>%s</string>\n"
"</dict>\n"
"</plist>\n", product_name, product_version);
fclose (f);
free (sv);
label = grub_util_path_concat (2, core_services, ".disk_label");
char *label_string = xasprintf ("%s %s", product_name, product_version);
grub_util_render_label (label_font, label_bgcolor ? : "white",
label_color ? : "black", label_string, label);
free (label);
label_text = grub_util_path_concat (2, core_services, ".disk_label.contentDetails");
f = grub_util_fopen (label_text, "wb");
fprintf (f, "%s\n", label_string);
fclose (f);
free (label_string);
free (label_text);
if (system_area == SYS_AREA_COMMON)
{
xorriso_push ("-hfsplus");
xorriso_push ("-apm-block-size");
xorriso_push ("2048");
xorriso_push ("-hfsplus-file-creator-type");
xorriso_push ("chrp");
xorriso_push ("tbxj");
xorriso_push ("/System/Library/CoreServices/.disk_label");
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
{
xorriso_push ("-hfs-bless-by");
xorriso_push ("i");
xorriso_push ("/System/Library/CoreServices/boot.efi");
}
}
}
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_IA64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_ARM_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_ARM64_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_MIPS64EL_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI])
{
char *efidir = grub_util_make_temporary_dir ();
char *efidir_efi = grub_util_path_concat (2, efidir, "efi");
char *efidir_efi_boot = grub_util_path_concat (3, efidir, "efi", "boot");
char *imgname, *img32, *img64, *img_mac = NULL;
char *efiimgfat;
grub_install_mkdir_p (efidir_efi_boot);
grub_install_push_module ("part_gpt");
grub_install_push_module ("part_msdos");
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootia64.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_IA64_EFI, "ia64-efi", imgname);
free (imgname);
grub_install_push_module ("part_apple");
img64 = grub_util_path_concat (2, efidir_efi_boot, "bootx64.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_X86_64_EFI, "x86_64-efi", img64);
grub_install_pop_module ();
grub_install_push_module ("part_apple");
img32 = grub_util_path_concat (2, efidir_efi_boot, "bootia32.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_I386_EFI, "i386-efi", img32);
grub_install_pop_module ();
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootarm.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_ARM_EFI, "arm-efi", imgname);
free (imgname);
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootaa64.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_ARM64_EFI, "arm64-efi",
imgname);
free (imgname);
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootmips64el.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_MIPS64EL_EFI, "mips64el-efi",
imgname);
free (imgname);
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv32.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI, "riscv32-efi",
imgname);
free (imgname);
imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv64.efi");
make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV64_EFI, "riscv64-efi",
imgname);
free (imgname);
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI])
{
imgname = grub_util_path_concat (2, efidir_efi_boot, "boot.efi");
/* For old macs. Suggested by Peter Jones. */
grub_install_copy_file (img32, imgname, 1);
}
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
|| source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
img_mac = grub_util_path_concat (2, core_services, "boot.efi");
if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI]
&& source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
grub_util_glue_efi (img32, img64, img_mac);
else if (source_dirs[GRUB_INSTALL_PLATFORM_X86_64_EFI])
grub_install_copy_file (img64, img_mac, 1);
else if (source_dirs[GRUB_INSTALL_PLATFORM_I386_EFI])
grub_install_copy_file (img32, img_mac, 1);
free (img_mac);
free (img32);
free (img64);
free (efidir_efi_boot);
efiimgfat = grub_util_path_concat (2, iso9660_dir, "efi.img");
rv = grub_util_exec ((const char * []) { "mformat", "-C", "-f", "2880", "-L", "16", "-i",
efiimgfat, "::", NULL });
if (rv != 0)
grub_util_error ("`%s` invocation failed\n", "mformat");
rv = grub_util_exec ((const char * []) { "mcopy", "-s", "-i", efiimgfat, efidir_efi, "::/", NULL });
if (rv != 0)
grub_util_error ("`%s` invocation failed\n", "mcopy");
xorriso_push ("--efi-boot");
xorriso_push ("efi.img");
xorriso_push ("-efi-boot-part");
xorriso_push ("--efi-boot-image");
grub_util_unlink_recursive (efidir);
free (efiimgfat);
free (efidir_efi);
free (efidir);
grub_install_pop_module ();
grub_install_pop_module ();
}
grub_install_push_module ("part_apple");
make_image_fwdisk (GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275, "powerpc-ieee1275", "powerpc-ieee1275/core.elf");
grub_install_pop_module ();
if (source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275])
{
char *grub_chrp = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275],
"grub.chrp");
char *bisrc = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275],
"bootinfo.txt");
char *bootx = grub_util_path_concat (2, core_services, "BootX");
char *ppc_chrp = grub_util_path_concat (3, iso9660_dir, "ppc", "chrp");
char *bitgt = grub_util_path_concat (3, iso9660_dir, "ppc", "bootinfo.txt");
grub_install_copy_file (grub_chrp, bootx, 1);
grub_install_mkdir_p (ppc_chrp);
grub_install_copy_file (bisrc, bitgt, 1);
xorriso_link ("/System/Library/CoreServices/grub.elf", "/boot/grub/powerpc-ieee1275/core.elf");
xorriso_link ("/boot/grub/powerpc.elf", "/boot/grub/powerpc-ieee1275/core.elf");
/* FIXME: add PreP */
if (system_area == SYS_AREA_COMMON)
{
xorriso_push ("-hfsplus-file-creator-type");
xorriso_push ("chrp");
xorriso_push ("tbxi");
xorriso_push ("/System/Library/CoreServices/BootX");
xorriso_push ("-hfs-bless-by");
xorriso_push ("p");
xorriso_push ("/System/Library/CoreServices");
}
xorriso_push ("-sysid");
xorriso_push ("PPC");
}
make_image_fwdisk (GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275,
"sparc64-ieee1275-cdcore", "sparc64-ieee1275/core.img");
if (source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275]
&& system_area == SYS_AREA_SPARC)
{
char *cdboot;
FILE *in, *out;
char buf[512];
sysarea_img = grub_util_make_temporary_file ();
cdboot = grub_util_path_concat (2, source_dirs[GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275],
"cdboot.img");
in = grub_util_fopen (cdboot, "rb");
if (!in)
grub_util_error (_("cannot open `%s': %s"), cdboot,
strerror (errno));
out = grub_util_fopen (sysarea_img, "wb");
if (!out)
grub_util_error (_("cannot open `%s': %s"), sysarea_img,
strerror (errno));
memset (buf, 0, 512);
fwrite (buf, 1, 512, out);
if (fread (buf, 1, 512, in) != 512)
grub_util_error (_("cannot read `%s': %s"), cdboot,
strerror (errno));
fwrite (buf, 1, 512, out);
fclose (in);
fclose (out);
xorriso_push ("-G");
xorriso_push (sysarea_img);
xorriso_push ("-B");
xorriso_push (",");
xorriso_push ("--grub2-sparc-core");
xorriso_push ("/boot/grub/sparc64-ieee1275/core.img");
}
make_image_fwdisk (GRUB_INSTALL_PLATFORM_MIPS_ARC, "mips-arc", "mips-arc/core.img");
if (source_dirs[GRUB_INSTALL_PLATFORM_MIPS_ARC])
{
xorriso_link ("/boot/grub/mips-arc/grub", "/boot/grub/mips-arc/core.img");
xorriso_link ("/boot/grub/mips-arc/sashARCS", "/boot/grub/mips-arc/core.img");
xorriso_link ("/boot/grub/mips-arc/sash", "/boot/grub/mips-arc/core.img");
}
if (source_dirs[GRUB_INSTALL_PLATFORM_MIPS_ARC] && system_area == SYS_AREA_ARCS)
{
xorriso_push ("-mips-boot");
xorriso_push ("/boot/grub/mips-arc/sashARCS");
xorriso_push ("-mips-boot");
xorriso_push ("/boot/grub/mips-arc/sash");
xorriso_push ("-mips-boot");
xorriso_push ("/boot/grub/mips-arc/grub");
}
make_image_fwdisk (GRUB_INSTALL_PLATFORM_MIPSEL_ARC, "mipsel-arc", "arc.exe");
grub_install_push_module ("pata");
make_image (GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS, "mipsel-qemu_mips-elf", "roms/mipsel-qemu_mips.elf");
make_image (GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "mipsel-loongson-elf", "loongson.elf");
make_image (GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "mipsel-yeeloong-flash", "mipsel-yeeloong.bin");
make_image (GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "mipsel-fuloong2f-flash", "mipsel-fuloong2f.bin");
make_image (GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS, "mips-qemu_mips-elf", "roms/mips-qemu_mips.elf");
grub_install_push_module ("at_keyboard");
make_image (GRUB_INSTALL_PLATFORM_I386_QEMU, "i386-qemu", "roms/qemu.img");
grub_install_push_module ("ahci");
make_image (GRUB_INSTALL_PLATFORM_I386_COREBOOT, "i386-coreboot", "roms/coreboot.elf");
grub_install_pop_module ();
grub_install_pop_module ();
grub_install_pop_module ();
if (rom_directory)
{
const struct
{
enum grub_install_plat plat;
const char *from, *to;
} roms[] =
{
{GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS, "roms/mipsel-qemu_mips.elf", "mipsel-qemu_mips.elf"},
{GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "loongson.elf", "mipsel-loongson.elf"},
{GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "roms/mipsel-yeeloong.bin", "mipsel-yeeloong.bin"},
{GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON, "roms/mipsel-fulong.bin", "mipsel-fulong.bin"},
{GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS, "roms/mips-qemu_mips.elf", "mips-qemu_mips.elf"},
{GRUB_INSTALL_PLATFORM_I386_QEMU, "roms/qemu.img", "qemu.img"},
{GRUB_INSTALL_PLATFORM_I386_COREBOOT, "roms/coreboot.elf", "coreboot.elf"},
};
grub_size_t i;
for (i = 0; i < ARRAY_SIZE (roms); i++)
{
char *from = grub_util_path_concat (2, boot_grub, roms[i].from);
char *to = grub_util_path_concat (2, rom_directory, roms[i].to);
grub_install_copy_file (from, to, 0);
}
}
xorriso_push ("--protective-msdos-label");
xorriso_push ("-o");
xorriso_push (output_image);
xorriso_push ("-r");
xorriso_push (iso9660_dir);
xorriso_push ("--sort-weight");
xorriso_push ("0");
xorriso_push ("/");
xorriso_push ("--sort-weight");
xorriso_push ("1");
xorriso_push ("/boot");
int i;
for (i = 0; i < xorriso_tail_argc; i++)
xorriso_push (xorriso_tail_argv[i]);
xorriso_argv[xorriso_argc] = NULL;
rv = grub_util_exec ((const char *const *)xorriso_argv);
if (rv != 0)
grub_util_error ("`%s` invocation failed\n", "xorriso");
grub_util_unlink_recursive (iso9660_dir);
if (sysarea_img)
grub_util_unlink (sysarea_img);
free (core_services);
free (romdir);
return 0;
}
#include <stdio.h>
#include <string.h>
#include <grub/elf.h>
#include <grub/module_verifier.h>
#include <grub/misc.h>
#include <grub/util/misc.h>
struct grub_module_verifier_arch archs[] = {
{ "i386", 4, 0, EM_386, GRUB_MODULE_VERIFY_SUPPORTS_REL, (int[]){
R_386_32,
R_386_PC32,
-1
} },
{ "x86_64", 8, 0, EM_X86_64, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_X86_64_64,
R_X86_64_PC64,
/* R_X86_64_32, R_X86_64_32S are supported but shouldn't be used because of their limited range. */
-1
}, (int[]){
R_X86_64_PC32,
R_X86_64_PLT32,
-1
}
},
{ "powerpc", 4, 1, EM_PPC, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
GRUB_ELF_R_PPC_ADDR16_LO,
GRUB_ELF_R_PPC_REL24, /* It has limited range but GRUB adds trampolines when necessarry. */
GRUB_ELF_R_PPC_ADDR16_HA,
GRUB_ELF_R_PPC_ADDR32,
GRUB_ELF_R_PPC_REL32,
GRUB_ELF_R_PPC_PLTREL24,
-1
} },
{ "sparc64", 8, 1, EM_SPARCV9, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_SPARC_WDISP30, /* It has limited range but GRUB adds trampolines when necessarry. */
R_SPARC_HH22,
R_SPARC_HM10,
R_SPARC_LM22,
R_SPARC_LO10,
R_SPARC_64,
R_SPARC_OLO10,
/* Following 2 relocations have limited range but unfortunately
clang generates them, as it doesn't implement mcmodel=large properly.
At least our heap and core are under 4G, so it's not a problem
usually. */
R_SPARC_HI22,
R_SPARC_32,
-1
} },
{ "ia64", 8, 0, EM_IA_64, GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_IA64_PCREL21B, /* We should verify that it's pointing either
to a function or to a section in the same module.
Checking that external symbol is a function is
non-trivial and I have never seen this relocation used
for anything else, so assume that it always points to a
function.
*/
R_IA64_SEGREL64LSB,
R_IA64_FPTR64LSB,
R_IA64_DIR64LSB,
R_IA64_PCREL64LSB,
R_IA64_LTOFF22X,
R_IA64_LTOFF22,
R_IA64_GPREL64I,
R_IA64_LTOFF_FPTR22,
R_IA64_LDXMOV,
-1
}, (int[]){
R_IA64_GPREL22,
-1
} },
{ "mipsel", 4, 0, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_MIPS_HI16,
R_MIPS_LO16,
R_MIPS_32,
R_MIPS_GPREL32,
R_MIPS_26,
R_MIPS_GOT16,
R_MIPS_CALL16,
R_MIPS_JALR,
-1
} },
{ "mips", 4, 1, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_MIPS_HI16,
R_MIPS_LO16,
R_MIPS_32,
R_MIPS_GPREL32,
R_MIPS_26,
R_MIPS_GOT16,
R_MIPS_CALL16,
R_MIPS_JALR,
-1
} },
{ "arm", 4, 0, EM_ARM, GRUB_MODULE_VERIFY_SUPPORTS_REL, (int[]){
/* Some relocations are range-limited but trampolines are added when necessarry. */
R_ARM_ABS32,
R_ARM_CALL,
R_ARM_JUMP24,
R_ARM_THM_CALL,
R_ARM_THM_JUMP24,
R_ARM_V4BX,
R_ARM_THM_MOVW_ABS_NC,
R_ARM_THM_MOVT_ABS,
R_ARM_THM_JUMP19,
-1
} },
{ "arm64", 8, 0, EM_AARCH64, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_AARCH64_ABS64,
R_AARCH64_CALL26,
R_AARCH64_JUMP26,
R_AARCH64_ADR_GOT_PAGE,
R_AARCH64_LD64_GOT_LO12_NC,
-1
}, (int[]){
R_AARCH64_ADR_PREL_PG_HI21,
R_AARCH64_ADD_ABS_LO12_NC,
R_AARCH64_LDST64_ABS_LO12_NC,
R_AARCH64_PREL32,
-1
} },
{ "mips64el", 8, 0, EM_MIPS, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_MIPS_64,
R_MIPS_32,
R_MIPS_26,
R_MIPS_LO16,
R_MIPS_HI16,
R_MIPS_HIGHER,
R_MIPS_HIGHEST,
-1
}, (int[]){
-1
}
},
{ "riscv32", 4, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_RISCV_32,
R_RISCV_64,
R_RISCV_ADD8,
R_RISCV_ADD16,
R_RISCV_ADD32,
R_RISCV_ADD64,
R_RISCV_SUB8,
R_RISCV_SUB16,
R_RISCV_SUB32,
R_RISCV_SUB64,
R_RISCV_ALIGN,
R_RISCV_BRANCH,
R_RISCV_CALL,
R_RISCV_CALL_PLT,
R_RISCV_GOT_HI20,
R_RISCV_HI20,
R_RISCV_JAL,
R_RISCV_LO12_I,
R_RISCV_LO12_S,
R_RISCV_PCREL_HI20,
R_RISCV_PCREL_LO12_I,
R_RISCV_PCREL_LO12_S,
R_RISCV_RELAX,
R_RISCV_RVC_BRANCH,
R_RISCV_RVC_JUMP,
-1
} },
{ "riscv64", 8, 0, EM_RISCV, GRUB_MODULE_VERIFY_SUPPORTS_REL | GRUB_MODULE_VERIFY_SUPPORTS_RELA, (int[]){
R_RISCV_32,
R_RISCV_64,
R_RISCV_ADD8,
R_RISCV_ADD16,
R_RISCV_ADD32,
R_RISCV_ADD64,
R_RISCV_SUB8,
R_RISCV_SUB16,
R_RISCV_SUB32,
R_RISCV_SUB64,
R_RISCV_ALIGN,
R_RISCV_BRANCH,
R_RISCV_CALL,
R_RISCV_CALL_PLT,
R_RISCV_GOT_HI20,
R_RISCV_HI20,
R_RISCV_JAL,
R_RISCV_LO12_I,
R_RISCV_LO12_S,
R_RISCV_PCREL_HI20,
R_RISCV_PCREL_LO12_I,
R_RISCV_PCREL_LO12_S,
R_RISCV_RELAX,
R_RISCV_RVC_BRANCH,
R_RISCV_RVC_JUMP,
-1
}
},
};
struct platform_whitelist {
const char *arch;
const char *platform;
const char **whitelist_empty;
};
static struct platform_whitelist whitelists[] = {
{"i386", "xen", (const char *[]) {"all_video", 0}},
{"i386", "xen_pvh", (const char *[]) {"all_video", 0}},
{"x86_64", "xen", (const char *[]) {"all_video", 0}},
{"sparc64", "ieee1275", (const char *[]) {"all_video", 0}},
/* video is compiled-in on MIPS. */
{"mipsel", "loongson", (const char *[]) {"all_video", 0}},
{"mipsel", "qemu_mips", (const char *[]) {"all_video", 0}},
{"mipsel", "arc", (const char *[]) {"all_video", 0}},
{"mips", "qemu_mips", (const char *[]) {"all_video", 0}},
{"mips", "arc", (const char *[]) {"all_video", 0}},
};
int
main (int argc, char **argv)
{
size_t module_size;
unsigned arch, whitelist;
const char **whitelist_empty = 0;
char *module_img;
if (argc != 4) {
fprintf (stderr, "usage: %s FILE ARCH PLATFORM\n", argv[0]);
return 1;
}
for (arch = 0; arch < ARRAY_SIZE(archs); arch++)
if (strcmp(archs[arch].name, argv[2]) == 0)
break;
if (arch == ARRAY_SIZE(archs))
grub_util_error("%s: unknown arch: %s", argv[1], argv[2]);
for (whitelist = 0; whitelist < ARRAY_SIZE(whitelists); whitelist++)
if (strcmp(whitelists[whitelist].arch, argv[2]) == 0
&& strcmp(whitelists[whitelist].platform, argv[3]) == 0)
break;
if (whitelist != ARRAY_SIZE(whitelists))
whitelist_empty = whitelists[whitelist].whitelist_empty;
module_size = grub_util_get_image_size (argv[1]);
module_img = grub_util_read_image (argv[1]);
if (archs[arch].voidp_sizeof == 8)
grub_module_verify64(argv[1], module_img, module_size, &archs[arch], whitelist_empty);
else
grub_module_verify32(argv[1], module_img, module_size, &archs[arch], whitelist_empty);
return 0;
}
#include <string.h>
#include <grub/elf.h>
#include <grub/module_verifier.h>
#include <grub/util/misc.h>
#if defined(MODULEVERIFIER_ELF32)
# define SUFFIX(x) x ## 32
# define ELFCLASSXX ELFCLASS32
# define Elf_Ehdr Elf32_Ehdr
# define Elf_Phdr Elf32_Phdr
# define Elf_Nhdr Elf32_Nhdr
# define Elf_Addr Elf32_Addr
# define Elf_Sym Elf32_Sym
# define Elf_Off Elf32_Off
# define Elf_Shdr Elf32_Shdr
# define Elf_Rela Elf32_Rela
# define Elf_Rel Elf32_Rel
# define Elf_Word Elf32_Word
# define Elf_Half Elf32_Half
# define Elf_Section Elf32_Section
# define ELF_R_SYM(val) ELF32_R_SYM(val)
# define ELF_R_TYPE(val) ELF32_R_TYPE(val)
# define ELF_ST_TYPE(val) ELF32_ST_TYPE(val)
#elif defined(MODULEVERIFIER_ELF64)
# define SUFFIX(x) x ## 64
# define ELFCLASSXX ELFCLASS64
# define Elf_Ehdr Elf64_Ehdr
# define Elf_Phdr Elf64_Phdr
# define Elf_Nhdr Elf64_Nhdr
# define Elf_Addr Elf64_Addr
# define Elf_Sym Elf64_Sym
# define Elf_Off Elf64_Off
# define Elf_Shdr Elf64_Shdr
# define Elf_Rela Elf64_Rela
# define Elf_Rel Elf64_Rel
# define Elf_Word Elf64_Word
# define Elf_Half Elf64_Half
# define Elf_Section Elf64_Section
# define ELF_R_SYM(val) ELF64_R_SYM(val)
# define ELF_R_TYPE(val) ELF64_R_TYPE(val)
# define ELF_ST_TYPE(val) ELF64_ST_TYPE(val)
#else
#error "I'm confused"
#endif
#define grub_target_to_host32(x) (grub_target_to_host32_real (arch, (x)))
#define grub_host_to_target32(x) (grub_host_to_target32_real (arch, (x)))
#define grub_target_to_host64(x) (grub_target_to_host64_real (arch, (x)))
#define grub_host_to_target64(x) (grub_host_to_target64_real (arch, (x)))
#define grub_host_to_target_addr(x) (grub_host_to_target_addr_real (arch, (x)))
#define grub_target_to_host16(x) (grub_target_to_host16_real (arch, (x)))
#define grub_host_to_target16(x) (grub_host_to_target16_real (arch, (x)))
#define grub_target_to_host(val) grub_target_to_host_real(arch, (val))
static inline grub_uint32_t
grub_target_to_host32_real (const struct grub_module_verifier_arch *arch,
grub_uint32_t in)
{
if (arch->bigendian)
return grub_be_to_cpu32 (in);
else
return grub_le_to_cpu32 (in);
}
static inline grub_uint64_t
grub_target_to_host64_real (const struct grub_module_verifier_arch *arch,
grub_uint64_t in)
{
if (arch->bigendian)
return grub_be_to_cpu64 (in);
else
return grub_le_to_cpu64 (in);
}
static inline grub_uint64_t
grub_host_to_target64_real (const struct grub_module_verifier_arch *arch,
grub_uint64_t in)
{
if (arch->bigendian)
return grub_cpu_to_be64 (in);
else
return grub_cpu_to_le64 (in);
}
static inline grub_uint32_t
grub_host_to_target32_real (const struct grub_module_verifier_arch *arch,
grub_uint32_t in)
{
if (arch->bigendian)
return grub_cpu_to_be32 (in);
else
return grub_cpu_to_le32 (in);
}
static inline grub_uint16_t
grub_target_to_host16_real (const struct grub_module_verifier_arch *arch,
grub_uint16_t in)
{
if (arch->bigendian)
return grub_be_to_cpu16 (in);
else
return grub_le_to_cpu16 (in);
}
static inline grub_uint16_t
grub_host_to_target16_real (const struct grub_module_verifier_arch *arch,
grub_uint16_t in)
{
if (arch->bigendian)
return grub_cpu_to_be16 (in);
else
return grub_cpu_to_le16 (in);
}
static inline grub_uint64_t
grub_host_to_target_addr_real (const struct grub_module_verifier_arch *arch, grub_uint64_t in)
{
if (arch->voidp_sizeof == 8)
return grub_host_to_target64_real (arch, in);
else
return grub_host_to_target32_real (arch, in);
}
static inline grub_uint64_t
grub_target_to_host_real (const struct grub_module_verifier_arch *arch, grub_uint64_t in)
{
if (arch->voidp_sizeof == 8)
return grub_target_to_host64_real (arch, in);
else
return grub_target_to_host32_real (arch, in);
}
static Elf_Shdr *
find_section (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, const char *name)
{
Elf_Shdr *s;
const char *str;
unsigned i;
s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host16 (e->e_shstrndx) * grub_target_to_host16 (e->e_shentsize));
str = (char *) e + grub_target_to_host (s->sh_offset);
for (i = 0, s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff));
i < grub_target_to_host16 (e->e_shnum);
i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize)))
if (strcmp (str + grub_target_to_host32 (s->sh_name), name) == 0)
return s;
return NULL;
}
static void
check_license (const char * const filename,
const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
{
Elf_Shdr *s = find_section (arch, e, ".module_license");
if (s && (strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3") == 0
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv3+") == 0
|| strcmp ((char *) e + grub_target_to_host(s->sh_offset), "LICENSE=GPLv2+") == 0))
return;
grub_util_error ("%s: incompatible license", filename);
}
static Elf_Sym *
get_symtab (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word *size, Elf_Word *entsize)
{
unsigned i;
Elf_Shdr *s, *sections;
Elf_Sym *sym;
sections = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff));
for (i = 0, s = sections;
i < grub_target_to_host16 (e->e_shnum);
i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize)))
if (grub_target_to_host32 (s->sh_type) == SHT_SYMTAB)
break;
if (i == grub_target_to_host16 (e->e_shnum))
return NULL;
sym = (Elf_Sym *) ((char *) e + grub_target_to_host (s->sh_offset));
*size = grub_target_to_host (s->sh_size);
*entsize = grub_target_to_host (s->sh_entsize);
return sym;
}
static int
is_whitelisted (const char *modname, const char **whitelist)
{
const char **ptr;
if (!whitelist)
return 0;
if (!modname)
return 0;
for (ptr = whitelist; *ptr; ptr++)
if (strcmp (modname, *ptr) == 0)
return 1;
return 0;
}
static void
check_symbols (const struct grub_module_verifier_arch *arch,
Elf_Ehdr *e, const char *modname,
const char **whitelist_empty)
{
Elf_Sym *sym;
Elf_Word size, entsize;
unsigned i;
/* Module without symbol table and without .moddeps section is useless
at boot time, so catch it early to prevent build errors */
sym = get_symtab (arch, e, &size, &entsize);
if (!sym)
{
Elf_Shdr *s;
/* However some modules are dependencies-only,
e.g. insmod all_video pulls in all video drivers.
Some platforms e.g. xen have no video drivers, so
the module does nothing. */
if (is_whitelisted (modname, whitelist_empty))
return;
s = find_section (arch, e, ".moddeps");
if (!s)
grub_util_error ("%s: no symbol table and no .moddeps section", modname);
if (!s->sh_size)
grub_util_error ("%s: no symbol table and empty .moddeps section", modname);
return;
}
for (i = 0;
i < size / entsize;
i++, sym = (Elf_Sym *) ((char *) sym + entsize))
{
unsigned char type = ELF_ST_TYPE (sym->st_info);
switch (type)
{
case STT_NOTYPE:
case STT_OBJECT:
case STT_FUNC:
case STT_SECTION:
case STT_FILE:
break;
default:
return grub_util_error ("%s: unknown symbol type `%d'", modname, (int) type);
}
}
}
static int
is_symbol_local(Elf_Sym *sym)
{
switch (ELF_ST_TYPE (sym->st_info))
{
case STT_NOTYPE:
case STT_OBJECT:
if (sym->st_name != 0 && sym->st_shndx == 0)
return 0;
return 1;
case STT_FUNC:
case STT_SECTION:
return 1;
default:
return 0;
}
}
static void
section_check_relocations (const char * const modname,
const struct grub_module_verifier_arch *arch, void *ehdr,
Elf_Shdr *s, size_t target_seg_size)
{
Elf_Rel *rel, *max;
Elf_Sym *symtab;
Elf_Word symtabsize, symtabentsize;
symtab = get_symtab (arch, ehdr, &symtabsize, &symtabentsize);
if (!symtab)
grub_util_error ("%s: relocation without symbol table", modname);
for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)),
max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size));
rel < max;
rel = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_entsize)))
{
Elf_Sym *sym;
unsigned i;
if (target_seg_size < grub_target_to_host (rel->r_offset))
grub_util_error ("%s: reloc offset is out of the segment", modname);
grub_size_t r_info;
if (arch->machine == EM_MIPS && arch->voidp_sizeof == 8)
r_info = ((grub_uint64_t) rel->r_info << 32) |
(grub_uint32_t) grub_be_to_cpu64 (rel->r_info);
else
r_info = grub_target_to_host (rel->r_info);
grub_uint32_t type = ELF_R_TYPE (r_info);
if (arch->machine == EM_SPARCV9)
type &= 0xff;
for (i = 0; arch->supported_relocations[i] != -1; i++)
if (type == arch->supported_relocations[i])
break;
if (arch->supported_relocations[i] != -1)
continue;
if (!arch->short_relocations)
grub_util_error ("%s: unsupported relocation 0x%x", modname, type);
for (i = 0; arch->short_relocations[i] != -1; i++)
if (type == arch->short_relocations[i])
break;
if (arch->short_relocations[i] == -1)
grub_util_error ("%s: unsupported relocation 0x%x", modname, type);
sym = (Elf_Sym *) ((char *) symtab + symtabentsize * ELF_R_SYM (r_info));
if (is_symbol_local (sym))
continue;
grub_util_error ("%s: relocation 0x%x is not module-local", modname, type);
}
#if defined(MODULEVERIFIER_ELF64)
if (arch->machine == EM_AARCH64)
{
unsigned unmatched_adr_got_page = 0;
Elf_Rela *rel2;
for (rel = (Elf_Rel *) ((char *) ehdr + grub_target_to_host (s->sh_offset)),
max = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_size));
rel < max;
rel = (Elf_Rel *) ((char *) rel + grub_target_to_host (s->sh_entsize)))
{
switch (ELF_R_TYPE (grub_target_to_host (rel->r_info)))
{
case R_AARCH64_ADR_GOT_PAGE:
unmatched_adr_got_page++;
for (rel2 = (Elf_Rela *) ((char *) rel + grub_target_to_host (s->sh_entsize));
rel2 < (Elf_Rela *) max;
rel2 = (Elf_Rela *) ((char *) rel2 + grub_target_to_host (s->sh_entsize)))
if (ELF_R_SYM (rel2->r_info)
== ELF_R_SYM (rel->r_info)
&& ((Elf_Rela *) rel)->r_addend == rel2->r_addend
&& ELF_R_TYPE (rel2->r_info) == R_AARCH64_LD64_GOT_LO12_NC)
break;
if (rel2 >= (Elf_Rela *) max)
grub_util_error ("%s: ADR_GOT_PAGE without matching LD64_GOT_LO12_NC", modname);
break;
case R_AARCH64_LD64_GOT_LO12_NC:
if (unmatched_adr_got_page == 0)
grub_util_error ("%s: LD64_GOT_LO12_NC without matching ADR_GOT_PAGE", modname);
unmatched_adr_got_page--;
break;
}
}
}
#endif
}
static void
check_relocations (const char * const modname,
const struct grub_module_verifier_arch *arch, Elf_Ehdr *e)
{
Elf_Shdr *s;
unsigned i;
for (i = 0, s = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff));
i < grub_target_to_host16 (e->e_shnum);
i++, s = (Elf_Shdr *) ((char *) s + grub_target_to_host16 (e->e_shentsize)))
if (grub_target_to_host32 (s->sh_type) == SHT_REL || grub_target_to_host32 (s->sh_type) == SHT_RELA)
{
Elf_Shdr *ts;
if (grub_target_to_host32 (s->sh_type) == SHT_REL && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_REL))
grub_util_error ("%s: unsupported SHT_REL", modname);
if (grub_target_to_host32 (s->sh_type) == SHT_RELA && !(arch->flags & GRUB_MODULE_VERIFY_SUPPORTS_RELA))
grub_util_error ("%s: unsupported SHT_RELA", modname);
/* Find the target segment. */
if (grub_target_to_host32 (s->sh_info) >= grub_target_to_host16 (e->e_shnum))
grub_util_error ("%s: orphaned reloc section", modname);
ts = (Elf_Shdr *) ((char *) e + grub_target_to_host (e->e_shoff) + grub_target_to_host32 (s->sh_info) * grub_target_to_host16 (e->e_shentsize));
section_check_relocations (modname, arch, e, s, grub_target_to_host (ts->sh_size));
}
}
void
SUFFIX(grub_module_verify) (const char * const filename,
void *module_img, size_t size,
const struct grub_module_verifier_arch *arch,
const char **whitelist_empty)
{
Elf_Ehdr *e = module_img;
/* Check the header size. */
if (size < sizeof (Elf_Ehdr))
grub_util_error ("%s: ELF header smaller than expected", filename);
/* Check the magic numbers. */
if (e->e_ident[EI_MAG0] != ELFMAG0
|| e->e_ident[EI_MAG1] != ELFMAG1
|| e->e_ident[EI_MAG2] != ELFMAG2
|| e->e_ident[EI_MAG3] != ELFMAG3
|| e->e_ident[EI_VERSION] != EV_CURRENT
|| grub_target_to_host32 (e->e_version) != EV_CURRENT)
grub_util_error ("%s: invalid arch-independent ELF magic", filename);
if (e->e_ident[EI_CLASS] != ELFCLASSXX
|| e->e_ident[EI_DATA] != (arch->bigendian ? ELFDATA2MSB : ELFDATA2LSB)
|| grub_target_to_host16 (e->e_machine) != arch->machine)
grub_util_error ("%s: invalid arch-dependent ELF magic", filename);
if (grub_target_to_host16 (e->e_type) != ET_REL)
{
grub_util_error ("%s: this ELF file is not of the right type", filename);
}
/* Make sure that every section is within the core. */
if (size < grub_target_to_host (e->e_shoff)
+ (grub_uint32_t) grub_target_to_host16 (e->e_shentsize) * grub_target_to_host16(e->e_shnum))
{
grub_util_error ("%s: ELF sections outside core", filename);
}
check_license (filename, arch, e);
Elf_Shdr *s;
const char *modname;
s = find_section (arch, e, ".modname");
if (!s)
grub_util_error ("%s: no module name found", filename);
modname = (const char *) e + grub_target_to_host (s->sh_offset);
check_symbols(arch, e, modname, whitelist_empty);
check_relocations(modname, arch, e);
}
/* grub-mkimage.c - make a bootable image */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/types.h>
#include <grub/elf.h>
#include <grub/aout.h>
#include <grub/i18n.h>
#include <grub/kernel.h>
#include <grub/disk.h>
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/util/resolve.h>
#include <grub/misc.h>
#include <grub/offsets.h>
#include <grub/crypto.h>
#include <grub/dl.h>
#include <time.h>
#include <multiboot.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <grub/efi/pe32.h>
#include <grub/uboot/image.h>
#include <grub/arm/reloc.h>
#include <grub/arm64/reloc.h>
#include <grub/ia64/reloc.h>
#include <grub/osdep/hostfile.h>
#include <grub/util/install.h>
#include <grub/util/mkimage.h>
#define ALIGN_ADDR(x) (ALIGN_UP((x), image_target->voidp_sizeof))
#ifdef USE_LIBLZMA
#include <lzma.h>
#endif
#pragma GCC diagnostic ignored "-Wcast-align"
#define TARGET_NO_FIELD 0xffffffff
/* use 2015-01-01T00:00:00+0000 as a stock timestamp */
#define STABLE_EMBEDDING_TIMESTAMP 1420070400
#define EFI32_HEADER_SIZE ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE \
+ GRUB_PE32_SIGNATURE_SIZE \
+ sizeof (struct grub_pe32_coff_header) \
+ sizeof (struct grub_pe32_optional_header) \
+ 4 * sizeof (struct grub_pe32_section_table), \
GRUB_PE32_FILE_ALIGNMENT)
#define EFI64_HEADER_SIZE ALIGN_UP (GRUB_PE32_MSDOS_STUB_SIZE \
+ GRUB_PE32_SIGNATURE_SIZE \
+ sizeof (struct grub_pe32_coff_header) \
+ sizeof (struct grub_pe64_optional_header) \
+ 4 * sizeof (struct grub_pe32_section_table), \
GRUB_PE32_FILE_ALIGNMENT)
static const struct grub_install_image_target_desc image_targets[] =
{
{
.dirname = "i386-coreboot",
.names = { "i386-coreboot", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_COREBOOT,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.reloc_table_offset = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_I386_COREBOOT_LINK_ADDR,
.elf_target = EM_386,
.link_align = 4,
.mod_gap = GRUB_KERNEL_I386_COREBOOT_MOD_GAP,
.mod_align = GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN
},
{
.dirname = "i386-multiboot",
.names = { "i386-multiboot", NULL},
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_COREBOOT,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_I386_COREBOOT_LINK_ADDR,
.elf_target = EM_386,
.link_align = 4,
.mod_gap = GRUB_KERNEL_I386_COREBOOT_MOD_GAP,
.mod_align = GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN
},
{
.dirname = "i386-pc",
.names = { "i386-pc", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_I386_PC,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_I386_PC_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_I386_PC_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_I386_PC_LINK_ADDR,
.default_compression = GRUB_COMPRESSION_LZMA
},
{
.dirname = "i386-xen_pvh",
.names = { "i386-xen_pvh", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_XEN_PVH,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.elf_target = EM_386,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_I386_XEN_PVH_LINK_ADDR,
.mod_align = GRUB_KERNEL_I386_XEN_PVH_MOD_ALIGN,
.link_align = 4
},
{
.dirname = "i386-pc",
.names = { "i386-pc-pxe", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_I386_PC_PXE,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_I386_PC_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_I386_PC_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_I386_PC_LINK_ADDR,
.default_compression = GRUB_COMPRESSION_LZMA
},
{
.dirname = "i386-pc",
.names = { "i386-pc-eltorito", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_I386_PC_ELTORITO,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_I386_PC_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_I386_PC_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_I386_PC_LINK_ADDR,
.default_compression = GRUB_COMPRESSION_LZMA
},
{
.dirname = "i386-efi",
.names = { "i386-efi", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI32_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_I386,
.elf_target = EM_386,
},
{
.dirname = "i386-ieee1275",
.names = { "i386-ieee1275", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_I386_IEEE1275,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_I386_IEEE1275_LINK_ADDR,
.elf_target = EM_386,
.mod_gap = GRUB_KERNEL_I386_IEEE1275_MOD_GAP,
.mod_align = GRUB_KERNEL_I386_IEEE1275_MOD_ALIGN,
.link_align = 4,
},
{
.dirname = "i386-qemu",
.names = { "i386-qemu", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_QEMU,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_I386_QEMU_LINK_ADDR
},
{
.dirname = "x86_64-efi",
.names = { "x86_64-efi", NULL },
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI64_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_X86_64,
.elf_target = EM_X86_64,
},
{
.dirname = "i386-xen",
.names = { "i386-xen", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_XEN,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = 0,
.elf_target = EM_386,
.mod_gap = GRUB_KERNEL_I386_XEN_MOD_GAP,
.mod_align = GRUB_KERNEL_I386_XEN_MOD_ALIGN,
.link_align = 4
},
{
.dirname = "x86_64-xen",
.names = { "x86_64-xen", NULL },
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_XEN,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = 0,
.elf_target = EM_X86_64,
.mod_gap = GRUB_KERNEL_X86_64_XEN_MOD_GAP,
.mod_align = GRUB_KERNEL_X86_64_XEN_MOD_ALIGN,
.link_align = 8
},
{
.dirname = "mipsel-loongson",
.names = { "mipsel-yeeloong-flash", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_YEELOONG_FLASH,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "mipsel-loongson",
.names = { "mipsel-fuloong2f-flash", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_FULOONG2F_FLASH,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "mipsel-loongson",
.names = { "mipsel-loongson-elf", "mipsel-yeeloong-elf",
"mipsel-fuloong2f-elf", "mipsel-fuloong2e-elf",
"mipsel-fuloong-elf", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_LOONGSON_ELF,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_LOONGSON_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPS_LOONGSON_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_LOONGSON_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "powerpc-ieee1275",
.names = { "powerpc-ieee1275", NULL },
.voidp_sizeof = 4,
.bigendian = 1,
.id = IMAGE_PPC,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_POWERPC_IEEE1275_LINK_ADDR,
.elf_target = EM_PPC,
.mod_gap = GRUB_KERNEL_POWERPC_IEEE1275_MOD_GAP,
.mod_align = GRUB_KERNEL_POWERPC_IEEE1275_MOD_ALIGN,
.link_align = 4
},
{
.dirname = "sparc64-ieee1275",
.names = { "sparc64-ieee1275-raw", NULL },
.voidp_sizeof = 8,
.bigendian = 1,
.id = IMAGE_SPARC64_RAW,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR,
.mod_align = GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN,
},
{
.dirname = "sparc64-ieee1275",
.names = { "sparc64-ieee1275-cdcore", NULL },
.voidp_sizeof = 8,
.bigendian = 1,
.id = IMAGE_SPARC64_CDCORE,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR,
.mod_align = GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN,
},
{
.dirname = "sparc64-ieee1275",
.names = { "sparc64-ieee1275-aout", NULL },
.voidp_sizeof = 8,
.bigendian = 1,
.id = IMAGE_SPARC64_AOUT,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = GRUB_KERNEL_SPARC64_IEEE1275_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_SPARC64_IEEE1275_LINK_ADDR,
.mod_align = GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN,
},
{
.dirname = "ia64-efi",
.names = {"ia64-efi", NULL},
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI64_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_IA64,
.elf_target = EM_IA_64,
},
{
.dirname = "mips-arc",
.names = {"mips-arc", NULL},
.voidp_sizeof = 4,
.bigendian = 1,
.id = IMAGE_MIPS_ARC,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPS_ARC_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_ARC_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "mipsel-arc",
.names = {"mipsel-arc", NULL},
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_MIPS_ARC,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPSEL_ARC_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_ARC_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "mipsel-qemu_mips",
.names = { "mipsel-qemu_mips-elf", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_LOONGSON_ELF,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "mips-qemu_mips",
.names = { "mips-qemu_mips-flash", NULL },
.voidp_sizeof = 4,
.bigendian = 1,
.id = IMAGE_QEMU_MIPS_FLASH,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "mipsel-qemu_mips",
.names = { "mipsel-qemu_mips-flash", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_QEMU_MIPS_FLASH,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "mips-qemu_mips",
.names = { "mips-qemu_mips-elf", NULL },
.voidp_sizeof = 4,
.bigendian = 1,
.id = IMAGE_LOONGSON_ELF,
.flags = PLATFORM_FLAGS_DECOMPRESSORS,
.total_module_size = GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
.decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
.decompressor_uncompressed_addr = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_ADDR,
.section_align = 1,
.vaddr_offset = 0,
.link_addr = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ADDR,
.elf_target = EM_MIPS,
.link_align = GRUB_KERNEL_MIPS_QEMU_MIPS_LINK_ALIGN,
.default_compression = GRUB_COMPRESSION_NONE
},
{
.dirname = "arm-uboot",
.names = { "arm-uboot", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_UBOOT,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = GRUB_KERNEL_ARM_UBOOT_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN,
.vaddr_offset = 0,
.elf_target = EM_ARM,
.mod_gap = GRUB_KERNEL_ARM_UBOOT_MOD_GAP,
.mod_align = GRUB_KERNEL_ARM_UBOOT_MOD_ALIGN,
.link_align = 4
},
/* For coreboot versions that don't support self-relocating images. */
{
.dirname = "arm-coreboot-vexpress",
.names = { "arm-coreboot-vexpress", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_COREBOOT,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = GRUB_KERNEL_ARM_COREBOOT_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN,
.vaddr_offset = 0,
.elf_target = EM_ARM,
.mod_gap = GRUB_KERNEL_ARM_COREBOOT_MOD_GAP,
.mod_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN,
.link_align = 4,
.link_addr = 0x62000000,
},
{
.dirname = "arm-coreboot-veyron",
.names = { "arm-coreboot-veyron", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_COREBOOT,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = GRUB_KERNEL_ARM_COREBOOT_TOTAL_MODULE_SIZE,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN,
.vaddr_offset = 0,
.elf_target = EM_ARM,
.mod_gap = GRUB_KERNEL_ARM_COREBOOT_MOD_GAP,
.mod_align = GRUB_KERNEL_ARM_COREBOOT_MOD_ALIGN,
.link_align = 4,
.link_addr = 0x43000000,
},
{
.dirname = "arm-efi",
.names = { "arm-efi", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI32_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_ARMTHUMB_MIXED,
.elf_target = EM_ARM,
},
{
.dirname = "arm64-efi",
.names = { "arm64-efi", NULL },
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI64_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_ARM64,
.elf_target = EM_AARCH64,
},
{
.dirname = "mips64el-efi",
.names = { "mips64el-efi", NULL },
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI64_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_MIPS,
.elf_target = EM_MIPS,
},
{
.dirname = "riscv32-efi",
.names = { "riscv32-efi", NULL },
.voidp_sizeof = 4,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI32_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_RISCV32,
.elf_target = EM_RISCV,
},
{
.dirname = "riscv64-efi",
.names = { "riscv64-efi", NULL },
.voidp_sizeof = 8,
.bigendian = 0,
.id = IMAGE_EFI,
.flags = PLATFORM_FLAGS_NONE,
.total_module_size = TARGET_NO_FIELD,
.decompressor_compressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_size = TARGET_NO_FIELD,
.decompressor_uncompressed_addr = TARGET_NO_FIELD,
.section_align = GRUB_PE32_SECTION_ALIGNMENT,
.vaddr_offset = EFI64_HEADER_SIZE,
.pe_target = GRUB_PE32_MACHINE_RISCV64,
.elf_target = EM_RISCV,
},
};
#include <grub/lib/LzmaEnc.h>
static void *SzAlloc(void *p __attribute__ ((unused)), size_t size) { return xmalloc(size); }
static void SzFree(void *p __attribute__ ((unused)), void *address) { free(address); }
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
static void
compress_kernel_lzma (char *kernel_img, size_t kernel_size,
char **core_img, size_t *core_size)
{
CLzmaEncProps props;
unsigned char out_props[5];
size_t out_props_size = 5;
LzmaEncProps_Init(&props);
props.dictSize = 1 << 16;
props.lc = 3;
props.lp = 0;
props.pb = 2;
props.numThreads = 1;
*core_img = xmalloc (kernel_size);
*core_size = kernel_size;
if (LzmaEncode ((unsigned char *) *core_img, core_size,
(unsigned char *) kernel_img,
kernel_size,
&props, out_props, &out_props_size,
0, NULL, &g_Alloc, &g_Alloc) != SZ_OK)
grub_util_error ("%s", _("cannot compress the kernel image"));
}
#ifdef USE_LIBLZMA
static void
compress_kernel_xz (char *kernel_img, size_t kernel_size,
char **core_img, size_t *core_size)
{
lzma_stream strm = LZMA_STREAM_INIT;
lzma_ret xzret;
lzma_options_lzma lzopts = {
.dict_size = 1 << 16,
.preset_dict = NULL,
.preset_dict_size = 0,
.lc = 3,
.lp = 0,
.pb = 2,
.mode = LZMA_MODE_NORMAL,
.nice_len = 64,
.mf = LZMA_MF_BT4,
.depth = 0,
};
lzma_filter fltrs[] = {
{ .id = LZMA_FILTER_LZMA2, .options = &lzopts},
{ .id = LZMA_VLI_UNKNOWN, .options = NULL}
};
xzret = lzma_stream_encoder (&strm, fltrs, LZMA_CHECK_NONE);
if (xzret != LZMA_OK)
grub_util_error ("%s", _("cannot compress the kernel image"));
*core_img = xmalloc (kernel_size);
*core_size = kernel_size;
strm.next_in = (unsigned char *) kernel_img;
strm.avail_in = kernel_size;
strm.next_out = (unsigned char *) *core_img;
strm.avail_out = *core_size;
while (1)
{
xzret = lzma_code (&strm, LZMA_FINISH);
if (xzret == LZMA_OK)
continue;
if (xzret == LZMA_STREAM_END)
break;
grub_util_error ("%s", _("cannot compress the kernel image"));
}
*core_size -= strm.avail_out;
}
#endif
static void
compress_kernel (const struct grub_install_image_target_desc *image_target, char *kernel_img,
size_t kernel_size, char **core_img, size_t *core_size,
grub_compression_t comp)
{
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS
&& (comp == GRUB_COMPRESSION_LZMA))
{
compress_kernel_lzma (kernel_img, kernel_size, core_img,
core_size);
return;
}
#ifdef USE_LIBLZMA
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS
&& (comp == GRUB_COMPRESSION_XZ))
{
compress_kernel_xz (kernel_img, kernel_size, core_img,
core_size);
return;
}
#endif
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS
&& (comp != GRUB_COMPRESSION_NONE))
grub_util_error (_("unknown compression %d"), comp);
*core_img = xmalloc (kernel_size);
memcpy (*core_img, kernel_img, kernel_size);
*core_size = kernel_size;
}
const struct grub_install_image_target_desc *
grub_install_get_image_target (const char *arg)
{
unsigned i, j;
for (i = 0; i < ARRAY_SIZE (image_targets); i++)
for (j = 0; j < ARRAY_SIZE (image_targets[i].names) &&
image_targets[i].names[j]; j++)
if (strcmp (arg, image_targets[i].names[j]) == 0)
return &image_targets[i];
return NULL;
}
const char *
grub_util_get_target_dirname (const struct grub_install_image_target_desc *t)
{
return t->dirname;
}
const char *
grub_util_get_target_name (const struct grub_install_image_target_desc *t)
{
return t->names[0];
}
char *
grub_install_get_image_targets_string (void)
{
int format_len = 0;
char *formats;
char *ptr;
unsigned i;
for (i = 0; i < ARRAY_SIZE (image_targets); i++)
format_len += strlen (image_targets[i].names[0]) + 2;
ptr = formats = xmalloc (format_len);
for (i = 0; i < ARRAY_SIZE (image_targets); i++)
{
strcpy (ptr, image_targets[i].names[0]);
ptr += strlen (image_targets[i].names[0]);
*ptr++ = ',';
*ptr++ = ' ';
}
ptr[-2] = 0;
return formats;
}
void
grub_install_generate_image (const char *dir, const char *prefix,
FILE *out, const char *outname, char *mods[],
char *memdisk_path, char **pubkey_paths,
size_t npubkeys, char *config_path,
const struct grub_install_image_target_desc *image_target,
int note, grub_compression_t comp, const char *dtb_path)
{
char *kernel_img, *core_img;
size_t total_module_size, core_size;
size_t memdisk_size = 0, config_size = 0;
size_t prefix_size = 0, dtb_size = 0;
char *kernel_path;
size_t offset;
struct grub_util_path_list *path_list, *p;
size_t decompress_size = 0;
struct grub_mkimage_layout layout;
if (comp == GRUB_COMPRESSION_AUTO)
comp = image_target->default_compression;
if (image_target->id == IMAGE_I386_PC
|| image_target->id == IMAGE_I386_PC_PXE
|| image_target->id == IMAGE_I386_PC_ELTORITO)
comp = GRUB_COMPRESSION_LZMA;
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
kernel_path = grub_util_get_path (dir, "kernel.img");
if (image_target->voidp_sizeof == 8)
total_module_size = sizeof (struct grub_module_info64);
else
total_module_size = sizeof (struct grub_module_info32);
{
size_t i;
for (i = 0; i < npubkeys; i++)
{
size_t curs;
curs = ALIGN_ADDR (grub_util_get_image_size (pubkey_paths[i]));
grub_util_info ("the size of public key %u is 0x%"
GRUB_HOST_PRIxLONG_LONG,
(unsigned) i, (unsigned long long) curs);
total_module_size += curs + sizeof (struct grub_module_header);
}
}
if (memdisk_path)
{
memdisk_size = ALIGN_UP(grub_util_get_image_size (memdisk_path), 512);
grub_util_info ("the size of memory disk is 0x%" GRUB_HOST_PRIxLONG_LONG,
(unsigned long long) memdisk_size);
total_module_size += memdisk_size + sizeof (struct grub_module_header);
}
if (dtb_path)
{
dtb_size = ALIGN_ADDR(grub_util_get_image_size (dtb_path));
total_module_size += dtb_size + sizeof (struct grub_module_header);
}
if (config_path)
{
config_size = ALIGN_ADDR (grub_util_get_image_size (config_path) + 1);
grub_util_info ("the size of config file is 0x%" GRUB_HOST_PRIxLONG_LONG,
(unsigned long long) config_size);
total_module_size += config_size + sizeof (struct grub_module_header);
}
if (prefix)
{
prefix_size = ALIGN_ADDR (strlen (prefix) + 1);
total_module_size += prefix_size + sizeof (struct grub_module_header);
}
for (p = path_list; p; p = p->next)
total_module_size += (ALIGN_ADDR (grub_util_get_image_size (p->name))
+ sizeof (struct grub_module_header));
grub_util_info ("the total module size is 0x%" GRUB_HOST_PRIxLONG_LONG,
(unsigned long long) total_module_size);
if (image_target->voidp_sizeof == 4)
kernel_img = grub_mkimage_load_image32 (kernel_path, total_module_size,
&layout, image_target);
else
kernel_img = grub_mkimage_load_image64 (kernel_path, total_module_size,
&layout, image_target);
if ((image_target->id == IMAGE_XEN || image_target->id == IMAGE_XEN_PVH) &&
layout.align < 4096)
layout.align = 4096;
if ((image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
&& (image_target->total_module_size != TARGET_NO_FIELD))
*((grub_uint32_t *) (kernel_img + image_target->total_module_size))
= grub_host_to_target32 (total_module_size);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
{
memmove (kernel_img + total_module_size, kernel_img, layout.kernel_size);
memset (kernel_img, 0, total_module_size);
}
if (image_target->voidp_sizeof == 8)
{
/* Fill in the grub_module_info structure. */
struct grub_module_info64 *modinfo;
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
modinfo = (struct grub_module_info64 *) kernel_img;
else
modinfo = (struct grub_module_info64 *) (kernel_img + layout.kernel_size);
modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC);
modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info64));
modinfo->size = grub_host_to_target_addr (total_module_size);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
offset = sizeof (struct grub_module_info64);
else
offset = layout.kernel_size + sizeof (struct grub_module_info64);
}
else
{
/* Fill in the grub_module_info structure. */
struct grub_module_info32 *modinfo;
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
modinfo = (struct grub_module_info32 *) kernel_img;
else
modinfo = (struct grub_module_info32 *) (kernel_img + layout.kernel_size);
modinfo->magic = grub_host_to_target32 (GRUB_MODULE_MAGIC);
modinfo->offset = grub_host_to_target_addr (sizeof (struct grub_module_info32));
modinfo->size = grub_host_to_target_addr (total_module_size);
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
offset = sizeof (struct grub_module_info32);
else
offset = layout.kernel_size + sizeof (struct grub_module_info32);
}
for (p = path_list; p; p = p->next)
{
struct grub_module_header *header;
size_t mod_size;
mod_size = ALIGN_ADDR (grub_util_get_image_size (p->name));
header = (struct grub_module_header *) (kernel_img + offset);
header->type = grub_host_to_target32 (OBJ_TYPE_ELF);
header->size = grub_host_to_target32 (mod_size + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (p->name, kernel_img + offset);
offset += mod_size;
}
{
size_t i;
for (i = 0; i < npubkeys; i++)
{
size_t curs;
struct grub_module_header *header;
curs = grub_util_get_image_size (pubkey_paths[i]);
header = (struct grub_module_header *) (kernel_img + offset);
header->type = grub_host_to_target32 (OBJ_TYPE_PUBKEY);
header->size = grub_host_to_target32 (curs + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (pubkey_paths[i], kernel_img + offset);
offset += ALIGN_ADDR (curs);
}
}
if (memdisk_path)
{
struct grub_module_header *header;
header = (struct grub_module_header *) (kernel_img + offset);
header->type = grub_host_to_target32 (OBJ_TYPE_MEMDISK);
header->size = grub_host_to_target32 (memdisk_size + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (memdisk_path, kernel_img + offset);
offset += memdisk_size;
}
if (dtb_path)
{
struct grub_module_header *header;
header = (struct grub_module_header *) (kernel_img + offset);
header->type = grub_host_to_target32 (OBJ_TYPE_DTB);
header->size = grub_host_to_target32 (dtb_size + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (dtb_path, kernel_img + offset);
offset += dtb_size;
}
if (config_path)
{
struct grub_module_header *header;
header = (struct grub_module_header *) (kernel_img + offset);
header->type = grub_host_to_target32 (OBJ_TYPE_CONFIG);
header->size = grub_host_to_target32 (config_size + sizeof (*header));
offset += sizeof (*header);
grub_util_load_image (config_path, kernel_img + offset);
offset += config_size;
}
if (prefix)
{
struct grub_module_header *header;
header = (struct grub_module_header *) (kernel_img + offset);
header->type = grub_host_to_target32 (OBJ_TYPE_PREFIX);
header->size = grub_host_to_target32 (prefix_size + sizeof (*header));
offset += sizeof (*header);
grub_strcpy (kernel_img + offset, prefix);
offset += prefix_size;
}
grub_util_info ("kernel_img=%p, kernel_size=0x%" GRUB_HOST_PRIxLONG_LONG,
kernel_img,
(unsigned long long) layout.kernel_size);
compress_kernel (image_target, kernel_img, layout.kernel_size + total_module_size,
&core_img, &core_size, comp);
free (kernel_img);
grub_util_info ("the core size is 0x%" GRUB_HOST_PRIxLONG_LONG,
(unsigned long long) core_size);
if (!(image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
&& image_target->total_module_size != TARGET_NO_FIELD)
*((grub_uint32_t *) (core_img + image_target->total_module_size))
= grub_host_to_target32 (total_module_size);
if (image_target->flags & PLATFORM_FLAGS_DECOMPRESSORS)
{
char *full_img;
size_t full_size;
char *decompress_path, *decompress_img;
const char *name;
switch (comp)
{
case GRUB_COMPRESSION_XZ:
name = "xz_decompress.img";
break;
case GRUB_COMPRESSION_LZMA:
name = "lzma_decompress.img";
break;
case GRUB_COMPRESSION_NONE:
name = "none_decompress.img";
break;
default:
grub_util_error (_("unknown compression %d"), comp);
}
decompress_path = grub_util_get_path (dir, name);
decompress_size = grub_util_get_image_size (decompress_path);
decompress_img = grub_util_read_image (decompress_path);
if ((image_target->id == IMAGE_I386_PC
|| image_target->id == IMAGE_I386_PC_PXE
|| image_target->id == IMAGE_I386_PC_ELTORITO)
&& decompress_size > GRUB_KERNEL_I386_PC_LINK_ADDR - 0x8200)
grub_util_error ("%s", _("Decompressor is too big"));
if (image_target->decompressor_compressed_size != TARGET_NO_FIELD)
*((grub_uint32_t *) (decompress_img
+ image_target->decompressor_compressed_size))
= grub_host_to_target32 (core_size);
if (image_target->decompressor_uncompressed_size != TARGET_NO_FIELD)
*((grub_uint32_t *) (decompress_img
+ image_target->decompressor_uncompressed_size))
= grub_host_to_target32 (layout.kernel_size + total_module_size);
if (image_target->decompressor_uncompressed_addr != TARGET_NO_FIELD)
{
if (image_target->flags & PLATFORM_FLAGS_MODULES_BEFORE_KERNEL)
*((grub_uint32_t *) (decompress_img + image_target->decompressor_uncompressed_addr))
= grub_host_to_target_addr (image_target->link_addr - total_module_size);
else
*((grub_uint32_t *) (decompress_img + image_target->decompressor_uncompressed_addr))
= grub_host_to_target_addr (image_target->link_addr);
}
full_size = core_size + decompress_size;
full_img = xmalloc (full_size);
memcpy (full_img, decompress_img, decompress_size);
memcpy (full_img + decompress_size, core_img, core_size);
free (core_img);
core_img = full_img;
core_size = full_size;
free (decompress_img);
free (decompress_path);
}
switch (image_target->id)
{
case IMAGE_I386_PC:
case IMAGE_I386_PC_PXE:
case IMAGE_I386_PC_ELTORITO:
if (GRUB_KERNEL_I386_PC_LINK_ADDR + core_size > 0x78000
|| (core_size > (0xffff << GRUB_DISK_SECTOR_BITS))
|| (layout.kernel_size + layout.bss_size
+ GRUB_KERNEL_I386_PC_LINK_ADDR > 0x68000))
grub_util_error (_("core image is too big (0x%x > 0x%x)"),
GRUB_KERNEL_I386_PC_LINK_ADDR + (unsigned) core_size,
0x78000);
/* fallthrough */
case IMAGE_COREBOOT:
case IMAGE_QEMU:
if (image_target->elf_target != EM_ARM && layout.kernel_size + layout.bss_size + GRUB_KERNEL_I386_PC_LINK_ADDR > 0x68000)
grub_util_error (_("kernel image is too big (0x%x > 0x%x)"),
(unsigned) layout.kernel_size + (unsigned) layout.bss_size
+ GRUB_KERNEL_I386_PC_LINK_ADDR,
0x68000);
break;
case IMAGE_LOONGSON_ELF:
case IMAGE_YEELOONG_FLASH:
case IMAGE_FULOONG2F_FLASH:
case IMAGE_EFI:
case IMAGE_MIPS_ARC:
case IMAGE_QEMU_MIPS_FLASH:
case IMAGE_XEN:
case IMAGE_XEN_PVH:
break;
case IMAGE_SPARC64_AOUT:
case IMAGE_SPARC64_RAW:
case IMAGE_SPARC64_CDCORE:
case IMAGE_I386_IEEE1275:
case IMAGE_PPC:
case IMAGE_UBOOT:
break;
}
switch (image_target->id)
{
case IMAGE_I386_PC:
case IMAGE_I386_PC_PXE:
case IMAGE_I386_PC_ELTORITO:
{
unsigned num;
char *boot_path, *boot_img;
size_t boot_size;
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
if (image_target->id == IMAGE_I386_PC_PXE)
{
char *pxeboot_path, *pxeboot_img;
size_t pxeboot_size;
grub_uint32_t *ptr;
pxeboot_path = grub_util_get_path (dir, "pxeboot.img");
pxeboot_size = grub_util_get_image_size (pxeboot_path);
pxeboot_img = grub_util_read_image (pxeboot_path);
grub_util_write_image (pxeboot_img, pxeboot_size, out,
outname);
free (pxeboot_img);
free (pxeboot_path);
/* Remove Multiboot header to avoid confusing ipxe. */
for (ptr = (grub_uint32_t *) core_img;
ptr < (grub_uint32_t *) (core_img + MULTIBOOT_SEARCH); ptr++)
if (*ptr == grub_host_to_target32 (MULTIBOOT_HEADER_MAGIC)
&& grub_target_to_host32 (ptr[0])
+ grub_target_to_host32 (ptr[1])
+ grub_target_to_host32 (ptr[2]) == 0)
{
*ptr = 0;
break;
}
}
if (image_target->id == IMAGE_I386_PC_ELTORITO)
{
char *eltorito_path, *eltorito_img;
size_t eltorito_size;
eltorito_path = grub_util_get_path (dir, "cdboot.img");
eltorito_size = grub_util_get_image_size (eltorito_path);
eltorito_img = grub_util_read_image (eltorito_path);
grub_util_write_image (eltorito_img, eltorito_size, out,
outname);
free (eltorito_img);
free (eltorito_path);
}
boot_path = grub_util_get_path (dir, "diskboot.img");
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("diskboot.img size must be %u bytes"),
GRUB_DISK_SECTOR_SIZE);
boot_img = grub_util_read_image (boot_path);
{
struct grub_pc_bios_boot_blocklist *block;
block = (struct grub_pc_bios_boot_blocklist *) (boot_img
+ GRUB_DISK_SECTOR_SIZE
- sizeof (*block));
block->len = grub_host_to_target16 (num);
/* This is filled elsewhere. Verify it just in case. */
assert (block->segment
== grub_host_to_target16 (GRUB_BOOT_I386_PC_KERNEL_SEG
+ (GRUB_DISK_SECTOR_SIZE >> 4)));
}
grub_util_write_image (boot_img, boot_size, out, outname);
free (boot_img);
free (boot_path);
}
break;
case IMAGE_EFI:
{
void *pe_img;
grub_uint8_t *header;
void *sections;
size_t pe_size;
struct grub_pe32_coff_header *c;
struct grub_pe32_section_table *text_section, *data_section;
struct grub_pe32_section_table *mods_section, *reloc_section;
static const grub_uint8_t stub[] = GRUB_PE32_MSDOS_STUB;
int header_size;
int reloc_addr;
if (image_target->voidp_sizeof == 4)
header_size = EFI32_HEADER_SIZE;
else
header_size = EFI64_HEADER_SIZE;
reloc_addr = ALIGN_UP (header_size + core_size,
GRUB_PE32_FILE_ALIGNMENT);
pe_size = ALIGN_UP (reloc_addr + layout.reloc_size,
GRUB_PE32_FILE_ALIGNMENT);
pe_img = xmalloc (reloc_addr + layout.reloc_size);
memset (pe_img, 0, header_size);
memcpy ((char *) pe_img + header_size, core_img, core_size);
memset ((char *) pe_img + header_size + core_size, 0, reloc_addr - (header_size + core_size));
memcpy ((char *) pe_img + reloc_addr, layout.reloc_section, layout.reloc_size);
header = pe_img;
/* The magic. */
memcpy (header, stub, GRUB_PE32_MSDOS_STUB_SIZE);
memcpy (header + GRUB_PE32_MSDOS_STUB_SIZE, "PE\0\0",
GRUB_PE32_SIGNATURE_SIZE);
/* The COFF file header. */
c = (struct grub_pe32_coff_header *) (header + GRUB_PE32_MSDOS_STUB_SIZE
+ GRUB_PE32_SIGNATURE_SIZE);
c->machine = grub_host_to_target16 (image_target->pe_target);
c->num_sections = grub_host_to_target16 (4);
c->time = grub_host_to_target32 (STABLE_EMBEDDING_TIMESTAMP);
c->characteristics = grub_host_to_target16 (GRUB_PE32_EXECUTABLE_IMAGE
| GRUB_PE32_LINE_NUMS_STRIPPED
| ((image_target->voidp_sizeof == 4)
? GRUB_PE32_32BIT_MACHINE
: 0)
| GRUB_PE32_LOCAL_SYMS_STRIPPED
| GRUB_PE32_DEBUG_STRIPPED);
/* The PE Optional header. */
if (image_target->voidp_sizeof == 4)
{
struct grub_pe32_optional_header *o;
c->optional_header_size = grub_host_to_target16 (sizeof (struct grub_pe32_optional_header));
o = (struct grub_pe32_optional_header *)
(header + GRUB_PE32_MSDOS_STUB_SIZE + GRUB_PE32_SIGNATURE_SIZE
+ sizeof (struct grub_pe32_coff_header));
o->magic = grub_host_to_target16 (GRUB_PE32_PE32_MAGIC);
o->code_size = grub_host_to_target32 (layout.exec_size);
o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size
- header_size);
o->bss_size = grub_cpu_to_le32 (layout.bss_size);
o->entry_addr = grub_cpu_to_le32 (layout.start_address);
o->code_base = grub_cpu_to_le32 (header_size);
o->data_base = grub_host_to_target32 (header_size + layout.exec_size);
o->image_base = 0;
o->section_alignment = grub_host_to_target32 (image_target->section_align);
o->file_alignment = grub_host_to_target32 (GRUB_PE32_FILE_ALIGNMENT);
o->image_size = grub_host_to_target32 (pe_size);
o->header_size = grub_host_to_target32 (header_size);
o->subsystem = grub_host_to_target16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION);
/* Do these really matter? */
o->stack_reserve_size = grub_host_to_target32 (0x10000);
o->stack_commit_size = grub_host_to_target32 (0x10000);
o->heap_reserve_size = grub_host_to_target32 (0x10000);
o->heap_commit_size = grub_host_to_target32 (0x10000);
o->num_data_directories = grub_host_to_target32 (GRUB_PE32_NUM_DATA_DIRECTORIES);
o->base_relocation_table.rva = grub_host_to_target32 (reloc_addr);
o->base_relocation_table.size = grub_host_to_target32 (layout.reloc_size);
sections = o + 1;
}
else
{
struct grub_pe64_optional_header *o;
c->optional_header_size = grub_host_to_target16 (sizeof (struct grub_pe64_optional_header));
o = (struct grub_pe64_optional_header *)
(header + GRUB_PE32_MSDOS_STUB_SIZE + GRUB_PE32_SIGNATURE_SIZE
+ sizeof (struct grub_pe32_coff_header));
o->magic = grub_host_to_target16 (GRUB_PE32_PE64_MAGIC);
o->code_size = grub_host_to_target32 (layout.exec_size);
o->data_size = grub_cpu_to_le32 (reloc_addr - layout.exec_size
- header_size);
o->bss_size = grub_cpu_to_le32 (layout.bss_size);
o->entry_addr = grub_cpu_to_le32 (layout.start_address);
o->code_base = grub_cpu_to_le32 (header_size);
o->image_base = 0;
o->section_alignment = grub_host_to_target32 (image_target->section_align);
o->file_alignment = grub_host_to_target32 (GRUB_PE32_FILE_ALIGNMENT);
o->image_size = grub_host_to_target32 (pe_size);
o->header_size = grub_host_to_target32 (header_size);
o->subsystem = grub_host_to_target16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION);
/* Do these really matter? */
o->stack_reserve_size = grub_host_to_target64 (0x10000);
o->stack_commit_size = grub_host_to_target64 (0x10000);
o->heap_reserve_size = grub_host_to_target64 (0x10000);
o->heap_commit_size = grub_host_to_target64 (0x10000);
o->num_data_directories
= grub_host_to_target32 (GRUB_PE32_NUM_DATA_DIRECTORIES);
o->base_relocation_table.rva = grub_host_to_target32 (reloc_addr);
o->base_relocation_table.size = grub_host_to_target32 (layout.reloc_size);
sections = o + 1;
}
/* The sections. */
text_section = sections;
strcpy (text_section->name, ".text");
text_section->virtual_size = grub_cpu_to_le32 (layout.exec_size);
text_section->virtual_address = grub_cpu_to_le32 (header_size);
text_section->raw_data_size = grub_cpu_to_le32 (layout.exec_size);
text_section->raw_data_offset = grub_cpu_to_le32 (header_size);
text_section->characteristics = grub_cpu_to_le32_compile_time (
GRUB_PE32_SCN_CNT_CODE
| GRUB_PE32_SCN_MEM_EXECUTE
| GRUB_PE32_SCN_MEM_READ);
data_section = text_section + 1;
strcpy (data_section->name, ".data");
data_section->virtual_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size);
data_section->virtual_address = grub_cpu_to_le32 (header_size + layout.exec_size);
data_section->raw_data_size = grub_cpu_to_le32 (layout.kernel_size - layout.exec_size);
data_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.exec_size);
data_section->characteristics
= grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
| GRUB_PE32_SCN_MEM_READ
| GRUB_PE32_SCN_MEM_WRITE);
#if 0
bss_section = data_section + 1;
strcpy (bss_section->name, ".bss");
bss_section->virtual_size = grub_cpu_to_le32 (layout.bss_size);
bss_section->virtual_address = grub_cpu_to_le32 (header_size + layout.kernel_size);
bss_section->raw_data_size = 0;
bss_section->raw_data_offset = 0;
bss_section->characteristics
= grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_MEM_READ
| GRUB_PE32_SCN_MEM_WRITE
| GRUB_PE32_SCN_ALIGN_64BYTES
| GRUB_PE32_SCN_CNT_INITIALIZED_DATA
| 0x80);
#endif
mods_section = data_section + 1;
strcpy (mods_section->name, "mods");
mods_section->virtual_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size);
mods_section->virtual_address = grub_cpu_to_le32 (header_size + layout.kernel_size + layout.bss_size);
mods_section->raw_data_size = grub_cpu_to_le32 (reloc_addr - layout.kernel_size - header_size);
mods_section->raw_data_offset = grub_cpu_to_le32 (header_size + layout.kernel_size);
mods_section->characteristics
= grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
| GRUB_PE32_SCN_MEM_READ
| GRUB_PE32_SCN_MEM_WRITE);
reloc_section = mods_section + 1;
strcpy (reloc_section->name, ".reloc");
reloc_section->virtual_size = grub_cpu_to_le32 (layout.reloc_size);
reloc_section->virtual_address = grub_cpu_to_le32 (reloc_addr + layout.bss_size);
reloc_section->raw_data_size = grub_cpu_to_le32 (layout.reloc_size);
reloc_section->raw_data_offset = grub_cpu_to_le32 (reloc_addr);
reloc_section->characteristics
= grub_cpu_to_le32_compile_time (GRUB_PE32_SCN_CNT_INITIALIZED_DATA
| GRUB_PE32_SCN_MEM_DISCARDABLE
| GRUB_PE32_SCN_MEM_READ);
free (core_img);
core_img = pe_img;
core_size = pe_size;
}
break;
case IMAGE_QEMU:
{
char *rom_img;
size_t rom_size;
char *boot_path, *boot_img;
size_t boot_size;
boot_path = grub_util_get_path (dir, "boot.img");
boot_size = grub_util_get_image_size (boot_path);
boot_img = grub_util_read_image (boot_path);
/* Rom sizes must be 64k-aligned. */
rom_size = ALIGN_UP (core_size + boot_size, 64 * 1024);
rom_img = xmalloc (rom_size);
memset (rom_img, 0, rom_size);
*((grub_int32_t *) (core_img + GRUB_KERNEL_I386_QEMU_CORE_ENTRY_ADDR))
= grub_host_to_target32 ((grub_uint32_t) -rom_size);
memcpy (rom_img, core_img, core_size);
*((grub_int32_t *) (boot_img + GRUB_BOOT_I386_QEMU_CORE_ENTRY_ADDR))
= grub_host_to_target32 ((grub_uint32_t) -rom_size);
memcpy (rom_img + rom_size - boot_size, boot_img, boot_size);
free (core_img);
core_img = rom_img;
core_size = rom_size;
free (boot_img);
free (boot_path);
}
break;
case IMAGE_SPARC64_AOUT:
{
void *aout_img;
size_t aout_size;
struct grub_aout32_header *aout_head;
aout_size = core_size + sizeof (*aout_head);
aout_img = xmalloc (aout_size);
aout_head = aout_img;
grub_memset (aout_head, 0, sizeof (*aout_head));
aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16)
| AOUT32_OMAGIC);
aout_head->a_text = grub_host_to_target32 (core_size);
aout_head->a_entry
= grub_host_to_target32 (GRUB_BOOT_SPARC64_IEEE1275_IMAGE_ADDRESS);
memcpy ((char *) aout_img + sizeof (*aout_head), core_img, core_size);
free (core_img);
core_img = aout_img;
core_size = aout_size;
}
break;
case IMAGE_SPARC64_RAW:
{
unsigned int num;
char *boot_path, *boot_img;
size_t boot_size;
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
num <<= GRUB_DISK_SECTOR_BITS;
boot_path = grub_util_get_path (dir, "diskboot.img");
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error (_("diskboot.img size must be %u bytes"),
GRUB_DISK_SECTOR_SIZE);
boot_img = grub_util_read_image (boot_path);
*((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
- GRUB_BOOT_SPARC64_IEEE1275_LIST_SIZE + 8))
= grub_host_to_target32 (num);
grub_util_write_image (boot_img, boot_size, out, outname);
free (boot_img);
free (boot_path);
}
break;
case IMAGE_SPARC64_CDCORE:
break;
case IMAGE_YEELOONG_FLASH:
case IMAGE_FULOONG2F_FLASH:
{
char *rom_img;
size_t rom_size;
char *boot_path, *boot_img;
size_t boot_size;
/* fwstart.img is the only part which can't be tested by using *-elf
target. Check it against the checksum. */
const grub_uint8_t yeeloong_fwstart_good_hash[512 / 8] =
{
0x5f, 0x67, 0x46, 0x57, 0x31, 0x30, 0xc5, 0x0a,
0xe9, 0x98, 0x18, 0xc9, 0xf3, 0xca, 0x45, 0xa5,
0x75, 0x64, 0x6b, 0xbb, 0x24, 0xcd, 0xb4, 0xbc,
0xf2, 0x3e, 0x23, 0xf9, 0xc2, 0x6a, 0x8c, 0xde,
0x3b, 0x94, 0x9c, 0xcc, 0xa5, 0xa7, 0x58, 0xb1,
0xbe, 0x8b, 0x3d, 0x73, 0x98, 0x18, 0x7e, 0x68,
0x5e, 0x5f, 0x23, 0x7d, 0x7a, 0xe8, 0x51, 0xf7,
0x1a, 0xaf, 0x2f, 0x54, 0x11, 0x2e, 0x5c, 0x25
};
const grub_uint8_t fuloong2f_fwstart_good_hash[512 / 8] =
{
0x76, 0x9b, 0xad, 0x6e, 0xa2, 0x39, 0x47, 0x62,
0x1f, 0xc9, 0x3a, 0x6d, 0x05, 0x5c, 0x43, 0x5c,
0x29, 0x4a, 0x7e, 0x08, 0x2a, 0x31, 0x8f, 0x5d,
0x02, 0x84, 0xa0, 0x85, 0xf2, 0xd1, 0xb9, 0x53,
0xa2, 0xbc, 0xf2, 0xe1, 0x39, 0x1e, 0x51, 0xb5,
0xaf, 0xec, 0x9e, 0xf2, 0xf1, 0xf3, 0x0a, 0x2f,
0xe6, 0xf1, 0x08, 0x89, 0xbe, 0xbc, 0x73, 0xab,
0x46, 0x50, 0xd6, 0x21, 0xce, 0x8e, 0x24, 0xa7
};
const grub_uint8_t *fwstart_good_hash;
grub_uint8_t fwstart_hash[512 / 8];
if (image_target->id == IMAGE_FULOONG2F_FLASH)
{
fwstart_good_hash = fuloong2f_fwstart_good_hash;
boot_path = grub_util_get_path (dir, "fwstart_fuloong2f.img");
}
else
{
fwstart_good_hash = yeeloong_fwstart_good_hash;
boot_path = grub_util_get_path (dir, "fwstart.img");
}
boot_size = grub_util_get_image_size (boot_path);
boot_img = grub_util_read_image (boot_path);
grub_crypto_hash (GRUB_MD_SHA512, fwstart_hash, boot_img, boot_size);
if (grub_memcmp (fwstart_hash, fwstart_good_hash,
GRUB_MD_SHA512->mdlen) != 0)
/* TRANSLATORS: fwstart.img may still be good, just it wasn't checked. */
grub_util_warn ("%s",
_("fwstart.img doesn't match the known good version. "
"proceed at your own risk"));
if (core_size + boot_size > 512 * 1024)
grub_util_error ("%s", _("firmware image is too big"));
rom_size = 512 * 1024;
rom_img = xmalloc (rom_size);
memset (rom_img, 0, rom_size);
memcpy (rom_img, boot_img, boot_size);
memcpy (rom_img + boot_size, core_img, core_size);
memset (rom_img + boot_size + core_size, 0,
rom_size - (boot_size + core_size));
free (core_img);
core_img = rom_img;
core_size = rom_size;
free (boot_img);
free (boot_path);
}
break;
case IMAGE_QEMU_MIPS_FLASH:
{
char *rom_img;
size_t rom_size;
if (core_size > 512 * 1024)
grub_util_error ("%s", _("firmware image is too big"));
rom_size = 512 * 1024;
rom_img = xmalloc (rom_size);
memset (rom_img, 0, rom_size);
memcpy (rom_img, core_img, core_size);
memset (rom_img + core_size, 0,
rom_size - core_size);
free (core_img);
core_img = rom_img;
core_size = rom_size;
}
break;
case IMAGE_UBOOT:
{
struct grub_uboot_image_header *hdr;
hdr = xmalloc (core_size + sizeof (struct grub_uboot_image_header));
memcpy (hdr + 1, core_img, core_size);
memset (hdr, 0, sizeof (*hdr));
hdr->ih_magic = grub_cpu_to_be32_compile_time (GRUB_UBOOT_IH_MAGIC);
hdr->ih_time = grub_cpu_to_be32 (STABLE_EMBEDDING_TIMESTAMP);
hdr->ih_size = grub_cpu_to_be32 (core_size);
hdr->ih_load = 0;
hdr->ih_ep = 0;
hdr->ih_type = GRUB_UBOOT_IH_TYPE_KERNEL_NOLOAD;
hdr->ih_os = GRUB_UBOOT_IH_OS_LINUX;
hdr->ih_arch = GRUB_UBOOT_IH_ARCH_ARM;
hdr->ih_comp = GRUB_UBOOT_IH_COMP_NONE;
grub_crypto_hash (GRUB_MD_CRC32, &hdr->ih_dcrc, hdr + 1, core_size);
grub_crypto_hash (GRUB_MD_CRC32, &hdr->ih_hcrc, hdr, sizeof (*hdr));
free (core_img);
core_img = (char *) hdr;
core_size += sizeof (struct grub_uboot_image_header);
}
break;
case IMAGE_MIPS_ARC:
{
char *ecoff_img;
struct ecoff_header {
grub_uint16_t magic;
grub_uint16_t nsec;
grub_uint32_t time;
grub_uint32_t syms;
grub_uint32_t nsyms;
grub_uint16_t opt;
grub_uint16_t flags;
grub_uint16_t magic2;
grub_uint16_t version;
grub_uint32_t textsize;
grub_uint32_t datasize;
grub_uint32_t bsssize;
grub_uint32_t entry;
grub_uint32_t text_start;
grub_uint32_t data_start;
grub_uint32_t bss_start;
grub_uint32_t gprmask;
grub_uint32_t cprmask[4];
grub_uint32_t gp_value;
};
struct ecoff_section
{
char name[8];
grub_uint32_t paddr;
grub_uint32_t vaddr;
grub_uint32_t size;
grub_uint32_t file_offset;
grub_uint32_t reloc;
grub_uint32_t gp;
grub_uint16_t nreloc;
grub_uint16_t ngp;
grub_uint32_t flags;
};
struct ecoff_header *head;
struct ecoff_section *section;
grub_uint32_t target_addr;
size_t program_size;
program_size = ALIGN_ADDR (core_size);
if (comp == GRUB_COMPRESSION_NONE)
target_addr = (image_target->link_addr - decompress_size);
else
target_addr = ALIGN_UP (image_target->link_addr
+ layout.kernel_size + total_module_size, 32);
ecoff_img = xmalloc (program_size + sizeof (*head) + sizeof (*section));
grub_memset (ecoff_img, 0, program_size + sizeof (*head) + sizeof (*section));
head = (void *) ecoff_img;
section = (void *) (head + 1);
head->magic = image_target->bigendian ? grub_host_to_target16 (0x160)
: grub_host_to_target16 (0x166);
head->nsec = grub_host_to_target16 (1);
head->time = grub_host_to_target32 (0);
head->opt = grub_host_to_target16 (0x38);
head->flags = image_target->bigendian
? grub_host_to_target16 (0x207)
: grub_host_to_target16 (0x103);
head->magic2 = grub_host_to_target16 (0x107);
head->textsize = grub_host_to_target32 (program_size);
head->entry = grub_host_to_target32 (target_addr);
head->text_start = grub_host_to_target32 (target_addr);
head->data_start = grub_host_to_target32 (target_addr + program_size);
grub_memcpy (section->name, ".text", sizeof (".text") - 1);
section->vaddr = grub_host_to_target32 (target_addr);
section->size = grub_host_to_target32 (program_size);
section->file_offset = grub_host_to_target32 (sizeof (*head) + sizeof (*section));
if (!image_target->bigendian)
{
section->paddr = grub_host_to_target32 (0xaa60);
section->flags = grub_host_to_target32 (0x20);
}
memcpy (section + 1, core_img, core_size);
free (core_img);
core_img = ecoff_img;
core_size = program_size + sizeof (*head) + sizeof (*section);
}
break;
case IMAGE_LOONGSON_ELF:
case IMAGE_PPC:
case IMAGE_XEN:
case IMAGE_XEN_PVH:
case IMAGE_COREBOOT:
case IMAGE_I386_IEEE1275:
{
grub_uint64_t target_addr;
if (image_target->id == IMAGE_LOONGSON_ELF)
{
if (comp == GRUB_COMPRESSION_NONE)
target_addr = (image_target->link_addr - decompress_size);
else
target_addr = ALIGN_UP (image_target->link_addr
+ layout.kernel_size + total_module_size, 32);
}
else
target_addr = image_target->link_addr;
if (image_target->voidp_sizeof == 4)
grub_mkimage_generate_elf32 (image_target, note, &core_img, &core_size,
target_addr, &layout);
else
grub_mkimage_generate_elf64 (image_target, note, &core_img, &core_size,
target_addr, &layout);
}
break;
}
grub_util_write_image (core_img, core_size, out, outname);
free (core_img);
free (kernel_path);
free (layout.reloc_section);
grub_util_free_path_list (path_list);
}
......@@ -55,6 +55,23 @@ make -j 16 || exit 1
sh install.sh arm64
#build for mips64el EFI
#http://ftp.loongnix.org/os/loongnix-server/1.7/os/Source/SPackages/grub2-2.02-0.40.lns7.14.loongnix.src.rpm
make distclean
./autogen.sh
./configure --prefix=/home/share/Ventoy/GRUB2/INSTALL/ \
--target=mips64el --with-platform=efi \
--host=x86_64-linux-gnu \
HOST_CC=x86_64-linux-gnu-gcc \
BUILD_CC=gcc \
TARGET_CC="mips-linux-gnu-gcc -mabi=64 -Wno-error=cast-align -Wno-error=misleading-indentation" \
TARGET_OBJCOPY=mips-linux-gnu-objcopy \
TARGET_STRIP=mips-linux-gnu-strip TARGET_NM=mips-linux-gnu-nm \
TARGET_RANLIB=mips-linux-gnu-ranlib
make -j 16 || exit 1
sh install.sh mips64el
# build for i386-pc
echo '======== build grub2 for i386-pc ==============='
......
......@@ -36,20 +36,34 @@ export SED=$BUSYBOX_PATH/sed
export SLEEP=$BUSYBOX_PATH/sleep
export HEAD=$BUSYBOX_PATH/head
if [ -e $BUSYBOX_PATH/32h ]; then
if [ -e $BUSYBOX_PATH/64h ]; then
#this is arm64
$BUSYBOX_PATH/xzminidecaa64 < $BUSYBOX_PATH/busyboxaa64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmodaa64 $BUSYBOX_PATH/busybox
if [ -e $BUSYBOX_PATH/busyboxaa64.xz ]; then
export VTOY_ARCH=aarch64
elif [ -e $BUSYBOX_PATH/busyboxm64e.xz ]; then
export VTOY_ARCH=mips64el
else
if [ -e $BUSYBOX_PATH/32h ]; then
export VTOY_ARCH=x86_64
else
export VTOY_ARCH=i386
fi
fi
echo $VTOY_ARCH > $VTOY_PATH/ventoy_arch
if [ "$VTOY_ARCH" = "aarch64" ]; then
$BUSYBOX_PATH/xzminidecaa64 < $BUSYBOX_PATH/busyboxaa64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmodaa64 $BUSYBOX_PATH/busybox
elif [ "$VTOY_ARCH" = "mips64el" ]; then
$BUSYBOX_PATH/xzminidecm64e < $BUSYBOX_PATH/busyboxm64e.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmodm64e $BUSYBOX_PATH/busybox
elif [ "$VTOY_ARCH" = "x86_64" ]; then
$BUSYBOX_PATH/xzminidec64 < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
if [ -s $BUSYBOX_PATH/busybox ]; then
$BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
else
#this is x86_64
$BUSYBOX_PATH/xzminidec64 < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
if [ -s $BUSYBOX_PATH/busybox ]; then
$BUSYBOX_PATH/vtchmod64 $BUSYBOX_PATH/busybox
else
$BUSYBOX_PATH/xzminidec64_musl < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod64_musl $BUSYBOX_PATH/busybox
fi
$BUSYBOX_PATH/xzminidec64_musl < $BUSYBOX_PATH/busybox64.xz > $BUSYBOX_PATH/busybox
$BUSYBOX_PATH/vtchmod64_musl $BUSYBOX_PATH/busybox
fi
else
$BUSYBOX_PATH/xzminidec32 < $BUSYBOX_PATH/busybox32.xz > $BUSYBOX_PATH/busybox
......@@ -91,35 +105,47 @@ else
xz -d -c loop.cpio.xz | cpio -idm 2>>$VTLOG
fi
if [ -e $BUSYBOX_PATH/32h ]; then
if [ -e $BUSYBOX_PATH/64h ]; then
echo "Use ARM64 busybox toolkit ..." >>$VTLOG
echo aarch64 > $VTOY_PATH/ventoy_arch
ln -s $BUSYBOX_PATH/xzminidecaa64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetupaa64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzipaa64 $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4cataa64 $VTOY_PATH/tool/lz4cat
ln -s $VTOY_PATH/tool/zstdcataa64 $VTOY_PATH/tool/zstdcat
else
echo "Use x86_64 busybox toolkit ..." >>$VTLOG
echo x86_64 > $VTOY_PATH/ventoy_arch
ln -s $BUSYBOX_PATH/xzminidec64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetup64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzip64 $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4cat64 $VTOY_PATH/tool/lz4cat
ln -s $VTOY_PATH/tool/zstdcat64 $VTOY_PATH/tool/zstdcat
fi
else
if [ "$VTOY_ARCH" = "x86_64" ]; then
echo "Use x86_64 busybox toolkit ..." >>$VTLOG
ln -s $BUSYBOX_PATH/xzminidec64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetup64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzip64 $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4cat64 $VTOY_PATH/tool/lz4cat
ln -s $VTOY_PATH/tool/zstdcat64 $VTOY_PATH/tool/zstdcat
elif [ "$VTOY_ARCH" = "i386" ]; then
echo "Use i386 busybox toolkit ..." >>$VTLOG
echo i386 > $VTOY_PATH/ventoy_arch
ln -s $BUSYBOX_PATH/xzminidec32 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetup32 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzip32 $VTOY_PATH/tool/lunzip
elif [ "$VTOY_ARCH" = "mips64el" ]; then
echo "Use MIPS64 busybox toolkit ..." >>$VTLOG
ln -s $BUSYBOX_PATH/xzminidecm64e $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetupm64e $VTOY_PATH/tool/dmsetup
# TBD
#ln -s $VTOY_PATH/tool/lunzipm64e $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4catm64e $VTOY_PATH/tool/lz4cat
# TBD
#ln -s $VTOY_PATH/tool/zstdcataa64 $VTOY_PATH/tool/zstdcat
elif [ "$VTOY_ARCH" = "aarch64" ]; then
echo "Use ARM64 busybox toolkit ..." >>$VTLOG
ln -s $BUSYBOX_PATH/xzminidecaa64 $BUSYBOX_PATH/xzminidec
ln -s $VTOY_PATH/tool/dmsetupaa64 $VTOY_PATH/tool/dmsetup
ln -s $VTOY_PATH/tool/lunzipaa64 $VTOY_PATH/tool/lunzip
rm -f $VTOY_PATH/tool/lz4cat $VTOY_PATH/tool/zstdcat
ln -s $VTOY_PATH/tool/lz4cataa64 $VTOY_PATH/tool/lz4cat
ln -s $VTOY_PATH/tool/zstdcataa64 $VTOY_PATH/tool/zstdcat
else
echo "Unknown busybox toolkit ..." >>$VTLOG
fi
rm -f *.xz
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment