2

When I boot linux on zynq board, one of the line that I get is;

Starting kernel . . .

For debugging purpose I wanted to know where in the source code these lines are written, I would change them and then add printf/printk statements at various points to debug my linux kernel. I found that in the bootm.c file it was indeed written. But I also found this 'fake' stuff here which I am uanble to understand.

/**
 * announce_and_cleanup() - Print message and prepare for kernel boot
 *
 * @fake: non-zero to do everything except actually boot
 */
static void announce_and_cleanup(int fake)
{
        printf("\n Starting kernel ...%s\n\n", fake ?
                "(fake run for tracing)" : "");
        bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
#ifdef CONFIG_BOOTSTAGE_FDT
           if (flag == BOOTM_STATE_OS_FAKE_GO)
                bootstage_fdt_add_report();
#endif
#ifdef CONFIG_BOOTSTAGE_REPORT
        bootstage_report();
#endif

the complete file is available here also

What exactly is this 'fake' stuf and why do we need it?

gpuguy
  • 1,356

1 Answers1

0

The announce_and_cleanup routine doesn't use its fake parameter except for printing the "(fake run for tracing)" or not. In particular, it doesn't pass it on to the functions it calls after printf(). The parameter comment for fake says non-zero means do everything except actually boot, and the difference in printf() cannot be the cause for that.

If you look at where announce_and_cleanup() is being called, then fake might be a bit clearer (from the same file you link to):

 248/* Subcommand: GO */
 249static void boot_jump_linux(bootm_headers_t *images, int flag)
 250{
 251#ifdef CONFIG_ARM64
 252        void (*kernel_entry)(void *fdt_addr);
 253        int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
 254
 255        kernel_entry = (void (*)(void *fdt_addr))images->ep;
 256
 257        debug("## Transferring control to Linux (at address %lx)...\n",
 258                (ulong) kernel_entry);
 259        bootstage_mark(BOOTSTAGE_ID_RUN_OS);
 260
 261        announce_and_cleanup(fake);
 262
 263        if (!fake)
 264                kernel_entry(images->ft_addr);
 265#else
 266        unsigned long machid = gd->bd->bi_arch_number;
 267        char *s;
 268        void (*kernel_entry)(int zero, int arch, uint params);
 269        unsigned long r2;
 270        int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
 271
 272        kernel_entry = (void (*)(int, int, uint))images->ep;
 273
 274        s = getenv("machid");
 275        if (s) {
 276                strict_strtoul(s, 16, &machid);
 277                printf("Using machid 0x%lx from environment\n", machid);
 278        }
 279
 280        debug("## Transferring control to Linux (at address %08lx)" \
 281                "...\n", (ulong) kernel_entry);
 282        bootstage_mark(BOOTSTAGE_ID_RUN_OS);
 283        announce_and_cleanup(fake);
 284
 285        if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
 286                r2 = (unsigned long)images->ft_addr;
 287        else
 288                r2 = gd->bd->bi_boot_params;
 289
 290        if (!fake)
 291                kernel_entry(0, machid, r2);
 292#endif
 293}

if fake is non-zero for announce_and_cleanup(), the kernel_entry() is never called and the program control flow does not transfer to the loaded kernel.

Anthon
  • 79,293