Laczen commented on PR #18373:
URL: https://github.com/apache/nuttx/pull/18373#issuecomment-3916112230

   @aviralgarg05 Thank you for the work you are putting into this. Booting a 
NuttX image from a NuttX image on an esp32 is not a trivial task.
   
   I have taken a look at the code and I see some room for improvement.
   
   The general approach should be:
   1. Find out the header absolute position (reading the header can also be 
done using NuttX approach),
   2. Verify all data in the header to see if the image can be booted (the iram 
and dram sizes will be limited by the stack region and iram stub region, see 
further point 6 and 7),
   3. Disable interrupts,
   4. From this point on we can no longer safely return to NuttX
   5. Copy any rtc iram/dram to the correct location, 
   6. Reserve a region at the end of dram for a new stack (do not use the heap 
as this might end up overwritten by dram copy),
   7. Reserve a region at the end of iram for the stub bootloader function (the 
stub bootloader function is stored in iram and takes entry point, iram location 
+ iram destination + iram size, dram location + dram destination + dram size) 
and copy the stub bootloader function to the end of dram. All parameters for 
the stub bootloader function will not fit in the registers but it is possible 
to use a part of the "new stack" region to pass them and declare the real stack 
start a little higher. 
   8. Call the stub bootloader after copying.
   
   This method should be generic (not rely on the existence/ use of the rtc), 
at the expense of some iram/dram not being available to the image.
   
   The region starts and end for dram and iram can be found by including 
"soc/soc.h":
   ```
   #define SOC_DRAM_LOW    0x3FFAE000  /* Start of DRAM */
   #define SOC_DRAM_HIGH   0x40000000  /* End of DRAM */
   #define SOC_IRAM_LOW    0x40080000  /* Start of IRAM (after cache) */
   #define SOC_IRAM_HIGH   0x400C0000  /* End of IRAM */
   ``` 
   
   Have you been able to setup a test method to validate the PR?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to