From: Simon Glass Date: Sat, 5 Sep 2020 20:50:38 +0000 (-0600) Subject: x86: zimage: Use a state struct to hold the state X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=e81483748835df1f45be73a84eb13ce9592f8300;p=u-boot.git x86: zimage: Use a state struct to hold the state At present the 'zboot' command does everything in one go. It would be better if it supported sub-commands like bootm, so it is possible to examine what will be booted before actually booting it. In preparation for this, move the 'state' of the command into a struct. This will allow it to be shared among multiple functions in this file. Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner Reviewed-by: Bin Meng --- diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c index d2b6002008..a79971f052 100644 --- a/arch/x86/lib/zimage.c +++ b/arch/x86/lib/zimage.c @@ -45,6 +45,24 @@ #define COMMAND_LINE_SIZE 2048 +/** + * struct zboot_state - Current state of the boot + * + * @bzimage_addr: Address of the bzImage to boot + * @bzimage_size: Size of the bzImage, or 0 to detect this + * @initrd_addr: Address of the initial ramdisk, or 0 if none + * @initrd_size: Size of the initial ramdisk, or 0 if none + * @load_address: Address where the bzImage is moved before booting, either + * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR + */ +struct zboot_state { + ulong bzimage_addr; + ulong bzimage_size; + ulong initrd_addr; + ulong initrd_size; + ulong load_address; +} state; + static void build_command_line(char *command_line, int auto_boot) { char *env_command_line; @@ -307,15 +325,10 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct boot_params *base_ptr; - void *bzImage_addr = NULL; - ulong load_address; char *s; - ulong bzImage_size = 0; - ulong initrd_addr = 0; - ulong initrd_size = 0; disable_interrupts(); - + memset(&state, '\0', sizeof(state)); if (argc >= 2) { /* argv[1] holds the address of the bzImage */ s = argv[1]; @@ -324,33 +337,34 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } if (s) - bzImage_addr = (void *)simple_strtoul(s, NULL, 16); + state.bzimage_addr = simple_strtoul(s, NULL, 16); if (argc >= 3) { /* argv[2] holds the size of the bzImage */ - bzImage_size = simple_strtoul(argv[2], NULL, 16); + state.bzimage_size = simple_strtoul(argv[2], NULL, 16); } if (argc >= 4) - initrd_addr = simple_strtoul(argv[3], NULL, 16); + state.initrd_addr = simple_strtoul(argv[3], NULL, 16); if (argc >= 5) - initrd_size = simple_strtoul(argv[4], NULL, 16); + state.initrd_size = simple_strtoul(argv[4], NULL, 16); /* Lets look for */ - base_ptr = load_zimage(bzImage_addr, bzImage_size, &load_address); - + base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size, + &state.load_address); if (!base_ptr) { puts("## Kernel loading failed ...\n"); return -1; } - if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, - 0, initrd_addr, initrd_size)) { + + if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0, + state.initrd_addr, state.initrd_size)) { puts("Setting up boot parameters failed ...\n"); return -1; } /* we assume that the kernel is in place */ - return boot_linux_kernel((ulong)base_ptr, load_address, false); + return boot_linux_kernel((ulong)base_ptr, state.load_address, false); } U_BOOT_CMD(