
From: Simon Glass <sjg@chromium.org> Some environment variables affect the operation of bootm. Reading these variables is buried within the boot code at present. Ideally this information should be in struct bootm_info so that it can be provided directly, without needing the environment variables. Also it should support allocation if the variables are not provided. As a first step towards this, add an explicit read of the variables, storing the values. For now this only covers kernel_comp_addr_r and kernel_comp_size Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootm.c | 17 ++++++++++++----- cmd/booti.c | 1 + cmd/bootm.c | 1 + include/bootm.h | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index 9626fff13b0..8c51f71ed76 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -310,7 +310,7 @@ static int bootm_pre_load(const char *addr_str) return ret; } -static int found_booti_os(enum image_comp_t comp) +static int found_booti_os(struct bootm_info *bmi, enum image_comp_t comp) { images.os.load = images.os.image_start; images.os.type = IH_TYPE_KERNEL; @@ -325,8 +325,8 @@ static int found_booti_os(enum image_comp_t comp) images.os.load, images.os.image_start, images.os.image_len, images.ep, images.os.os, images.os.comp); if (comp != IH_COMP_NONE) { - images.os.load = env_get_hex("kernel_comp_addr_r", 0); - images.os.image_len = env_get_ulong("kernel_comp_size", 16, 0); + images.os.load = bmi->kern_comp_addr; + images.os.image_len = bmi->kern_comp_size; if (!images.os.load || !images.os.image_len) { puts("kernel_comp_addr_r or kernel_comp_size is not provided!\n"); return -ENOTSUPP; @@ -453,7 +453,7 @@ static int bootm_find_os(struct bootm_info *bmi) case IMAGE_FORMAT_BOOTI: log_debug("booti"); if (IS_ENABLED(CONFIG_CMD_BOOTI)) { - if (found_booti_os(IH_COMP_NONE)) + if (found_booti_os(bmi, IH_COMP_NONE)) return 1; ep_found = true; break; @@ -468,7 +468,7 @@ static int bootm_find_os(struct bootm_info *bmi) log_debug("booti decomp: %s\n", genimg_get_comp_name(comp)); if (comp != IH_COMP_NONE) { - if (found_booti_os(comp)) + if (found_booti_os(bmi, comp)) return 1; ep_found = true; } @@ -1315,6 +1315,12 @@ int booti_run(struct bootm_info *bmi) BOOTM_STATE_LOADOS); } +void bootm_read_env(struct bootm_info *bmi) +{ + bmi->kern_comp_addr = env_get_hex("kernel_comp_addr_r", 0); + bmi->kern_comp_size = env_get_ulong("kernel_comp_size", 16, 0); +} + int bootm_boot_start(ulong addr, const char *cmdline) { char addr_str[BOOTM_STRLEN]; @@ -1340,6 +1346,7 @@ int bootm_boot_start(ulong addr, const char *cmdline) return ret; } bootm_init(&bmi); + bootm_read_env(&bmi); bootm_set_addr_img(&bmi, addr, addr_str); bmi.cmd_name = "bootm"; ret = bootm_run_states(&bmi, states); diff --git a/cmd/booti.c b/cmd/booti.c index c1a61e4752d..bfbe530cb15 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -110,6 +110,7 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) argc--; argv++; bootm_init(&bmi); + bootm_read_env(&bmi); if (argc) bmi.addr_img = argv[0]; if (argc > 1) diff --git a/cmd/bootm.c b/cmd/bootm.c index 23b3d56c101..cb86f576a25 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -159,6 +159,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } bootm_init(&bmi); + bootm_read_env(&bmi); if (argc) bmi.addr_img = argv[0]; if (argc > 1) diff --git a/include/bootm.h b/include/bootm.h index 7420c657293..b24148c394d 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -58,6 +58,10 @@ enum bootm_final_t { * @argv: NULL-terminated list of arguments, or NULL if there are no arguments * @ignore_bootm_len: Ignore the value CONFIG_SYS_BOOTM_LEN and use 10x the * compressed length as the maximum uncompressed size + * @kern_comp_addr: Address to decompress the kernel to, if needed. If 0, space + * is reserved using lmb and this value is updated + * @kern_comp_size: Maximum size of the decompressed kernel. If 0, the size is + * calculated based on 4x the size of the kernel, up to a limit of 1G * * For zboot: * @bzimage_addr: Address of the bzImage to boot, or 0 if the image has already @@ -84,6 +88,8 @@ struct bootm_info { int argc; char *const *argv; bool ignore_bootm_len; + ulong kern_comp_addr; + ulong kern_comp_size; /* zboot items */ #ifdef CONFIG_X86 @@ -174,6 +180,16 @@ static inline ulong bootm_len(void) return 0; } +/** + * bootm_read_env() - Read environment variables used during the boot + * + * If bootm needs to decompress a kernel, it can use the 'kernel_comp_addr_r' + * and 'kernel_comp_size' variables to specify a region to decompress into. + * Call this function after bootm_init() to set up these variables. Otherwise, + * space will be reserved using lmb + */ +void bootm_read_env(struct bootm_info *bmi); + /** * bootm_init() - Set up a bootm_info struct with useful defaults * -- 2.43.0