Debug for ARGS on u-boot

備忘録。

From 4dad630abed1a56a70816b75e4c71ce844dd23bb Mon Sep 17 00:00:00 2001
From: Hidemi Ishihara <hidemi@sweetcafe.jp>
Date: Sat, 8 Apr 2017 13:51:50 +0900
Subject: [PATCH] Debug for ARGS

---
 arch/arm/lib/bootm.c | 45 ++++++++++++++++++++++++++++++++++++++-------
 cmd/bootm.c          | 28 +++++++++++++++++++++++++++-
 cmd/pxe.c            |  5 +++++
 common/bootm.c       | 19 +++++++++++++++++++
 common/bootm_os.c    | 11 +++++++++++
 common/command.c     | 24 ++++++++++++++++++++++++
 common/image.c       |  2 ++
 7 files changed, 126 insertions(+), 8 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 82354dd..db97f19 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -205,8 +205,12 @@ static void boot_prep_linux(bootm_headers_t *images)
 {
    char *commandline = getenv("bootargs");

+   printf("boot_prep_linux: in\n");
+   //  printf(" - bootargs: %s\n", commandline);
+
    if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
 #ifdef CONFIG_OF_LIBFDT
+     //printf("using: FDT\n");
        debug("using: FDT\n");
        if (image_setup_linux(images)) {
            printf("FDT creation failed! hanging...");
@@ -214,7 +218,7 @@ static void boot_prep_linux(bootm_headers_t *images)
        }
 #endif
    } else if (BOOTM_ENABLE_TAGS) {
-       debug("using: ATAGS\n");
+     printf("using: ATAGS\n");
        setup_start_tag(gd->bd);
        if (BOOTM_ENABLE_SERIAL_TAG)
            setup_serial_tag(&params);
@@ -246,6 +250,8 @@ static void boot_prep_linux(bootm_headers_t *images)
        printf("FDT and ATAGS support not compiled in - hanging\n");
        hang();
    }
+
+   printf("boot_prep_linux: out\n");
 }

 #ifdef CONFIG_ARMV7_NONSEC
@@ -271,6 +277,7 @@ bool armv7_boot_nonsec(void)
 /* Subcommand: GO */
 static void boot_jump_linux(bootm_headers_t *images, int flag)
 {
+    printf("boot_jump_linux: in\n");
 #ifdef CONFIG_ARM64
    void (*kernel_entry)(void *fdt_addr, void *res0, void *res1,
            void *res2);
@@ -307,27 +314,44 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
        printf("Using machid 0x%lx from environment\n", machid);
    }

-   debug("## Transferring control to Linux (at address %08lx)" \
+   printf("## Transferring control to Linux (at address %08lx)"    \
        "...\n", (ulong) kernel_entry);
+
    bootstage_mark(BOOTSTAGE_ID_RUN_OS);
+   printf("boot_jump_linux: bootstage_mark\n");
    announce_and_cleanup(fake);

-   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
-       r2 = (unsigned long)images->ft_addr;
-   else
-       r2 = gd->bd->bi_boot_params;
+   printf("boot_jump_linux: announce_and_cleanup\n");
+
+   if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len){
+        r2 = (unsigned long)images->ft_addr;
+       // iamges->ft_lenはDTBのファイルサイズが入る
+       printf("boot_jump_linux: (IMAGE_ENABLE_OF_LIBFDT && images->ft_len\n");
+       printf(" - images->ft_len: %d\n", images->ft_len);
+    }else{
+        r2 = gd->bd->bi_boot_params;
+        printf("boot_jump_linux: r2 = gd->bd->bi_boot_params\n");
+    }

    if (!fake) {
 #ifdef CONFIG_ARMV7_NONSEC
+  printf("boot_jump_linux: CONFIG_ARMV7_NONSEC\n");
        if (armv7_boot_nonsec()) {
            armv7_init_nonsec();
            secure_ram_addr(_do_nonsec_entry)(kernel_entry,
                              0, machid, r2);
        } else
 #endif
+       {
+            printf("boot_jump_linux: kernel entry\n");
+            //printf(" - machid: %016lx\n", machid);
+           //printf(" - r2    : %016lx\n", r2);
+           //printf(" - r2    : %08x\n", images->ft_addr);
            kernel_entry(0, machid, r2);
+        }
    }
 #endif
+  printf("boot_jump_linux: out\n");
 }

 /* Main Entry point for arm bootm implementation
@@ -339,22 +363,29 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
 int do_bootm_linux(int flag, int argc, char * const argv[],
           bootm_headers_t *images)
 {
-   /* No need for those on ARM */
+  printf("do_bootm_linux: in\n");
+
+  /* No need for those on ARM */
    if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
        return -1;

    if (flag & BOOTM_STATE_OS_PREP) {
+  printf("do_bootm_linux: prep\n");
        boot_prep_linux(images);
        return 0;
    }

    if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
+  printf("do_bootm_linux: jump\n");
        boot_jump_linux(images, flag);
        return 0;
    }

+  printf("do_bootm_linux: prep2\n");
    boot_prep_linux(images);
+  printf("do_bootm_linux: jump2\n");
    boot_jump_linux(images, flag);
+  printf("do_bootm_linux: ouy\n");
    return 0;
 }

diff --git a/cmd/bootm.c b/cmd/bootm.c
index 16fdea5..1fac462 100644
--- a/cmd/bootm.c
+++ b/cmd/bootm.c
@@ -67,6 +67,8 @@ static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
    long state;
    cmd_tbl_t *c;

+   printf("do_bootm_subcommand(): in");
+
    c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
    argc--; argv++;

@@ -99,6 +101,8 @@ int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
    static int relocated = 0;

+   printf("do_bootm(): in\n");
+
    if (!relocated) {
        int i;

@@ -560,6 +564,14 @@ static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
    int ret;
    ulong zi_start, zi_end;

+   printf("bootz_start(): in\n");
+
+   if(argc > 0){
+     for(int i = 0; i < argc; i++){
+       printf(" - args[%d]: %s\n", i, argv[i]);
+     }
+   }
+
    ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
                  images, 1);

@@ -587,6 +599,8 @@ static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
    if (bootm_find_images(flag, argc, argv))
        return 1;

+   printf("bootz_start(): out\n");
+
    return 0;
 }

@@ -594,6 +608,8 @@ int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
    int ret;

+   printf("do_bootz(): in\n");
+
    /* Consume 'bootz' */
    argc--; argv++;

@@ -606,12 +622,16 @@ int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
     */
    bootm_disable_interrupts();

+   printf("do_bootz(): disable_interrupt()\n");
+
    images.os.os = IH_OS_LINUX;
    ret = do_bootm_states(cmdtp, flag, argc, argv,
                  BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
                  BOOTM_STATE_OS_GO,
                  &images, 1);

+   printf("do_bootz(): out\n");
+
    return ret;
 }

@@ -661,13 +681,15 @@ static int booti_setup(bootm_headers_t *images)
    uint64_t dst;
    uint64_t image_size;

+   printf("booti_setup(): in");
+
    ih = (struct Image_header *)map_sysmem(images->ep, 0);

    if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
        puts("Bad Linux ARM64 Image magic!\n");
        return 1;
    }
-   
+
    if (ih->image_size == 0) {
        puts("Image lacks image_size field, assuming 16MiB\n");
        image_size = 16 << 20;
@@ -705,6 +727,8 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
    int ret;
    struct Image_header *ih;

+   printf("booti_start(): in\n");
+
    ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
                  images, 1);

@@ -743,6 +767,8 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
    int ret;

+   printf("do_booti(): in\n");
+
    /* Consume 'booti' */
    argc--; argv++;

diff --git a/cmd/pxe.c b/cmd/pxe.c
index 9434a18..2c6cde2 100644
--- a/cmd/pxe.c
+++ b/cmd/pxe.c
@@ -625,6 +625,8 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
    ulong kernel_addr;
    void *buf;

+   printf("label_boot(): in\n");
+
    label_print(label);

    label->attempted = 1;
@@ -803,6 +805,9 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
        do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
 #endif
    unmap_sysmem(buf);
+
+   printf("label_boot(): out\n");
+
    return 1;
 }

diff --git a/common/bootm.c b/common/bootm.c
index 2431019..b054df9 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -605,6 +605,14 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
    ulong iflag = 0;
    int ret = 0, need_boot_fn;

+   printf("do_bootm_states: in\n");
+
+   if(argc > 0){
+     for(int i = 0; i < argc; i++){
+       printf("argv[%d]: %s\n", i, argv[i]);
+     }
+   }
+
    images->state |= states;

    /*
@@ -623,6 +631,7 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
    }

    /* Load the OS */
+   printf("do_bootm_states: Load the OS\n");
    if (!ret && (states & BOOTM_STATE_LOADOS)) {
        ulong load_end;

@@ -643,6 +652,7 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],

    /* Relocate the ramdisk */
 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
+   printf("do_bootm_states: CONFIG_SYS_BOOT_RAMDISK_HIGH\n");
    if (!ret && (states & BOOTM_STATE_RAMDISK)) {
        ulong rd_len = images->rd_end - images->rd_start;

@@ -655,6 +665,7 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
    }
 #endif
 #if IMAGE_ENABLE_OF_LIBFDT && defined(CONFIG_LMB)
+   printf("do_bootm_states: IMAGE_ENABLE_OF_LIBFDT\n");
    if (!ret && (states & BOOTM_STATE_FDT)) {
        boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr);
        ret = boot_relocate_fdt(&images->lmb, &images->ft_addr,
@@ -663,6 +674,7 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 #endif

    /* From now on, we need the OS boot function */
+   printf("do_bootm_states: From now on\n");
    if (ret)
        return ret;
    boot_fn = bootm_os_get_boot_func(images->os.os);
@@ -679,6 +691,7 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
    }

    /* Call various other states that are not generally used */
+   printf("do_bootm_states: Call various\n");
    if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
        ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
    if (!ret && (states & BOOTM_STATE_OS_BD_T))
@@ -687,6 +700,7 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
        ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);

 #ifdef CONFIG_TRACE
+   printf("do_bootm_states: Pretend to run the OS\n");
    /* Pretend to run the OS, then run a user command */
    if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
        char *cmd_list = getenv("fakegocmd");
@@ -699,18 +713,21 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 #endif

    /* Check for unsupported subcommand. */
+   printf("do_bootm_states: Check for unsupported subcommand\n");
    if (ret) {
        puts("subcommand not supported\n");
        return ret;
    }

    /* Now run the OS! We hope this doesn't return */
+   printf("do_bootm_states: Non run the OS!\n");
    if (!ret && (states & BOOTM_STATE_OS_GO))
        ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO,
                images, boot_fn);

    /* Deal with any fallout */
 err:
+   printf("do_bootm_states: error\n");
    if (iflag)
        enable_interrupts();

@@ -719,6 +736,8 @@ err:
    else if (ret == BOOTM_ERR_RESET)
        do_reset(cmdtp, flag, argc, argv);

+   printf("do_bootm_states: out\n");
+
    return ret;
 }

diff --git a/common/bootm_os.c b/common/bootm_os.c
index 9ec84bd..10d91fd 100644
--- a/common/bootm_os.c
+++ b/common/bootm_os.c
@@ -476,8 +476,14 @@ __weak void arch_preboot_os(void)
 int boot_selected_os(int argc, char * const argv[], int state,
             bootm_headers_t *images, boot_os_fn *boot_fn)
 {
+  printf("boot_selected_os: in\n");
+
+  printf("boot_selected_os: arch_preboot_os - in\n");
    arch_preboot_os();
+  printf("boot_selected_os: arch_preboot_os - out\n");
+  printf("boot_selected_os: boot_fn - in\n");
    boot_fn(state, argc, argv, images);
+  printf("boot_selected_os: boot_fn - out\n");

    /* Stand-alone may return when 'autostart' is 'no' */
    if (images->os.type == IH_TYPE_STANDALONE ||
@@ -486,11 +492,14 @@ int boot_selected_os(int argc, char * const argv[], int state,
    bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
    debug("\n## Control returned to monitor - resetting...\n");

+   printf("boot_selected_os: out\n");
+
    return BOOTM_ERR_RESET;
 }

 boot_os_fn *bootm_os_get_boot_func(int os)
 {
+  printf("bootm_os_get_boot_func: in\n");
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
    static bool relocated;

@@ -505,5 +514,7 @@ boot_os_fn *bootm_os_get_boot_func(int os)
        relocated = true;
    }
 #endif
+   printf("bootm_os_get_boot_func: out(%d)\n", os);
+   printf(" - address: %08x\n", *boot_os[os]);
    return boot_os[os];
 }
diff --git a/common/command.c b/common/command.c
index e5d9b9c..800e82e 100644
--- a/common/command.c
+++ b/common/command.c
@@ -92,6 +92,8 @@ cmd_tbl_t *find_cmd_tbl(const char *cmd, cmd_tbl_t *table, int table_len)
    int len;
    int n_found = 0;

+   printf("find_cmd_tbl: in\n");
+
    if (!cmd)
        return NULL;
    /*
@@ -149,6 +151,8 @@ int var_complete(int argc, char * const argv[], char last_char, int maxv, char *
    static char tmp_buf[512];
    int space;

+   printf("var_complete: in\n");
+
    space = last_char == '\0' || isblank(last_char);

    if (space && argc == 1)
@@ -173,6 +177,8 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv
    int n_found = 0;
    const char *cmd;

+   printf("complete_cmdv: in\n");
+
    /* sanity? */
    if (maxv < 2)
        return -2;
@@ -243,6 +249,8 @@ static int make_argv(char *s, int argvsz, char *argv[])
 {
    int argc = 0;

+   printf("make_argv: in\n");
+
    /* split into argv */
    while (argc < argvsz - 1) {

@@ -331,6 +339,8 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp)
    int cnt;
    char last_char;

+   printf("auto_complete: in\n");
+
    if (strcmp(prompt, CONFIG_SYS_PROMPT) != 0)
        return 0;   /* not in normal console */

@@ -415,6 +425,8 @@ int cmd_get_data_size(char* arg, int default_size)
 {
    /* Check for a size specification .b, .w or .l.
     */
+   printf("cmd_get_data_size: in\n");
+
    int len = strlen(arg);
    if (len > 2 && arg[len-2] == '.') {
        switch (arg[len-1]) {
@@ -445,6 +457,8 @@ void fixup_cmdtable(cmd_tbl_t *cmdtp, int size)
 {
    int i;

+   printf("fixup cmdtable: in\n");
+
    if (gd->reloc_off == 0)
        return;

@@ -497,9 +511,14 @@ static int cmd_call(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
    int result;

+   printf("cmd_call: in\n");
+
    result = (cmdtp->cmd)(cmdtp, flag, argc, argv);
    if (result)
        debug("Command failed, result=%d\n", result);
+
+   printf("cmd_call: out\n");
+
    return result;
 }

@@ -509,6 +528,8 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
    enum command_ret_t rc = CMD_RET_SUCCESS;
    cmd_tbl_t *cmdtp;

+   printf("cmd_process: in\n");
+
    /* Look up command in command table */
    cmdtp = find_cmd(argv[0]);
    if (cmdtp == NULL) {
@@ -543,6 +564,9 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[],
    }
    if (rc == CMD_RET_USAGE)
        rc = cmd_usage(cmdtp);
+
+   printf("cmd_process: out\n");
+
    return rc;
 }

diff --git a/common/image.c b/common/image.c
index 0be09e5..40d2bcf 100644
--- a/common/image.c
+++ b/common/image.c
@@ -1459,6 +1459,8 @@ int image_setup_linux(bootm_headers_t *images)
    ulong rd_len;
    int ret;

+   printf("image_setup_linux: in\n");
+
    if (IMAGE_ENABLE_OF_LIBFDT)
        boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);

-- 
2.9.3
write: 2017/04/08/ 13:54:38