From d2cb0c8f759ddc9cbc063816454d5f0d18d7fcb1 Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Wed, 18 Nov 2020 17:45:56 +0100 Subject: spl: atf: provide a bl2_plat_get_bl31_params_default() Move the actual implementation of the bl2_plat_get_bl31_params() to its own function. The weak function will just call the default implementation. This has the advantage that board code can still call the original implementation if it just want to modify minor things. Signed-off-by: Michael Walle --- include/spl.h | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/spl.h b/include/spl.h index b72dfc7e3d..fd928377f0 100644 --- a/include/spl.h +++ b/include/spl.h @@ -526,25 +526,44 @@ int spl_ymodem_load_image(struct spl_image_info *spl_image, void spl_invoke_atf(struct spl_image_info *spl_image); /** - * bl2_plat_get_bl31_params() - prepare params for bl31. - * @bl32_entry address of BL32 executable (secure) - * @bl33_entry address of BL33 executable (non secure) - * @fdt_addr address of Flat Device Tree + * bl2_plat_get_bl31_params() - return params for bl31. + * @bl32_entry: address of BL32 executable (secure) + * @bl33_entry: address of BL33 executable (non secure) + * @fdt_addr: address of Flat Device Tree * - * This function assigns a pointer to the memory that the platform has kept - * aside to pass platform specific and trusted firmware related information - * to BL31. This memory is allocated by allocating memory to - * bl2_to_bl31_params_mem structure which is a superset of all the - * structure whose information is passed to BL31 - * NOTE: This function should be called only once and should be done - * before generating params to BL31 + * This is a weak function which might be overridden by the board code. By + * default it will just call bl2_plat_get_bl31_params_default(). * - * @return bl31 params structure pointer + * If you just want to manipulate or add some parameters, you can override + * this function, call bl2_plat_get_bl31_params_default and operate on the + * returned bl31 params. + * + * Return: bl31 params structure pointer */ struct bl31_params *bl2_plat_get_bl31_params(uintptr_t bl32_entry, uintptr_t bl33_entry, uintptr_t fdt_addr); +/** + * bl2_plat_get_bl31_params_default() - prepare params for bl31. + * @bl32_entry: address of BL32 executable (secure) + * @bl33_entry: address of BL33 executable (non secure) + * @fdt_addr: address of Flat Device Tree + * + * This is the default implementation of bl2_plat_get_bl31_params(). It assigns + * a pointer to the memory that the platform has kept aside to pass platform + * specific and trusted firmware related information to BL31. This memory is + * allocated by allocating memory to bl2_to_bl31_params_mem structure which is + * a superset of all the structure whose information is passed to BL31 + * + * NOTE: The memory is statically allocated, thus this function should be + * called only once. All subsequent calls will overwrite any changes. + * + * Return: bl31 params structure pointer + */ +struct bl31_params *bl2_plat_get_bl31_params_default(uintptr_t bl32_entry, + uintptr_t bl33_entry, + uintptr_t fdt_addr); /** * spl_optee_entry - entry function for optee * -- cgit From 553825c1090c9f6968e81a0d40d0a3f42202fc6b Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Wed, 18 Nov 2020 17:45:57 +0100 Subject: spl: atf: remove helper structure from common header bl2_to_bl31_params_mem is just an implementation detail of the SPL ATF support and is not needed anywhere else. Move it from the header to the actual module. Signed-off-by: Michael Walle Acked-by: Michal Simek --- include/atf_common.h | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'include') diff --git a/include/atf_common.h b/include/atf_common.h index fd5454c55b..e173a10ca9 100644 --- a/include/atf_common.h +++ b/include/atf_common.h @@ -162,20 +162,6 @@ struct bl31_params { struct atf_image_info *bl33_image_info; }; -/******************************************************************************* - * This structure represents the superset of information that is passed to - * BL31, e.g. while passing control to it from BL2, bl31_params - * and other platform specific params - ******************************************************************************/ -struct bl2_to_bl31_params_mem { - struct bl31_params bl31_params; - struct atf_image_info bl31_image_info; - struct atf_image_info bl32_image_info; - struct atf_image_info bl33_image_info; - struct entry_point_info bl33_ep_info; - struct entry_point_info bl32_ep_info; - struct entry_point_info bl31_ep_info; -}; #endif /*__ASSEMBLY__ */ -- cgit From 7b866825cd354a358eff8f62207701771e0511bd Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Wed, 18 Nov 2020 17:45:58 +0100 Subject: spl: atf: add support for LOAD_IMAGE_V2 Newer platforms use the LOAD_IMAGE_V2 parameter passing method. Add support for it. Signed-off-by: Michael Walle --- include/atf_common.h | 30 ++++++++++++++++++++++++++++++ include/spl.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) (limited to 'include') diff --git a/include/atf_common.h b/include/atf_common.h index e173a10ca9..d69892fac6 100644 --- a/include/atf_common.h +++ b/include/atf_common.h @@ -14,8 +14,14 @@ #define ATF_PARAM_EP 0x01 #define ATF_PARAM_IMAGE_BINARY 0x02 #define ATF_PARAM_BL31 0x03 +#define ATF_PARAM_BL_PARAMS 0x05 #define ATF_VERSION_1 0x01 +#define ATF_VERSION_2 0x02 + +#define ATF_BL31_IMAGE_ID 0x03 +#define ATF_BL32_IMAGE_ID 0x04 +#define ATF_BL33_IMAGE_ID 0x05 #define ATF_EP_SECURE 0x0 #define ATF_EP_NON_SECURE 0x1 @@ -121,6 +127,9 @@ struct atf_image_info { struct param_header h; uintptr_t image_base; /* physical address of base of image */ uint32_t image_size; /* bytes read from image file */ +#if CONFIG_IS_ENABLED(ATF_LOAD_IMAGE_V2) + uint32_t image_max_size; +#endif }; /***************************************************************************** @@ -162,6 +171,27 @@ struct bl31_params { struct atf_image_info *bl33_image_info; }; +/* BL image node in the BL image execution sequence */ +struct bl_params_node { + unsigned int image_id; + struct atf_image_info *image_info; + struct entry_point_info *ep_info; + struct bl_params_node *next_params_info; +}; + +/* + * BL image head node in the BL image execution sequence + * It is also used to pass information to next BL image. + */ +struct bl_params { + struct param_header h; + struct bl_params_node *head; +}; + +#define for_each_bl_params_node(bl_params, node) \ + for ((node) = (bl_params)->head; \ + (node); \ + (node) = (node)->next_params_info) #endif /*__ASSEMBLY__ */ diff --git a/include/spl.h b/include/spl.h index fd928377f0..374a295fa3 100644 --- a/include/spl.h +++ b/include/spl.h @@ -564,6 +564,41 @@ struct bl31_params *bl2_plat_get_bl31_params(uintptr_t bl32_entry, struct bl31_params *bl2_plat_get_bl31_params_default(uintptr_t bl32_entry, uintptr_t bl33_entry, uintptr_t fdt_addr); + +/** + * bl2_plat_get_bl31_params_v2() - return params for bl31 + * @bl32_entry: address of BL32 executable (secure) + * @bl33_entry: address of BL33 executable (non secure) + * @fdt_addr: address of Flat Device Tree + * + * This function does the same as bl2_plat_get_bl31_params() except that is is + * used for the new LOAD_IMAGE_V2 option, which uses a slightly different + * method to pass the parameters. + * + * Return: bl31 params structure pointer + */ +struct bl_params *bl2_plat_get_bl31_params_v2(uintptr_t bl32_entry, + uintptr_t bl33_entry, + uintptr_t fdt_addr); + +/** + * bl2_plat_get_bl31_params_v2_default() - prepare params for bl31. + * @bl32_entry: address of BL32 executable (secure) + * @bl33_entry: address of BL33 executable (non secure) + * @fdt_addr: address of Flat Device Tree + * + * This is the default implementation of bl2_plat_get_bl31_params_v2(). It + * prepares the linked list of the bl31 params, populates the image types and + * set the entry points for bl32 and bl33 (if available). + * + * NOTE: The memory is statically allocated, thus this function should be + * called only once. All subsequent calls will overwrite any changes. + * + * Return: bl31 params structure pointer + */ +struct bl_params *bl2_plat_get_bl31_params_v2_default(uintptr_t bl32_entry, + uintptr_t bl33_entry, + uintptr_t fdt_addr); /** * spl_optee_entry - entry function for optee * -- cgit From 96434a76fd254248ded19e95dc967d28e65a5edf Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:37 -0700 Subject: env: Allow returning errors from hdelete_r() At present this function returns 1 on success and 0 on failure. But in the latter case it provides no indication of what went wrong. If an attempt is made to delete a non-existent variable, the caller may want to ignore this error. This happens when setting a non-existent variable to "", for example. Update the function to return 0 on success and a useful error code on failure. Add a function comment too. Make sure that env_set() does not return an error if it is deleting a variable that doesn't exist. We could update env_set() to return useful error numbers also, but that is beyond the scope of this change. Signed-off-by: Simon Glass wip --- include/search.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/search.h b/include/search.h index e56843c26f..d0bb44388e 100644 --- a/include/search.h +++ b/include/search.h @@ -80,7 +80,16 @@ int hsearch_r(struct env_entry item, enum env_action action, int hmatch_r(const char *match, int last_idx, struct env_entry **retval, struct hsearch_data *htab); -/* Search and delete entry matching "key" in internal hash table. */ +/** + * hdelete_r() - Search and delete entry in internal hash table + * + * @key: Name of entry to delete + * @htab: Hash table + * @flag: Flags to use (H_...) + * @return 0 on success, -ENOENT if not found, -EPERM if the hash table callback + * rejected changing the variable, -EINVAL if the hash table refused to + * delete the variable + */ int hdelete_r(const char *key, struct hsearch_data *htab, int flag); ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag, -- cgit From f158ba15ee0f9f756193b60420adfdc0a9c1eb96 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:38 -0700 Subject: bootm: Add tests for fixup_silent_linux() This function currently has no tests. Export it so that we can implement a simple test on sandbox. Use IS_ENABLED() to remove the unused code, instead #ifdef. Signed-off-by: Simon Glass --- include/bootm.h | 3 +++ include/test/suites.h | 1 + 2 files changed, 4 insertions(+) (limited to 'include') diff --git a/include/bootm.h b/include/bootm.h index a812a6bf24..6d675e6455 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -85,4 +85,7 @@ void arch_preboot_os(void); */ void board_preboot_os(void); +/* Adjust the 'bootargs' to ensure that Linux boots silently, if required */ +void fixup_silent_linux(void); + #endif diff --git a/include/test/suites.h b/include/test/suites.h index 5c97846e7f..52e8fc8155 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -26,6 +26,7 @@ int cmd_ut_category(const char *name, const char *prefix, struct unit_test *tests, int n_ents, int argc, char *const argv[]); +int do_ut_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_bloblist(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc, -- cgit From 4ae42643d0d71dbb5af45d19fa05b7a6807150c0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:39 -0700 Subject: bootm: Update fixup_silent_linux() to return an error At present this function fails silently on error. Update it to produce an error code. Report this error to the user and abort the boot, since it likely will prevent a successful start. No tests are added at this stage, since additional refactoring is taking place in subsequent patches. Signed-off-by: Simon Glass --- include/bootm.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/bootm.h b/include/bootm.h index 6d675e6455..438829af0f 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -85,7 +85,14 @@ void arch_preboot_os(void); */ void board_preboot_os(void); -/* Adjust the 'bootargs' to ensure that Linux boots silently, if required */ -void fixup_silent_linux(void); +/* + * fixup_silent_linux() - Process fix-ups for the command line + * + * Updates the 'bootargs' envvar as required. This handles making Linux boot + * silently if requested ('silent_linux' envvar) + * + * @return 0 if OK, -ENOMEM if out of memory + */ +int fixup_silent_linux(void); #endif -- cgit From 4dcb81545ab09b6cb4ee1f3c870fb3131984cf6f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:40 -0700 Subject: bootm: Rename fixup_silent_linux() We want to add more processing to this function. Before doing so, rename it to bootm_process_cmdline_env(), which is more generic. Signed-off-by: Simon Glass --- include/bootm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/bootm.h b/include/bootm.h index 438829af0f..35c27ab960 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -86,13 +86,13 @@ void arch_preboot_os(void); void board_preboot_os(void); /* - * fixup_silent_linux() - Process fix-ups for the command line + * bootm_process_cmdline_env() - Process fix-ups for the command line * * Updates the 'bootargs' envvar as required. This handles making Linux boot * silently if requested ('silent_linux' envvar) * * @return 0 if OK, -ENOMEM if out of memory */ -int fixup_silent_linux(void); +int bootm_process_cmdline_env(void); #endif -- cgit From d9477a0a4d4c4561941007a8b3db588385aaad07 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:41 -0700 Subject: bootm: Add a bool parameter to bootm_process_cmdline_env() This function will soon do more than just handle the 'silent linux' feature. As a first step, update it to take a boolean parameter, indicating whether or not the processing is required. Signed-off-by: Simon Glass --- include/bootm.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/bootm.h b/include/bootm.h index 35c27ab960..f12ee2b3cb 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -91,8 +91,9 @@ void board_preboot_os(void); * Updates the 'bootargs' envvar as required. This handles making Linux boot * silently if requested ('silent_linux' envvar) * + * @do_silent: Process bootargs for silent console * @return 0 if OK, -ENOMEM if out of memory */ -int bootm_process_cmdline_env(void); +int bootm_process_cmdline_env(bool do_silent); #endif -- cgit From b3c01678fdb15c63b231743481b9b77c7c4f8549 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:44 -0700 Subject: bootm: Update bootm_process_cmdline_env() to use flags At present only one transformation is supported: making the Linux console silent. To prepare for adding more, convert the boolean parameter into a flag value. Signed-off-by: Simon Glass --- include/bootm.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/bootm.h b/include/bootm.h index f12ee2b3cb..4876d7b288 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -75,6 +75,13 @@ void board_quiesce_devices(void); */ void switch_to_non_secure_mode(void); +/* Flags to control bootm_process_cmdline() */ +enum bootm_cmdline_t { + BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */ + + BOOTM_CL_ALL = 1, /* All substitutions */ +}; + /** * arch_preboot_os() - arch specific configuration before booting */ @@ -91,9 +98,9 @@ void board_preboot_os(void); * Updates the 'bootargs' envvar as required. This handles making Linux boot * silently if requested ('silent_linux' envvar) * - * @do_silent: Process bootargs for silent console + * @flags: Flags to control what happens (see bootm_cmdline_t) * @return 0 if OK, -ENOMEM if out of memory */ -int bootm_process_cmdline_env(bool do_silent); +int bootm_process_cmdline_env(int flags); #endif -- cgit From 4448fe8e4e7cc4dc5336a2d27fa6048057eaf1a6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:45 -0700 Subject: bootm: Allow updating the bootargs in a buffer At present we only support updating the 'bootargs' environment variable. Add another function to update a buffer instead. This will allow zimage to use this feature. Also add a lot more tests to cover various cases. Signed-off-by: Simon Glass --- include/bootm.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include') diff --git a/include/bootm.h b/include/bootm.h index 4876d7b288..8d95fb2a90 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -93,6 +93,22 @@ void arch_preboot_os(void); void board_preboot_os(void); /* + * bootm_process_cmdline() - Process fix-ups for the command line + * + * This handles: making Linux boot silently if requested ('silent_linux' envvar) + * + * @maxlen must provide enough space for the string being processed plus the + * resulting string + * + * @buf: buffer holding commandline string to adjust + * @maxlen: Maximum length of buffer at @buf (including \0) + * @flags: Flags to control what happens (see bootm_cmdline_t) + * @return 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too + * long + */ +int bootm_process_cmdline(char *buf, int maxlen, int flags); + +/** * bootm_process_cmdline_env() - Process fix-ups for the command line * * Updates the 'bootargs' envvar as required. This handles making Linux boot -- cgit From 1a62d64c7de7e7de3facf221eb8408ddfb675cb8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:47 -0700 Subject: cli: Support macro processing with a fixed-size buffer At present cli_simple_process_macros() requires that the caller provide an output buffer that is exactly CONFIG_SYS_CBSIZE bytes in length. This makes sense since it is designed to be used from the command line. But we also want to use it for bootargs substitution. Update the function to allow the caller to specify the buffer size. Also return an error if the buffer is exhausted. The caller can ignore that if preferred. Signed-off-by: Simon Glass --- include/cli.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/cli.h b/include/cli.h index 39b913743b..3449fa6ae7 100644 --- a/include/cli.h +++ b/include/cli.h @@ -34,8 +34,10 @@ int cli_simple_run_command(const char *cmd, int flag); * * @param input Input string possible containing $() / ${} vars * @param output Output string with $() / ${} vars expanded + * @param max_size Maximum size of @output (including terminator) + * @return 0 if OK, -ENOSPC if we ran out of space in @output */ -void cli_simple_process_macros(const char *input, char *output); +int cli_simple_process_macros(const char *input, char *output, int max_size); /** * cli_simple_run_command_list() - Execute a list of command -- cgit From 51bb33846ad2b045799d2c43ca773fafa36e6ec8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Nov 2020 10:33:48 -0700 Subject: bootm: Support string substitution in bootargs In some cases it is necessary to pass parameters to Linux so that it will boot correctly. For example, the rootdev parameter is often used to specify the root device. However the root device may change depending on whence U-Boot loads the kernel. At present it is necessary to build up the command line by adding device strings to it one by one. It is often more convenient to provide a template for bootargs, with U-Boot doing the substitution from other environment variables. Add a way to substitute strings in the bootargs variable. This allows things like "rootdev=${rootdev}" to be used in bootargs, with the ${rootdev} substitution providing the UUID of the root device. For example, to substitute the GUID of the kernel partition: setenv bootargs "console=/dev/ttyS0 rootdev=${uuid}/PARTNROFF=1 kern_guid=${uuid}" part uuid mmc 2:2 uuid bootm This is particularly useful when the command line from another place. For example, Chrome OS stores the command line next to the kernel itself. It depends on the kernel version being used as well as the hardware features, so it is extremely difficult to devise a U-Boot script that works on all boards and kernel versions. With this feature, the command line can be read from disk and used directly, with a few substitutions set up. Signed-off-by: Simon Glass --- include/bootm.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/bootm.h b/include/bootm.h index 8d95fb2a90..7f88ec718b 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -78,8 +78,9 @@ void switch_to_non_secure_mode(void); /* Flags to control bootm_process_cmdline() */ enum bootm_cmdline_t { BOOTM_CL_SILENT = 1 << 0, /* Do silent console processing */ + BOOTM_CL_SUBST = 1 << 1, /* Do substitution */ - BOOTM_CL_ALL = 1, /* All substitutions */ + BOOTM_CL_ALL = 3, /* All substitutions */ }; /** @@ -95,7 +96,10 @@ void board_preboot_os(void); /* * bootm_process_cmdline() - Process fix-ups for the command line * - * This handles: making Linux boot silently if requested ('silent_linux' envvar) + * This handles: + * + * - making Linux boot silently if requested ('silent_linux' envvar) + * - performing substitutions in the command line ('bootargs_subst' envvar) * * @maxlen must provide enough space for the string being processed plus the * resulting string @@ -111,8 +115,10 @@ int bootm_process_cmdline(char *buf, int maxlen, int flags); /** * bootm_process_cmdline_env() - Process fix-ups for the command line * - * Updates the 'bootargs' envvar as required. This handles making Linux boot - * silently if requested ('silent_linux' envvar) + * Updates the 'bootargs' envvar as required. This handles: + * + * - making Linux boot silently if requested ('silent_linux' envvar) + * - performing substitutions in the command line ('bootargs_subst' envvar) * * @flags: Flags to control what happens (see bootm_cmdline_t) * @return 0 if OK, -ENOMEM if out of memory -- cgit