arm64: Add multiboot support file
PATCH 4/5 arm64: Add multiboot support file
grub-core/loader/arm64/multiboot.c
include/grub/arm64/multiboot.h
Add commands register code and hearder file intogrub-core/loader/arm64/linux.c
- This multiboot support is built into linux module for aarch64.
- The implementation for Xen is following <Multiboot on ARM Specification>:
http://wiki.xen.org/wiki/Xen_ARM_with_Virtualization_Extensions/Multiboot
and xen/docs/misc/arm/device-tree/booting.txt in Xen source code.
- This adds support for the Xen Multiboot on ARM specification for arm64, enabling config file portability across the architectures.
- The multiboot command is currently x86-only, so reusing these command names should not conflict with any future additions of ARM support to multiboot2.
- The reason of adding this functionality to the existing "linux" module rather than "multiboot(2)"
(1)multiboot is x86 only
(2)Multiboot is added to "linux" module because it reuses existing code.
--- grub-core/Makefile.core.def | 1 + grub-core/loader/arm64/linux.c | 6 + grub-core/loader/arm64/multiboot.c | 593 +++++++++++++++++++++++++++++++++++++ include/grub/arm64/multiboot.h | 115 +++++++ 4 files changed, 715 insertions(+) create mode 100644 grub-core/loader/arm64/multiboot.c create mode 100644 include/grub/arm64/multiboot.h
grub-core/Makefile.core.def +1 -0
@@ -1673,6 +1673,7 @@ module = { ia64_efi = loader/ia64/efi/linux.c; arm = loader/arm/linux.c; arm64 = loader/arm64/linux.c; + arm64 = loader/arm64/multiboot.c; fdt = lib/fdt.c; common = loader/linux.c; common = lib/cmdline.c;
grub-core/loader/arm64/linux.c +6 -0
@@ -26,6 +26,7 @@#include <grub/mm.h> #include <grub/types.h> #include <grub/cpu/linux.h> +#include <grub/cpu/multiboot.h> #include <grub/efi/efi.h> #include <grub/efi/pe32.h> #include <grub/i18n.h>
@@ -470,6 +471,9 @@ GRUB_MOD_INIT (linux) cmd_devicetree =grub_register_command ("devicetree" , grub_cmd_devicetree,0 ,N_ ("Load DTB file." )); + +grub_arm64_linux_register_multiboot_command (mod); + my_mod = mod; }
@@ -478,4 +482,6 @@ GRUB_MOD_FINI (linux)grub_unregister_command (cmd_linux);grub_unregister_command (cmd_initrd);grub_unregister_command (cmd_devicetree); + +grub_arm64_linux_unregister_multiboot_command (); }
grub-core/loader/arm64/multiboot.c new file +593 -0
593 lines not on this page · raw message
include/grub/arm64/multiboot.h new file +115 -0
115 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 15 lines · Fu Wei
grub-core/loader/arm64/multiboot.c
include/grub/arm64/multiboot.hAdd commands register code and hearder file into
grub-core/loader/arm64/linux.c- This multiboot support is built into linux module for aarch64.
- The implementation for Xen is following <Multiboot on ARM Specification>:
http://wiki.xen.org/wiki/Xen_ARM_with_Virtualization_Extensions/Multiboot
andxen/docs/misc/arm/device-tree/booting.txtin Xen source code.- This adds support for the Xen Multiboot on ARM specification for arm64, enabling config file portability across the architectures.
Quoted 6 lines
- The multiboot command is currently x86-only, so reusing these command names should not conflict with any future additions of ARM support to multiboot2.
- The reason of adding this functionality to the existing "linux" module rather than "multiboot(2)"
(1)multiboot is x86 only
multiboot2 isn't. But what you implement here is not multiboot. It's xen-specific protocol. So it should be called xen_hypervisor and xen_module. It's ok to add xen_hypervisor as an alias to multiboot on x86
Quoted 2 lines
(2)Multiboot is added to "linux" module because it reuses existing code.
Not a reason. You can move the code you reuse to separate module.
grub-core/Makefile.core.def module = { · line 1676
Quoted 9 lines
grub-core/Makefile.core.def +1
-0@@ -1673,6 +1673,7 @@ module = { ia64_efi = loader/ia64/efi/linux.c; arm = loader/arm/linux.c; arm64 = loader/arm64/linux.c; + arm64 = loader/arm64/multiboot.c;
Ditto
grub-core/Makefile.core.def module = { · line 1679
Quoted 3 lines
grub-core/Makefile.core.def +3
-0+ + grub_arm64_linux_register_multiboot_command (mod); +
Ditto
grub-core/Makefile.core.def GRUB_MOD_FINI (linux) · line 486
Quoted 9 lines
grub-core/Makefile.core.def +2
-0my_mod = mod; }@@ -478,4 +482,6 @@ GRUB_MOD_FINI (linux) grub_unregister_command (cmd_linux); grub_unregister_command (cmd_initrd); grub_unregister_command (cmd_devicetree); + + grub_arm64_linux_unregister_multiboot_command ();
Ditto
Quoted 29 lines
grub-core/Makefile.core.def +29
-0+static grub_dl_t linux_mod; +static int loaded; + +static struct multiboot_binary *multiboot_kernel = NULL; +static struct multiboot_binary *module_head = NULL; +static const grub_size_t module_default_align[] = { + MODULE_IMAGE_MIN_ALIGN, + MODULE_INITRD_MIN_ALIGN, + MODULE_OTHER_MIN_ALIGN, + MODULE_CUSTOM_MIN_ALIGN +}; + +static void *multiboot_fdt = NULL; +static const compat_string_struct_t default_compat_string[] = { + FDT_COMPATIBLE (MODULE_IMAGE_COMPATIBLE), + FDT_COMPATIBLE (MODULE_INITRD_COMPATIBLE), + FDT_COMPATIBLE (MODULE_OTHER_COMPATIBLE) +}; + +static grub_err_t +set_module_type (struct multiboot_binary *module, + int argc, char *argv[], int *file_name_index) +{ + static module_type_t default_type = MODULE_IMAGE; + char *temp = NULL; + grub_size_t total_size = 0; + int num_types = 0, i; + char **compat_string_temp_array = + (char **) grub_zalloc (sizeof (char *) * argc);
grub-core/Makefile.core.def GRUB_MOD_FINI (linux)
Quoted 10 lines
grub-core/Makefile.core.def +10
-0+ + *file_name_index = 0; + + /* if there are some options we need to process. */ + if (argc >= 3) + { + while (argc > 1) + { + if (grub_strcmp (argv[0], "--type") == 0) + {
Can we have separate xen_* commands for different types? It's ok for them to call similar code paths under the hood
Quoted 5 lines
grub-core/Makefile.core.def +5
-0+ module->node_info.type = MODULE_CUSTOM; + ARG_SHIFT(argc, argv); + total_size += grub_strlen (argv[0]) + 1; + compat_string_temp_array[num_types++] = argv[0]; + ARG_SHIFT(argc, argv);
grub-core/Makefile.core.def
Quoted 10 lines
grub-core/Makefile.core.def +10
-0+ (*file_name_index) += 2; + } + else + /* we can add more options process code here. */ + break; + } + } + + /* For the default module type : + * The implementation is following <Multiboot on ARM Specification>:
Could this thing be renamed to "xen ARM boot protocol"?
Quoted 25 lines
grub-core/Makefile.core.def +25
-0+ if (module->node_info.type != MODULE_CUSTOM) + { + /* the module type is set by the load order */ + module->node_info.type = default_type; + switch (default_type) + { + case MODULE_IMAGE: + default_type = MODULE_INITRD; + break; + + case MODULE_INITRD: + default_type = MODULE_OTHER; + break; + + case MODULE_OTHER: + break; + + default: + default_type = MODULE_IMAGE; /* error, reset the type */ + return (grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid argument"))); + } + } + else + { + /* the module type is set by "--type"(MODULE_CUSTOM) */
grub-core/Makefile.core.def
Quoted 10 lines
grub-core/Makefile.core.def +10
-0+ module->node_info.compat_string = temp = + (char *) grub_zalloc (total_size); + module->node_info.compat_string_size = total_size; + for (i = 0; num_types > 0; num_types--, i++, temp++) + { + grub_strcpy (temp, compat_string_temp_array[i]); + temp += grub_strlen (compat_string_temp_array[i]); + } + } +
Unnecessarry complexity just to have less commands. We've been down this path with grub1, it's not good.
Quoted 40 lines
grub-core/Makefile.core.def +40
-0+ grub_free (compat_string_temp_array); + return (GRUB_ERR_NONE); +} + +static grub_err_t +prepare_kernel_params (void) +{ + int retval; + int chosen_node = 0; + + multiboot_fdt = grub_linux_get_fdt (); + if (!multiboot_fdt) + return (grub_error (GRUB_ERR_BAD_OS, "failed to install/update FDT")); + + chosen_node = grub_fdt_find_subnode (multiboot_fdt, 0, "chosen"); + if (chosen_node < 0) + chosen_node = grub_fdt_add_subnode (multiboot_fdt, 0, "chosen"); + if (chosen_node < 1) + return (grub_error (GRUB_ERR_BAD_OS, "failed to install/update FDT")); + + grub_dprintf ("multiboot_loader", + "Multiboot Kernel cmdline : %s @ %p size:%d\n", + multiboot_kernel->cmdline, multiboot_kernel->cmdline, + multiboot_kernel->cmdline_size); + + retval = grub_fdt_set_prop (multiboot_fdt, chosen_node, "bootargs", + multiboot_kernel->cmdline, + multiboot_kernel->cmdline_size); + if (retval) + return grub_error (GRUB_ERR_BAD_OS, "failed to install/update FDT"); + + return (GRUB_ERR_NONE); +} + +static grub_err_t +prepare_module_params (struct multiboot_binary *module) +{ + int retval, chosen_node = 0, module_node = 0; + char module_name[FDT_NODE_NAME_MAX_SIZE]; +
grub-core/Makefile.core.def
Quoted 10 lines
grub-core/Makefile.core.def +10
-0+ retval = grub_snprintf (module_name, FDT_NODE_NAME_MAX_SIZE, + "module@%lx", + multiboot_address_align (module->start, + module->align)); + grub_dprintf ("multiboot_loader", "Module node name %s \n", module_name); + + if (retval < (int) sizeof ("module@")) + return (grub_error (GRUB_ERR_BAD_OS, + N_("failed to install/update FDT"))); +
What kind of errors do you expect here? I don't see grub_snprintf erroring here at all under any circumstances.
Please make errors more descriptive. You have same error message for at least 5 different problems.
Is this error likely to happen to a normal user? If not, let's not load translators with obscure technical strings. If it is likely it must way more clearer and have TRANSLATORS comment on context.
grub-core/Makefile.core.def
Quoted 12 lines
grub-core/Makefile.core.def +12
-0+ chosen_node = grub_fdt_find_subnode (multiboot_fdt, 0, "chosen"); + if (chosen_node < 0) + chosen_node = grub_fdt_add_subnode (multiboot_fdt, 0, "chosen"); + if (chosen_node < 1) + return (grub_error (GRUB_ERR_BAD_OS, "failed to install/update FDT")); + + module_node = + grub_fdt_find_subnode (multiboot_fdt, chosen_node, module_name); + if (module_node < 0) + module_node = + grub_fdt_add_subnode (multiboot_fdt, chosen_node, module_name); +
Could you please encapsulate find/add/setprop to a separate function?
grub-core/Makefile.core.def
Quoted 7 lines
grub-core/Makefile.core.def +7
-0+ retval = grub_fdt_set_prop (multiboot_fdt, module_node, "compatible", + module->node_info.compat_string, + (grub_uint32_t) module->node_info.compat_string_size); + if (retval) + return (grub_error (GRUB_ERR_BAD_OS, + N_("failed to install/update FDT"))); +
Style here and in many other places: no parens for return.
Quoted 16 lines
grub-core/Makefile.core.def +16
-0+static grub_err_t +multiboot_binary_load (struct multiboot_binary *binary, grub_file_t file, + int argc, char *argv[]) +{ + binary->size = grub_file_size (file); + grub_dprintf ("multiboot_loader", "Multiboot %s file size: 0x%lx\n", + binary->name, binary->size); + + binary->start = (grub_addr_t) grub_efi_allocate_pages (0, + (BYTES_TO_PAGES + (binary->size + + binary->align))); + if (!binary->start) + return (grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"))); + + grub_dprintf ("multiboot_loader", "Multiboot %s numpages: 0x%lx\n",
grub-core/Makefile.core.def
Quoted 10 lines
grub-core/Makefile.core.def +10
-0+ binary->name, BYTES_TO_PAGES (binary->size + binary->align)); + + if (grub_file_read (file, + (void *) multiboot_address_align (binary->start, + binary->align), + binary->size) < (grub_ssize_t) binary->size) + { + single_binary_unload (binary); + return (grub_error (GRUB_ERR_BAD_OS, + N_("premature end of file %s"), argv[0]));
Please don't override grub_errno if it's already set. See other loader for example.
include/grub/arm64/multiboot.h
Quoted 2 lines
include/grub/arm64/multiboot.h new file +0
-0
Again, please don't call it multiboot