zimage.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors.
  4. * (C) Copyright 2002
  5. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  6. */
  7. /*
  8. * Linux x86 zImage and bzImage loading
  9. *
  10. * based on the procdure described in
  11. * linux/Documentation/i386/boot.txt
  12. */
  13. #define LOG_CATEGORY LOGC_BOOT
  14. #include <common.h>
  15. #include <bootm.h>
  16. #include <command.h>
  17. #include <env.h>
  18. #include <init.h>
  19. #include <irq_func.h>
  20. #include <log.h>
  21. #include <malloc.h>
  22. #include <acpi/acpi_table.h>
  23. #include <asm/io.h>
  24. #include <asm/ptrace.h>
  25. #include <asm/zimage.h>
  26. #include <asm/byteorder.h>
  27. #include <asm/bootm.h>
  28. #include <asm/bootparam.h>
  29. #include <asm/global_data.h>
  30. #ifdef CONFIG_SYS_COREBOOT
  31. #include <asm/arch/timestamp.h>
  32. #endif
  33. #include <linux/compiler.h>
  34. #include <linux/ctype.h>
  35. #include <linux/libfdt.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /*
  38. * Memory lay-out:
  39. *
  40. * relative to setup_base (which is 0x90000 currently)
  41. *
  42. * 0x0000-0x7FFF Real mode kernel
  43. * 0x8000-0x8FFF Stack and heap
  44. * 0x9000-0x90FF Kernel command line
  45. */
  46. #define DEFAULT_SETUP_BASE 0x90000
  47. #define COMMAND_LINE_OFFSET 0x9000
  48. #define HEAP_END_OFFSET 0x8e00
  49. #define COMMAND_LINE_SIZE 2048
  50. /**
  51. * struct zboot_state - Current state of the boot
  52. *
  53. * @bzimage_addr: Address of the bzImage to boot
  54. * @bzimage_size: Size of the bzImage, or 0 to detect this
  55. * @initrd_addr: Address of the initial ramdisk, or 0 if none
  56. * @initrd_size: Size of the initial ramdisk, or 0 if none
  57. * @load_address: Address where the bzImage is moved before booting, either
  58. * BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
  59. * @base_ptr: Pointer to the boot parameters, typically at address
  60. * DEFAULT_SETUP_BASE
  61. * @cmdline: Environment variable containing the 'override' command line, or
  62. * NULL to use the one in the setup block
  63. */
  64. struct zboot_state {
  65. ulong bzimage_addr;
  66. ulong bzimage_size;
  67. ulong initrd_addr;
  68. ulong initrd_size;
  69. ulong load_address;
  70. struct boot_params *base_ptr;
  71. char *cmdline;
  72. } state;
  73. enum {
  74. ZBOOT_STATE_START = BIT(0),
  75. ZBOOT_STATE_LOAD = BIT(1),
  76. ZBOOT_STATE_SETUP = BIT(2),
  77. ZBOOT_STATE_INFO = BIT(3),
  78. ZBOOT_STATE_GO = BIT(4),
  79. /* This one doesn't execute automatically, so stop the count before 5 */
  80. ZBOOT_STATE_DUMP = BIT(5),
  81. ZBOOT_STATE_COUNT = 5,
  82. };
  83. static void build_command_line(char *command_line, int auto_boot)
  84. {
  85. char *env_command_line;
  86. command_line[0] = '\0';
  87. env_command_line = env_get("bootargs");
  88. /* set console= argument if we use a serial console */
  89. if (!strstr(env_command_line, "console=")) {
  90. if (!strcmp(env_get("stdout"), "serial")) {
  91. /* We seem to use serial console */
  92. sprintf(command_line, "console=ttyS0,%s ",
  93. env_get("baudrate"));
  94. }
  95. }
  96. if (auto_boot)
  97. strcat(command_line, "auto ");
  98. if (env_command_line)
  99. strcat(command_line, env_command_line);
  100. #ifdef DEBUG
  101. printf("Kernel command line:");
  102. puts(command_line);
  103. printf("\n");
  104. #endif
  105. }
  106. static int kernel_magic_ok(struct setup_header *hdr)
  107. {
  108. if (KERNEL_MAGIC != hdr->boot_flag) {
  109. printf("Error: Invalid Boot Flag "
  110. "(found 0x%04x, expected 0x%04x)\n",
  111. hdr->boot_flag, KERNEL_MAGIC);
  112. return 0;
  113. } else {
  114. printf("Valid Boot Flag\n");
  115. return 1;
  116. }
  117. }
  118. static int get_boot_protocol(struct setup_header *hdr, bool verbose)
  119. {
  120. if (hdr->header == KERNEL_V2_MAGIC) {
  121. if (verbose)
  122. printf("Magic signature found\n");
  123. return hdr->version;
  124. } else {
  125. /* Very old kernel */
  126. if (verbose)
  127. printf("Magic signature not found\n");
  128. return 0x0100;
  129. }
  130. }
  131. static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob)
  132. {
  133. int bootproto = get_boot_protocol(hdr, false);
  134. struct setup_data *sd;
  135. int size;
  136. if (bootproto < 0x0209)
  137. return -ENOTSUPP;
  138. if (!fdt_blob)
  139. return 0;
  140. size = fdt_totalsize(fdt_blob);
  141. if (size < 0)
  142. return -EINVAL;
  143. size += sizeof(struct setup_data);
  144. sd = (struct setup_data *)malloc(size);
  145. if (!sd) {
  146. printf("Not enough memory for DTB setup data\n");
  147. return -ENOMEM;
  148. }
  149. sd->next = hdr->setup_data;
  150. sd->type = SETUP_DTB;
  151. sd->len = fdt_totalsize(fdt_blob);
  152. memcpy(sd->data, fdt_blob, sd->len);
  153. hdr->setup_data = (unsigned long)sd;
  154. return 0;
  155. }
  156. static const char *get_kernel_version(struct boot_params *params,
  157. void *kernel_base)
  158. {
  159. struct setup_header *hdr = &params->hdr;
  160. int bootproto;
  161. const char *s, *end;
  162. bootproto = get_boot_protocol(hdr, false);
  163. if (bootproto < 0x0200 || hdr->setup_sects < 15)
  164. return NULL;
  165. /* sanity-check the kernel version in case it is missing */
  166. for (s = kernel_base + hdr->kernel_version + 0x200, end = s + 0x100; *s;
  167. s++) {
  168. if (!isprint(*s))
  169. return NULL;
  170. }
  171. return kernel_base + hdr->kernel_version + 0x200;
  172. }
  173. struct boot_params *load_zimage(char *image, unsigned long kernel_size,
  174. ulong *load_addressp)
  175. {
  176. struct boot_params *setup_base;
  177. const char *version;
  178. int setup_size;
  179. int bootproto;
  180. int big_image;
  181. struct boot_params *params = (struct boot_params *)image;
  182. struct setup_header *hdr = &params->hdr;
  183. /* base address for real-mode segment */
  184. setup_base = (struct boot_params *)DEFAULT_SETUP_BASE;
  185. if (!kernel_magic_ok(hdr))
  186. return 0;
  187. /* determine size of setup */
  188. if (0 == hdr->setup_sects) {
  189. log_warning("Setup Sectors = 0 (defaulting to 4)\n");
  190. setup_size = 5 * 512;
  191. } else {
  192. setup_size = (hdr->setup_sects + 1) * 512;
  193. }
  194. log_debug("Setup Size = 0x%8.8lx\n", (ulong)setup_size);
  195. if (setup_size > SETUP_MAX_SIZE)
  196. printf("Error: Setup is too large (%d bytes)\n", setup_size);
  197. /* determine boot protocol version */
  198. bootproto = get_boot_protocol(hdr, true);
  199. log_debug("Using boot protocol version %x.%02x\n",
  200. (bootproto & 0xff00) >> 8, bootproto & 0xff);
  201. version = get_kernel_version(params, image);
  202. if (version)
  203. printf("Linux kernel version %s\n", version);
  204. else
  205. printf("Setup Sectors < 15 - Cannot print kernel version\n");
  206. /* Determine image type */
  207. big_image = (bootproto >= 0x0200) &&
  208. (hdr->loadflags & BIG_KERNEL_FLAG);
  209. /* Determine load address */
  210. if (big_image)
  211. *load_addressp = BZIMAGE_LOAD_ADDR;
  212. else
  213. *load_addressp = ZIMAGE_LOAD_ADDR;
  214. printf("Building boot_params at 0x%8.8lx\n", (ulong)setup_base);
  215. memset(setup_base, 0, sizeof(*setup_base));
  216. setup_base->hdr = params->hdr;
  217. if (bootproto >= 0x0204)
  218. kernel_size = hdr->syssize * 16;
  219. else
  220. kernel_size -= setup_size;
  221. if (bootproto == 0x0100) {
  222. /*
  223. * A very old kernel MUST have its real-mode code
  224. * loaded at 0x90000
  225. */
  226. if ((ulong)setup_base != 0x90000) {
  227. /* Copy the real-mode kernel */
  228. memmove((void *)0x90000, setup_base, setup_size);
  229. /* Copy the command line */
  230. memmove((void *)0x99000,
  231. (u8 *)setup_base + COMMAND_LINE_OFFSET,
  232. COMMAND_LINE_SIZE);
  233. /* Relocated */
  234. setup_base = (struct boot_params *)0x90000;
  235. }
  236. /* It is recommended to clear memory up to the 32K mark */
  237. memset((u8 *)0x90000 + setup_size, 0,
  238. SETUP_MAX_SIZE - setup_size);
  239. }
  240. if (big_image) {
  241. if (kernel_size > BZIMAGE_MAX_SIZE) {
  242. printf("Error: bzImage kernel too big! "
  243. "(size: %ld, max: %d)\n",
  244. kernel_size, BZIMAGE_MAX_SIZE);
  245. return 0;
  246. }
  247. } else if ((kernel_size) > ZIMAGE_MAX_SIZE) {
  248. printf("Error: zImage kernel too big! (size: %ld, max: %d)\n",
  249. kernel_size, ZIMAGE_MAX_SIZE);
  250. return 0;
  251. }
  252. printf("Loading %s at address %lx (%ld bytes)\n",
  253. big_image ? "bzImage" : "zImage", *load_addressp, kernel_size);
  254. memmove((void *)*load_addressp, image + setup_size, kernel_size);
  255. return setup_base;
  256. }
  257. int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
  258. ulong initrd_addr, ulong initrd_size, ulong cmdline_force)
  259. {
  260. struct setup_header *hdr = &setup_base->hdr;
  261. int bootproto = get_boot_protocol(hdr, false);
  262. log_debug("Setup E820 entries\n");
  263. if (IS_ENABLED(CONFIG_COREBOOT_SYSINFO)) {
  264. setup_base->e820_entries = cb_install_e820_map(
  265. ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map);
  266. } else {
  267. setup_base->e820_entries = install_e820_map(
  268. ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map);
  269. }
  270. if (bootproto == 0x0100) {
  271. setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC;
  272. setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET;
  273. }
  274. if (bootproto >= 0x0200) {
  275. hdr->type_of_loader = 0x80; /* U-Boot version 0 */
  276. if (initrd_addr) {
  277. printf("Initial RAM disk at linear address "
  278. "0x%08lx, size %ld bytes\n",
  279. initrd_addr, initrd_size);
  280. hdr->ramdisk_image = initrd_addr;
  281. hdr->ramdisk_size = initrd_size;
  282. }
  283. }
  284. if (bootproto >= 0x0201) {
  285. hdr->heap_end_ptr = HEAP_END_OFFSET;
  286. hdr->loadflags |= HEAP_FLAG;
  287. }
  288. if (cmd_line) {
  289. int max_size = 0xff;
  290. int ret;
  291. log_debug("Setup cmdline\n");
  292. if (bootproto >= 0x0206)
  293. max_size = hdr->cmdline_size;
  294. if (bootproto >= 0x0202) {
  295. hdr->cmd_line_ptr = (uintptr_t)cmd_line;
  296. } else if (bootproto >= 0x0200) {
  297. setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC;
  298. setup_base->screen_info.cl_offset =
  299. (uintptr_t)cmd_line - (uintptr_t)setup_base;
  300. hdr->setup_move_size = 0x9100;
  301. }
  302. /* build command line at COMMAND_LINE_OFFSET */
  303. if (cmdline_force)
  304. strcpy(cmd_line, (char *)cmdline_force);
  305. else
  306. build_command_line(cmd_line, auto_boot);
  307. ret = bootm_process_cmdline(cmd_line, max_size, BOOTM_CL_ALL);
  308. if (ret) {
  309. printf("Cmdline setup failed (max_size=%x, bootproto=%x, err=%d)\n",
  310. max_size, bootproto, ret);
  311. return ret;
  312. }
  313. printf("Kernel command line: \"");
  314. puts(cmd_line);
  315. printf("\"\n");
  316. }
  317. if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207)
  318. hdr->hardware_subarch = X86_SUBARCH_INTEL_MID;
  319. if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE))
  320. setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr();
  321. log_debug("Setup devicetree\n");
  322. setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0));
  323. setup_video(&setup_base->screen_info);
  324. if (IS_ENABLED(CONFIG_EFI_STUB))
  325. setup_efi_info(&setup_base->efi_info);
  326. return 0;
  327. }
  328. static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
  329. char *const argv[])
  330. {
  331. const char *s;
  332. memset(&state, '\0', sizeof(state));
  333. if (argc >= 2) {
  334. /* argv[1] holds the address of the bzImage */
  335. s = argv[1];
  336. } else {
  337. s = env_get("fileaddr");
  338. }
  339. if (s)
  340. state.bzimage_addr = hextoul(s, NULL);
  341. if (argc >= 3) {
  342. /* argv[2] holds the size of the bzImage */
  343. state.bzimage_size = hextoul(argv[2], NULL);
  344. }
  345. if (argc >= 4)
  346. state.initrd_addr = hextoul(argv[3], NULL);
  347. if (argc >= 5)
  348. state.initrd_size = hextoul(argv[4], NULL);
  349. if (argc >= 6) {
  350. /*
  351. * When the base_ptr is passed in, we assume that the image is
  352. * already loaded at the address given by argv[1] and therefore
  353. * the original bzImage is somewhere else, or not accessible.
  354. * In any case, we don't need access to the bzImage since all
  355. * the processing is assumed to be done.
  356. *
  357. * So set the base_ptr to the given address, use this arg as the
  358. * load address and set bzimage_addr to 0 so we know that it
  359. * cannot be proceesed (or processed again).
  360. */
  361. state.base_ptr = (void *)hextoul(argv[5], NULL);
  362. state.load_address = state.bzimage_addr;
  363. state.bzimage_addr = 0;
  364. }
  365. if (argc >= 7)
  366. state.cmdline = env_get(argv[6]);
  367. return 0;
  368. }
  369. static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
  370. char *const argv[])
  371. {
  372. struct boot_params *base_ptr;
  373. if (state.base_ptr) {
  374. struct boot_params *from = (struct boot_params *)state.base_ptr;
  375. base_ptr = (struct boot_params *)DEFAULT_SETUP_BASE;
  376. log_debug("Building boot_params at 0x%8.8lx\n",
  377. (ulong)base_ptr);
  378. memset(base_ptr, '\0', sizeof(*base_ptr));
  379. base_ptr->hdr = from->hdr;
  380. } else {
  381. base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
  382. &state.load_address);
  383. if (!base_ptr) {
  384. puts("## Kernel loading failed ...\n");
  385. return CMD_RET_FAILURE;
  386. }
  387. }
  388. state.base_ptr = base_ptr;
  389. if (env_set_hex("zbootbase", (ulong)base_ptr) ||
  390. env_set_hex("zbootaddr", state.load_address))
  391. return CMD_RET_FAILURE;
  392. return 0;
  393. }
  394. static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
  395. char *const argv[])
  396. {
  397. struct boot_params *base_ptr = state.base_ptr;
  398. int ret;
  399. if (!base_ptr) {
  400. printf("base is not set: use 'zboot load' first\n");
  401. return CMD_RET_FAILURE;
  402. }
  403. ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
  404. 0, state.initrd_addr, state.initrd_size,
  405. (ulong)state.cmdline);
  406. if (ret) {
  407. puts("Setting up boot parameters failed ...\n");
  408. return CMD_RET_FAILURE;
  409. }
  410. return 0;
  411. }
  412. static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
  413. char *const argv[])
  414. {
  415. printf("Kernel loaded at %08lx, setup_base=%p\n",
  416. state.load_address, state.base_ptr);
  417. return 0;
  418. }
  419. static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
  420. char *const argv[])
  421. {
  422. int ret;
  423. disable_interrupts();
  424. /* we assume that the kernel is in place */
  425. ret = boot_linux_kernel((ulong)state.base_ptr, state.load_address,
  426. false);
  427. printf("Kernel returned! (err=%d)\n", ret);
  428. return CMD_RET_FAILURE;
  429. }
  430. static void print_num(const char *name, ulong value)
  431. {
  432. printf("%-20s: %lx\n", name, value);
  433. }
  434. static void print_num64(const char *name, u64 value)
  435. {
  436. printf("%-20s: %llx\n", name, value);
  437. }
  438. static const char *const e820_type_name[E820_COUNT] = {
  439. [E820_RAM] = "RAM",
  440. [E820_RESERVED] = "Reserved",
  441. [E820_ACPI] = "ACPI",
  442. [E820_NVS] = "ACPI NVS",
  443. [E820_UNUSABLE] = "Unusable",
  444. };
  445. static const char *const bootloader_id[] = {
  446. "LILO",
  447. "Loadlin",
  448. "bootsect-loader",
  449. "Syslinux",
  450. "Etherboot/gPXE/iPXE",
  451. "ELILO",
  452. "undefined",
  453. "GRUB",
  454. "U-Boot",
  455. "Xen",
  456. "Gujin",
  457. "Qemu",
  458. "Arcturus Networks uCbootloader",
  459. "kexec-tools",
  460. "Extended",
  461. "Special",
  462. "Reserved",
  463. "Minimal Linux Bootloader",
  464. "OVMF UEFI virtualization stack",
  465. };
  466. struct flag_info {
  467. uint bit;
  468. const char *name;
  469. };
  470. static struct flag_info load_flags[] = {
  471. { LOADED_HIGH, "loaded-high" },
  472. { QUIET_FLAG, "quiet" },
  473. { KEEP_SEGMENTS, "keep-segments" },
  474. { CAN_USE_HEAP, "can-use-heap" },
  475. };
  476. static struct flag_info xload_flags[] = {
  477. { XLF_KERNEL_64, "64-bit-entry" },
  478. { XLF_CAN_BE_LOADED_ABOVE_4G, "can-load-above-4gb" },
  479. { XLF_EFI_HANDOVER_32, "32-efi-handoff" },
  480. { XLF_EFI_HANDOVER_64, "64-efi-handoff" },
  481. { XLF_EFI_KEXEC, "kexec-efi-runtime" },
  482. };
  483. static void print_flags(struct flag_info *flags, int count, uint value)
  484. {
  485. int i;
  486. printf("%-20s:", "");
  487. for (i = 0; i < count; i++) {
  488. uint mask = flags[i].bit;
  489. if (value & mask)
  490. printf(" %s", flags[i].name);
  491. }
  492. printf("\n");
  493. }
  494. static void show_loader(struct setup_header *hdr)
  495. {
  496. bool version_valid = false;
  497. int type, version;
  498. const char *name;
  499. type = hdr->type_of_loader >> 4;
  500. version = hdr->type_of_loader & 0xf;
  501. if (type == 0xe)
  502. type = 0x10 + hdr->ext_loader_type;
  503. version |= hdr->ext_loader_ver << 4;
  504. if (!hdr->type_of_loader) {
  505. name = "pre-2.00 bootloader";
  506. } else if (hdr->type_of_loader == 0xff) {
  507. name = "unknown";
  508. } else if (type < ARRAY_SIZE(bootloader_id)) {
  509. name = bootloader_id[type];
  510. version_valid = true;
  511. } else {
  512. name = "undefined";
  513. }
  514. printf("%20s %s", "", name);
  515. if (version_valid)
  516. printf(", version %x", version);
  517. printf("\n");
  518. }
  519. void zimage_dump(struct boot_params *base_ptr)
  520. {
  521. struct setup_header *hdr;
  522. const char *version;
  523. int i;
  524. printf("Setup located at %p:\n\n", base_ptr);
  525. print_num64("ACPI RSDP addr", base_ptr->acpi_rsdp_addr);
  526. printf("E820: %d entries\n", base_ptr->e820_entries);
  527. if (base_ptr->e820_entries) {
  528. printf("%18s %16s %s\n", "Addr", "Size", "Type");
  529. for (i = 0; i < base_ptr->e820_entries; i++) {
  530. struct e820_entry *entry = &base_ptr->e820_map[i];
  531. printf("%12llx %10llx %s\n", entry->addr, entry->size,
  532. entry->type < E820_COUNT ?
  533. e820_type_name[entry->type] :
  534. simple_itoa(entry->type));
  535. }
  536. }
  537. hdr = &base_ptr->hdr;
  538. print_num("Setup sectors", hdr->setup_sects);
  539. print_num("Root flags", hdr->root_flags);
  540. print_num("Sys size", hdr->syssize);
  541. print_num("RAM size", hdr->ram_size);
  542. print_num("Video mode", hdr->vid_mode);
  543. print_num("Root dev", hdr->root_dev);
  544. print_num("Boot flag", hdr->boot_flag);
  545. print_num("Jump", hdr->jump);
  546. print_num("Header", hdr->header);
  547. if (hdr->header == KERNEL_V2_MAGIC)
  548. printf("%-20s %s\n", "", "Kernel V2");
  549. else
  550. printf("%-20s %s\n", "", "Ancient kernel, using version 100");
  551. print_num("Version", hdr->version);
  552. print_num("Real mode switch", hdr->realmode_swtch);
  553. print_num("Start sys", hdr->start_sys);
  554. print_num("Kernel version", hdr->kernel_version);
  555. version = get_kernel_version(base_ptr, (void *)state.bzimage_addr);
  556. if (version)
  557. printf(" @%p: %s\n", version, version);
  558. print_num("Type of loader", hdr->type_of_loader);
  559. show_loader(hdr);
  560. print_num("Load flags", hdr->loadflags);
  561. print_flags(load_flags, ARRAY_SIZE(load_flags), hdr->loadflags);
  562. print_num("Setup move size", hdr->setup_move_size);
  563. print_num("Code32 start", hdr->code32_start);
  564. print_num("Ramdisk image", hdr->ramdisk_image);
  565. print_num("Ramdisk size", hdr->ramdisk_size);
  566. print_num("Bootsect kludge", hdr->bootsect_kludge);
  567. print_num("Heap end ptr", hdr->heap_end_ptr);
  568. print_num("Ext loader ver", hdr->ext_loader_ver);
  569. print_num("Ext loader type", hdr->ext_loader_type);
  570. print_num("Command line ptr", hdr->cmd_line_ptr);
  571. if (hdr->cmd_line_ptr) {
  572. printf(" ");
  573. /* Use puts() to avoid limits from CONFIG_SYS_PBSIZE */
  574. puts((char *)(ulong)hdr->cmd_line_ptr);
  575. printf("\n");
  576. }
  577. print_num("Initrd addr max", hdr->initrd_addr_max);
  578. print_num("Kernel alignment", hdr->kernel_alignment);
  579. print_num("Relocatable kernel", hdr->relocatable_kernel);
  580. print_num("Min alignment", hdr->min_alignment);
  581. if (hdr->min_alignment)
  582. printf("%-20s: %x\n", "", 1 << hdr->min_alignment);
  583. print_num("Xload flags", hdr->xloadflags);
  584. print_flags(xload_flags, ARRAY_SIZE(xload_flags), hdr->xloadflags);
  585. print_num("Cmdline size", hdr->cmdline_size);
  586. print_num("Hardware subarch", hdr->hardware_subarch);
  587. print_num64("HW subarch data", hdr->hardware_subarch_data);
  588. print_num("Payload offset", hdr->payload_offset);
  589. print_num("Payload length", hdr->payload_length);
  590. print_num64("Setup data", hdr->setup_data);
  591. print_num64("Pref address", hdr->pref_address);
  592. print_num("Init size", hdr->init_size);
  593. print_num("Handover offset", hdr->handover_offset);
  594. if (get_boot_protocol(hdr, false) >= 0x215)
  595. print_num("Kernel info offset", hdr->kernel_info_offset);
  596. }
  597. static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc,
  598. char *const argv[])
  599. {
  600. struct boot_params *base_ptr = state.base_ptr;
  601. if (argc > 1)
  602. base_ptr = (void *)hextoul(argv[1], NULL);
  603. if (!base_ptr) {
  604. printf("No zboot setup_base\n");
  605. return CMD_RET_FAILURE;
  606. }
  607. zimage_dump(base_ptr);
  608. return 0;
  609. }
  610. /* Note: This defines the complete_zboot() function */
  611. U_BOOT_SUBCMDS(zboot,
  612. U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
  613. U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""),
  614. U_BOOT_CMD_MKENT(setup, 1, 1, do_zboot_setup, "", ""),
  615. U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
  616. U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
  617. U_BOOT_CMD_MKENT(dump, 2, 1, do_zboot_dump, "", ""),
  618. )
  619. int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
  620. char *const argv[], int state_mask)
  621. {
  622. int i;
  623. for (i = 0; i < ZBOOT_STATE_COUNT; i++) {
  624. struct cmd_tbl *cmd = &zboot_subcmds[i];
  625. int mask = 1 << i;
  626. int ret;
  627. if (mask & state_mask) {
  628. ret = cmd->cmd(cmd, flag, argc, argv);
  629. if (ret)
  630. return ret;
  631. }
  632. }
  633. return 0;
  634. }
  635. int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
  636. char *const argv[], int *repeatable)
  637. {
  638. /* determine if we have a sub command */
  639. if (argc > 1) {
  640. char *endp;
  641. hextoul(argv[1], &endp);
  642. /*
  643. * endp pointing to nul means that argv[1] was just a valid
  644. * number, so pass it along to the normal processing
  645. */
  646. if (*endp)
  647. return do_zboot(cmdtp, flag, argc, argv, repeatable);
  648. }
  649. do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
  650. ZBOOT_STATE_LOAD | ZBOOT_STATE_SETUP |
  651. ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
  652. return CMD_RET_FAILURE;
  653. }
  654. U_BOOT_CMDREP_COMPLETE(
  655. zboot, 8, do_zboot_parent, "Boot bzImage",
  656. "[addr] [size] [initrd addr] [initrd size] [setup] [cmdline]\n"
  657. " addr - The optional starting address of the bzimage.\n"
  658. " If not set it defaults to the environment\n"
  659. " variable \"fileaddr\".\n"
  660. " size - The optional size of the bzimage. Defaults to\n"
  661. " zero.\n"
  662. " initrd addr - The address of the initrd image to use, if any.\n"
  663. " initrd size - The size of the initrd image to use, if any.\n"
  664. " setup - The address of the kernel setup region, if this\n"
  665. " is not at addr\n"
  666. " cmdline - Environment variable containing the kernel\n"
  667. " command line, to override U-Boot's normal\n"
  668. " cmdline generation\n"
  669. "\n"
  670. "Sub-commands to do part of the zboot sequence:\n"
  671. "\tstart [addr [arg ...]] - specify arguments\n"
  672. "\tload - load OS image\n"
  673. "\tsetup - set up table\n"
  674. "\tinfo - show summary info\n"
  675. "\tgo - start OS\n"
  676. "\tdump [addr] - dump info (optional address of boot params)",
  677. complete_zboot
  678. );