Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active June 3, 2024 06:15
Show Gist options
  • Save lupyuen/cb14b278d2749fc83d3709f5d1f604e4 to your computer and use it in GitHub Desktop.
Save lupyuen/cb14b278d2749fc83d3709f5d1f604e4 to your computer and use it in GitHub Desktop.
Attached is the RISC-V Disassembly for Apache NuttX RTOS. How does bl808_head call nx_start_application?

Attached is the RISC-V Disassembly for Apache NuttX RTOS. How does bl808_head call nx_start_application?

RISC-V Disassembly: https://github.com/lupyuen2/wip-nuttx/releases/download/sg2000-1/nuttx.S

(Google Gemini 1.5 Pro / Free version of Google AI Studio)

The provided disassembly doesn't contain the definition of bl808_head, only its call to real_start. The actual process of calling nx_start_application is more involved and spread across multiple files. Here's a breakdown:

1. real_start Initialization:

  • real_start in bl808_head.S performs basic setup, including stack initialization and enabling the trap vector.
  • It then jumps to bl808_start in bl808_start.c.

2. bl808_start Setup:

  • bl808_start handles more initialization:
    • Clears BSS section.
    • Sets up the CPU idle stack.
    • Copies the RAM disk.
    • Adds the current CPU core (mhartid) to the system.
    • Configures the MMU.
    • Finally, calls bl808_start_s.

3. bl808_start_s Early Boot:

  • bl808_start_s performs further initialization:
    • Configures the FPU.
    • Prints progress indicators.
    • Initializes the memory manager.
    • Calls nx_start in nx_start.c.

4. nx_start Core OS Initialization:

  • nx_start handles core OS setup:
    • Initializes task lists, the IDLE task, etc.
    • Initializes the memory manager.
    • Initializes various subsystems:
      • File system.
      • Interrupt handling.
      • POSIX timers.
      • Signals.
      • Message queues.
      • Binary format loader (binfmt).
    • Calls up_initialize to perform architecture-specific initialization.
    • Calls drivers_initialize.
    • Calls board_early_initialize.
    • Sets the OS initialization state to OSINIT_HARDWARE.
    • Sets up standard file descriptors for the IDLE task.
    • Sets the OS initialization state to OSINIT_OSREADY.
    • Calls nx_bringup in nx_bringup.c.

5. nx_bringup Application Startup:

  • nx_bringup handles application-level initialization:
    • Sets up environment variables (e.g., PWD, PATH).
    • Calls nx_workqueues to initialize work queues.
    • Calls nx_create_initthread to create the "AppBringUp" task.

6. nx_create_initthread Task Creation:

  • nx_create_initthread uses nxthread_create to create the "AppBringUp" task with the entry point set to nx_start_task.

7. nx_start_task Late Initialization:

  • nx_start_task is the entry point of the "AppBringUp" task:
    • Calls board_late_initialize for any board-specific late initialization.
    • Mounts the initial file system (e.g., rootfs).
    • Prints a message indicating the start of the init task.
    • Calls exec_spawn to launch the init process specified in CONFIG_INIT_FILEPATH. This is likely where the actual application code is loaded and executed.

Conclusion:

  • bl808_head itself doesn't call nx_start_application. It initiates a chain of initialization processes.
  • nx_start_application is most likely called indirectly through exec_spawn within nx_start_task, which is the entry point of a separate "AppBringUp" task.
  • The provided disassembly doesn't include the definition of exec_spawn, so we can't see the exact details of how the application is launched from there.

To understand the complete flow, you would need to analyze the code for exec_spawn, board_late_initialize, and the configuration options related to the init process (CONFIG_INIT_FILEPATH, etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment