Commit 983c72f479173bced296f7292b4a9fbef9d17688

Authored by Simon Glass
Committed by Tom Rini
1 parent 37544a6dab

Clarify bootm OS arguments

At present the arguments to bootm are processed in a somewhat confusing
way. Sub-functions must know how many arguments their calling functions
have processed, and the OS boot function must also have this information.
Also it isn't obvious that 'bootm' and 'bootm start' provide arguments in
the same way.

Adjust the code so that arguments are removed from the list before calling
a sub-function. This means that all functions can know that argv[0] is the
first argument of which they need to take notice.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 6 changed files with 54 additions and 37 deletions Side-by-side Diff

arch/microblaze/lib/bootm.c
... ... @@ -62,8 +62,8 @@
62 62  
63 63 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
64 64  
65   - if (!of_flat_tree && argc > 3)
66   - of_flat_tree = (char *)simple_strtoul(argv[3], NULL, 16);
  65 + if (!of_flat_tree && argc > 1)
  66 + of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
67 67  
68 68 /* fixup the initrd now that we know where it should be */
69 69 if (images->rd_start && images->rd_end && of_flat_tree)
arch/nios2/lib/bootm.c
... ... @@ -40,8 +40,8 @@
40 40 if (images->ft_len)
41 41 of_flat_tree = images->ft_addr;
42 42 #endif
43   - if (!of_flat_tree && argc > 3)
44   - of_flat_tree = (char *)simple_strtoul(argv[3], NULL, 16);
  43 + if (!of_flat_tree && argc > 1)
  44 + of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
45 45 if (of_flat_tree)
46 46 initrd_end = (ulong)of_flat_tree;
47 47  
arch/openrisc/lib/bootm.c
... ... @@ -63,8 +63,8 @@
63 63  
64 64 show_boot_progress(15);
65 65  
66   - if (!of_flat_tree && argc > 3)
67   - of_flat_tree = (char *)simple_strtoul(argv[3], NULL, 16);
  66 + if (!of_flat_tree && argc > 1)
  67 + of_flat_tree = (char *)simple_strtoul(argv[1], NULL, 16);
68 68 #ifdef DEBUG
69 69 printf("## Transferring control to Linux (at address 0x%08lx) " \
70 70 "ramdisk 0x%08lx, FDT 0x%08lx...\n",
... ... @@ -104,9 +104,18 @@
104 104 * - verified image architecture (PPC) and type (KERNEL or MULTI),
105 105 * - loaded (first part of) image to header load address,
106 106 * - disabled interrupts.
  107 + *
  108 + * @flag: Command flags (CMD_FLAG_...)
  109 + * @argc: Number of arguments. Note that the arguments are shifted down
  110 + * so that 0 is the first argument not processed by U-Boot, and
  111 + * argc is adjusted accordingly. This avoids confusion as to how
  112 + * many arguments are available for the OS.
  113 + * @images: Pointers to os/initrd/fdt
  114 + * @return 1 on error. On success the OS boots so this function does
  115 + * not return.
107 116 */
108 117 typedef int boot_os_fn(int flag, int argc, char * const argv[],
109   - bootm_headers_t *images); /* pointers to os/initrd/fdt */
  118 + bootm_headers_t *images);
110 119  
111 120 #ifdef CONFIG_BOOTM_LINUX
112 121 extern boot_os_fn do_bootm_linux;
... ... @@ -457,7 +466,7 @@
457 466 return 0;
458 467 }
459 468 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
460   - (*appl)(argc-1, &argv[1]);
  469 + (*appl)(argc, argv);
461 470 return 0;
462 471 }
463 472  
464 473  
465 474  
... ... @@ -486,17 +495,15 @@
486 495 cmd_tbl_t *c;
487 496 boot_os_fn *boot_fn;
488 497  
489   - c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  498 + c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  499 + argc--; argv++;
490 500  
491 501 if (c) {
492 502 state = (long)c->cmd;
493 503  
494 504 /* treat start special since it resets the state machine */
495   - if (state == BOOTM_STATE_START) {
496   - argc--;
497   - argv++;
  505 + if (state == BOOTM_STATE_START)
498 506 return bootm_start(cmdtp, flag, argc, argv);
499   - }
500 507 } else {
501 508 /* Unrecognized command */
502 509 return CMD_RET_USAGE;
503 510  
... ... @@ -611,11 +618,12 @@
611 618 #endif
612 619  
613 620 /* determine if we have a sub command */
614   - if (argc > 1) {
  621 + argc--; argv++;
  622 + if (argc > 0) {
615 623 char *endp;
616 624  
617   - simple_strtoul(argv[1], &endp, 16);
618   - /* endp pointing to NULL means that argv[1] was just a
  625 + simple_strtoul(argv[0], &endp, 16);
  626 + /* endp pointing to NULL means that argv[0] was just a
619 627 * valid number, pass it along to the normal bootm processing
620 628 *
621 629 * If endp is ':' or '#' assume a FIT identifier so pass
622 630  
623 631  
624 632  
... ... @@ -816,22 +824,22 @@
816 824 #endif
817 825  
818 826 /* find out kernel image address */
819   - if (argc < 2) {
  827 + if (argc < 1) {
820 828 img_addr = load_addr;
821 829 debug("* kernel: default image load address = 0x%08lx\n",
822 830 load_addr);
823 831 #if defined(CONFIG_FIT)
824   - } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
  832 + } else if (fit_parse_conf(argv[0], load_addr, &img_addr,
825 833 &fit_uname_config)) {
826 834 debug("* kernel: config '%s' from image at 0x%08lx\n",
827 835 fit_uname_config, img_addr);
828   - } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
  836 + } else if (fit_parse_subimage(argv[0], load_addr, &img_addr,
829 837 &fit_uname_kernel)) {
830 838 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
831 839 fit_uname_kernel, img_addr);
832 840 #endif
833 841 } else {
834   - img_addr = simple_strtoul(argv[1], NULL, 16);
  842 + img_addr = simple_strtoul(argv[0], NULL, 16);
835 843 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
836 844 }
837 845  
838 846  
839 847  
... ... @@ -1401,16 +1409,16 @@
1401 1409 consdev = "scc3";
1402 1410 #endif
1403 1411  
1404   - if (argc > 2) {
  1412 + if (argc > 0) {
1405 1413 ulong len;
1406 1414 int i;
1407 1415  
1408   - for (i = 2, len = 0; i < argc; i += 1)
  1416 + for (i = 0, len = 0; i < argc; i += 1)
1409 1417 len += strlen(argv[i]) + 1;
1410 1418 cmdline = malloc(len);
1411 1419  
1412   - for (i = 2, len = 0; i < argc; i += 1) {
1413   - if (i > 2)
  1420 + for (i = 0, len = 0; i < argc; i += 1) {
  1421 + if (i > 0)
1414 1422 cmdline[len++] = ' ';
1415 1423 strcpy(&cmdline[len], argv[i]);
1416 1424 len += strlen(argv[i]);
... ... @@ -248,13 +248,16 @@
248 248 ulong default_addr;
249 249 int fdt_noffset;
250 250 #endif
  251 + const char *select = NULL;
251 252  
252 253 *of_flat_tree = NULL;
253 254 *of_size = 0;
254 255  
255   - if (argc > 3 || genimg_has_config(images)) {
  256 + if (argc > 2)
  257 + select = argv[2];
  258 + if (select || genimg_has_config(images)) {
256 259 #if defined(CONFIG_FIT)
257   - if (argc > 3) {
  260 + if (select) {
258 261 /*
259 262 * If the FDT blob comes from the FIT image and the
260 263 * FIT image address is omitted in the command line
261 264  
262 265  
... ... @@ -268,18 +271,18 @@
268 271 else
269 272 default_addr = load_addr;
270 273  
271   - if (fit_parse_conf(argv[3], default_addr,
  274 + if (fit_parse_conf(select, default_addr,
272 275 &fdt_addr, &fit_uname_config)) {
273 276 debug("* fdt: config '%s' from image at 0x%08lx\n",
274 277 fit_uname_config, fdt_addr);
275   - } else if (fit_parse_subimage(argv[3], default_addr,
  278 + } else if (fit_parse_subimage(select, default_addr,
276 279 &fdt_addr, &fit_uname_fdt)) {
277 280 debug("* fdt: subimage '%s' from image at 0x%08lx\n",
278 281 fit_uname_fdt, fdt_addr);
279 282 } else
280 283 #endif
281 284 {
282   - fdt_addr = simple_strtoul(argv[3], NULL, 16);
  285 + fdt_addr = simple_strtoul(select, NULL, 16);
283 286 debug("* fdt: cmdline image address = 0x%08lx\n",
284 287 fdt_addr);
285 288 }
... ... @@ -816,20 +816,23 @@
816 816 ulong default_addr;
817 817 int rd_noffset;
818 818 #endif
  819 + const char *select = NULL;
819 820  
820 821 *rd_start = 0;
821 822 *rd_end = 0;
822 823  
  824 + if (argc >= 2)
  825 + select = argv[1];
823 826 /*
824 827 * Look for a '-' which indicates to ignore the
825 828 * ramdisk argument
826 829 */
827   - if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
  830 + if (select && strcmp(select, "-") == 0) {
828 831 debug("## Skipping init Ramdisk\n");
829 832 rd_len = rd_data = 0;
830   - } else if (argc >= 3 || genimg_has_config(images)) {
  833 + } else if (select || genimg_has_config(images)) {
831 834 #if defined(CONFIG_FIT)
832   - if (argc >= 3) {
  835 + if (select) {
833 836 /*
834 837 * If the init ramdisk comes from the FIT image and
835 838 * the FIT image address is omitted in the command
836 839  
... ... @@ -841,12 +844,12 @@
841 844 else
842 845 default_addr = load_addr;
843 846  
844   - if (fit_parse_conf(argv[2], default_addr,
845   - &rd_addr, &fit_uname_config)) {
  847 + if (fit_parse_conf(select, default_addr,
  848 + &rd_addr, &fit_uname_config)) {
846 849 debug("* ramdisk: config '%s' from image at "
847 850 "0x%08lx\n",
848 851 fit_uname_config, rd_addr);
849   - } else if (fit_parse_subimage(argv[2], default_addr,
  852 + } else if (fit_parse_subimage(select, default_addr,
850 853 &rd_addr, &fit_uname_ramdisk)) {
851 854 debug("* ramdisk: subimage '%s' from image at "
852 855 "0x%08lx\n",
... ... @@ -854,7 +857,7 @@
854 857 } else
855 858 #endif
856 859 {
857   - rd_addr = simple_strtoul(argv[2], NULL, 16);
  860 + rd_addr = simple_strtoul(select, NULL, 16);
858 861 debug("* ramdisk: cmdline image address = "
859 862 "0x%08lx\n",
860 863 rd_addr);
... ... @@ -918,7 +921,10 @@
918 921 #endif
919 922 default:
920 923 #ifdef CONFIG_SUPPORT_RAW_INITRD
921   - if (argc >= 3 && (end = strchr(argv[2], ':'))) {
  924 + end = NULL;
  925 + if (select)
  926 + end = strchr(select, ':');
  927 + if (end) {
922 928 rd_len = simple_strtoul(++end, NULL, 16);
923 929 rd_data = rd_addr;
924 930 } else