Commit 65f3b1f99274ef876499c082aa66a83f46372d16
Committed by
Tom Rini
1 parent
fc1f58a4da
Exists in
smarc_8mq_lf_v2020.04
and in
11 other branches
sandbox: Filter arguments when starting U-Boot
The current method of starting U-Boot from U-Boot adds arguments to pass the memory file through, so that memory is preserved. This is fine for a single call, but if we call from TPL -> SPL -> U-Boot the arguments build up and we have several memory files in the argument list. Adjust the implementation to filter out arguments that we want to replace with new ones. Also print a useful error if the exec() call fails. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 1 changed file with 26 additions and 6 deletions Side-by-side Diff
arch/sandbox/cpu/os.c
... | ... | @@ -576,10 +576,10 @@ |
576 | 576 | */ |
577 | 577 | static int add_args(char ***argvp, char *add_args[], int count) |
578 | 578 | { |
579 | - char **argv; | |
579 | + char **argv, **ap; | |
580 | 580 | int argc; |
581 | 581 | |
582 | - for (argv = *argvp, argc = 0; (*argvp)[argc]; argc++) | |
582 | + for (argc = 0; (*argvp)[argc]; argc++) | |
583 | 583 | ; |
584 | 584 | |
585 | 585 | argv = os_malloc((argc + count + 1) * sizeof(char *)); |
... | ... | @@ -587,7 +587,24 @@ |
587 | 587 | printf("Out of memory for %d argv\n", count); |
588 | 588 | return -ENOMEM; |
589 | 589 | } |
590 | - memcpy(argv, *argvp, argc * sizeof(char *)); | |
590 | + for (ap = *argvp, argc = 0; *ap; ap++) { | |
591 | + char *arg = *ap; | |
592 | + | |
593 | + /* Drop args that we don't want to propagate */ | |
594 | + if (*arg == '-' && strlen(arg) == 2) { | |
595 | + switch (arg[1]) { | |
596 | + case 'j': | |
597 | + case 'm': | |
598 | + ap++; | |
599 | + continue; | |
600 | + } | |
601 | + } else if (!strcmp(arg, "--rm_memory")) { | |
602 | + ap++; | |
603 | + continue; | |
604 | + } | |
605 | + argv[argc++] = arg; | |
606 | + } | |
607 | + | |
591 | 608 | memcpy(argv + argc, add_args, count * sizeof(char *)); |
592 | 609 | argv[argc + count] = NULL; |
593 | 610 | |
... | ... | @@ -611,6 +628,7 @@ |
611 | 628 | int fd, err; |
612 | 629 | char *extra_args[5]; |
613 | 630 | char **argv = state->argv; |
631 | + int argc; | |
614 | 632 | #ifdef DEBUG |
615 | 633 | int i; |
616 | 634 | #endif |
617 | 635 | |
... | ... | @@ -630,11 +648,13 @@ |
630 | 648 | extra_args[1] = (char *)fname; |
631 | 649 | extra_args[2] = "-m"; |
632 | 650 | extra_args[3] = mem_fname; |
633 | - extra_args[4] = "--rm_memory"; | |
634 | - err = add_args(&argv, extra_args, | |
635 | - sizeof(extra_args) / sizeof(extra_args[0])); | |
651 | + argc = 4; | |
652 | + if (state->ram_buf_rm) | |
653 | + extra_args[argc++] = "--rm_memory"; | |
654 | + err = add_args(&argv, extra_args, argc); | |
636 | 655 | if (err) |
637 | 656 | return err; |
657 | + argv[0] = (char *)fname; | |
638 | 658 | |
639 | 659 | #ifdef DEBUG |
640 | 660 | for (i = 0; argv[i]; i++) |