title: How to optimize U-boot to kernel hand-off code?
body: <p>Platform: Linux on ARM Cortex A9 on Xilinx Zynq SoC.</p>
  
  <p>I asked a question : <a href="https://unix.stackexchange.com/questions/124403/why-is-kernel-boot-starting-too-late">Why is kernel boot starting too late</a> </p>
  
  <p>Basically I am trying to understand and then minimize the delay between these two events:</p>
  
  <pre><code>[Sat Apr 12 19:33:50.692 2014] Starting kernel ...
  [Sat Apr 12 19:33:50.692 2014] 
  [Sat Apr 12 19:33:51.298 2014] Booting Linux on physical CPU 0x0
  </code></pre>
  
  <p>The first line tells that the control is being given to the kernel now, while thesecond line tells that the control is now with the kernel and is being executed by the CPU. </p>
  
  <p>This hand-off from u-boot to kernel is taking too much time for our application. </p>
  
  <p>To understand what is going on between these two events I inserted printf statements in:</p>
  
  <p>1- <a href="https://github.com/Xilinx/u-boot-xlnx/blob/master/arch/arm/lib/bootm.c" rel="nofollow noreferrer">bootm.c</a>  </p>
  
  <p>I put the following line  at the end of the function <code>static void boot_jump_linux(bootm_headers_t *images, int flag)</code></p>
  
  <pre><code>         }
          if (!fake)
                 {printf("above kernel_entry in boot_jump_linux in bootm.c\n");
                  kernel_entry(0, machid, r2);
                  printf("below kernel_entry boot_jump_linux in bootm.c\n");
  
                 }
  }
  </code></pre>
  
  <p>2- <a href="https://github.com/Xilinx/linux-xlnx/blob/master/init/main.c" rel="nofollow noreferrer">main.c</a>     </p>
  
  <p>I put my statement like this in the <code>start_kernel</code> function: </p>
  
  <pre><code>asmlinkage void __init start_kernel(void)
  {
    printk("I am the first statement in start_kernel in main.c" );
          char * command_line;
          extern const struct kernel_param __start___param[], __stop___param[];
  </code></pre>
  
  <p>Then I compiled the u-boot and kernel and the new log message has the following lines: </p>
  
  <pre><code>[Sat Apr 12 19:33:50.692 2014] Starting kernel ...
  [Sat Apr 12 19:33:50.692 2014] above kernel_entry in boot_jump_linux in bootm.c
  
  [Sat Apr 12 19:33:51.298 2014] I am the first statement in start_kernel in main.c 
  [Sat Apr 12 19:33:51.298 2014] Booting Linux on physical CPU 0x0
  </code></pre>
  
  <p>(In fact I put printf statements at many places but all thsoe are comming either above "starting kernel..."  or below "Booting Linux on physical CPU 0x0", so I am ignoring it in this discussion. I also used ftrace to see the hotspot, but it is not reporting u-boot functions). </p>
  
  <p>I observed that "below kernel_entry in boot_jump_linux in bootm.c" is never printed anywhere in the log message. This shows that the control will not return after function kernel_entry(0, machid, r2); is called because the linux has now the control and is being executed. </p>
  
  <p>So my aim is to know which function is being executed during these two events.  </p>
  
  <p>Now to understand what is happening (which not yet clear even after inserting my printf/printk messages) I asked the following questions:</p>
  
  <p>1- <a href="https://stackoverflow.com/questions/24423960/in-u-boot-kernel-entry-points-to-which-function/24423961?noredirect=1#comment37791644_24423961">In u-boot, kernel_entry points to which function?</a></p>
  
  <p>2- <a href="https://stackoverflow.com/questions/24409821/trying-to-understand-the-usage-of-function-pointer/24414832#24414832">Trying to understand the usage of function pointer</a></p>
  
  <p>Based on the answers there I am suspecting that my hot spot i.e the code taking much time is located in one of the following files:</p>
  
  <p>1- <a href="https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/kernel/head.S" rel="nofollow noreferrer">https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/kernel/head.S</a></p>
  
  <p>2- <a href="https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/kernel/head-common.S" rel="nofollow noreferrer">https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/kernel/head-common.S</a></p>
  
  <p>3- <a href="https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/boot/compressed/head.S" rel="nofollow noreferrer">https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/boot/compressed/head.S</a></p>
  
  <p>My questions:</p>
  
  <p>1- Is my understanding correct that I should focus on the above files ? </p>
  
  <p>2- After the call to <code>kernel_entry(0, machid, r2);</code> is made, the control goes to which of the above code and which line? </p>
  
  <p>I am suspecting the file <a href="https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/boot/compressed/head.S" rel="nofollow noreferrer">https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/boot/compressed/head.S</a>
   is of no use to me since this is required for decompression, but my kernel is already decompressed, since the following line can be seen much early in u-boot log: </p>
  
  <pre><code>[Sat Apr 12 19:33:50.596 2014]    Uncompressing Kernel Image ... OK
  </code></pre>
  
  <p>The full log is <a href="https://unix.stackexchange.com/questions/124403/why-is-kernel-boot-starting-too-late">here</a>.  </p>
  
  <p>Can someone enlight me in this regard ? </p>
  
  <p>Many thanks in advance!!   </p>