Add support for device-tree-based drivers.

This commit is contained in:
Vladimir Serbinenko 2017-05-08 21:19:59 +02:00
parent 24e37a8852
commit fcbb723d4b
13 changed files with 519 additions and 52 deletions

View file

@ -499,7 +499,7 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix,
grub_install_generate_image (dir, prefix, fp, outname,
modules.entries, memdisk_path,
pubkeys, npubkeys, config_path, tgt,
note, compression);
note, compression, 0);
while (dc--)
grub_install_pop_module ();
}

View file

@ -71,6 +71,7 @@ static struct argp_option options[] = {
N_("embed FILE as a memdisk image\n"
"Implies `-p (memdisk)/boot/grub' and overrides any prefix supplied previously,"
" but the prefix itself can be overridden by later options"), 0},
{"dtb", 'D', N_("FILE"), 0, N_("embed FILE as a device tree (DTB)\n"), 0},
/* TRANSLATORS: "embed" is a verb (command description). "*/
{"config", 'c', N_("FILE"), 0, N_("embed FILE as an early config"), 0},
/* TRANSLATORS: "embed" is a verb (command description). "*/
@ -117,6 +118,7 @@ struct arguments
char *dir;
char *prefix;
char *memdisk;
char *dtb;
char **pubkeys;
size_t npubkeys;
char *font;
@ -176,6 +178,13 @@ argp_parser (int key, char *arg, struct argp_state *state)
arguments->prefix = xstrdup ("(memdisk)/boot/grub");
break;
case 'D':
if (arguments->dtb)
free (arguments->dtb);
arguments->dtb = xstrdup (arg);
break;
case 'k':
arguments->pubkeys = xrealloc (arguments->pubkeys,
sizeof (arguments->pubkeys[0])
@ -300,7 +309,7 @@ main (int argc, char *argv[])
arguments.memdisk, arguments.pubkeys,
arguments.npubkeys, arguments.config,
arguments.image_target, arguments.note,
arguments.comp);
arguments.comp, arguments.dtb);
grub_util_file_sync (fp);
fclose (fp);

View file

@ -777,13 +777,12 @@ grub_install_generate_image (const char *dir, const char *prefix,
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)
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;
size_t prefix_size = 0, dtb_size = 0;
char *kernel_path;
size_t offset;
struct grub_util_path_list *path_list, *p;
@ -828,6 +827,12 @@ grub_install_generate_image (const char *dir, const char *prefix,
total_module_size += memdisk_size + sizeof (struct grub_module_header);
}
if (dtb_path)
{
dtb_size = ALIGN_UP(grub_util_get_image_size (dtb_path), 4);
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);
@ -950,6 +955,19 @@ grub_install_generate_image (const char *dir, const char *prefix,
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;