1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker======= 4*61c4878aSAndroid Build Coastguard Workerpw_boot 5*61c4878aSAndroid Build Coastguard Worker======= 6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module:: 7*61c4878aSAndroid Build Coastguard Worker :name: pw_boot 8*61c4878aSAndroid Build Coastguard Worker 9*61c4878aSAndroid Build Coastguard Worker``pw_boot`` provides a linker script and some early initialization of static 10*61c4878aSAndroid Build Coastguard Workermemory regions and C++ constructors. This is enough to get many targets booted 11*61c4878aSAndroid Build Coastguard Workerand ready to run C++ code. 12*61c4878aSAndroid Build Coastguard Worker 13*61c4878aSAndroid Build Coastguard WorkerThis module is split into two components: 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard Worker1. This module, which provides the :ref:`facade <docs-facades>`. 16*61c4878aSAndroid Build Coastguard Worker2. A backend module such as :ref:`module-pw_boot_cortex_m` that implements the 17*61c4878aSAndroid Build Coastguard Worker facade. 18*61c4878aSAndroid Build Coastguard Worker 19*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-status: 20*61c4878aSAndroid Build Coastguard Worker 21*61c4878aSAndroid Build Coastguard Worker--------------------- 22*61c4878aSAndroid Build Coastguard WorkerStatus of this module 23*61c4878aSAndroid Build Coastguard Worker--------------------- 24*61c4878aSAndroid Build Coastguard Worker``pw_boot`` can be used in production if it meets your needs. In practice 25*61c4878aSAndroid Build Coastguard Workermost production projects probably won't use it because they need their own 26*61c4878aSAndroid Build Coastguard Workercustom linker scripts. The ``pw_boot`` source code can still be a useful 27*61c4878aSAndroid Build Coastguard Workerexample of how to set up a boot sequence. 28*61c4878aSAndroid Build Coastguard Worker 29*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-sequence: 30*61c4878aSAndroid Build Coastguard Worker 31*61c4878aSAndroid Build Coastguard Worker-------- 32*61c4878aSAndroid Build Coastguard WorkerSequence 33*61c4878aSAndroid Build Coastguard Worker-------- 34*61c4878aSAndroid Build Coastguard WorkerThe high-level ``pw_boot`` sequence looks like the following pseudo-code 35*61c4878aSAndroid Build Coastguard Workerinvocation of the user-implemented functions: 36*61c4878aSAndroid Build Coastguard Worker 37*61c4878aSAndroid Build Coastguard Worker.. code-block:: cpp 38*61c4878aSAndroid Build Coastguard Worker 39*61c4878aSAndroid Build Coastguard Worker void pw_boot_Entry() { // Boot entry point provided by backend. 40*61c4878aSAndroid Build Coastguard Worker pw_boot_PreStaticMemoryInit(); // User-implemented function. 41*61c4878aSAndroid Build Coastguard Worker // Static memory initialization. 42*61c4878aSAndroid Build Coastguard Worker pw_boot_PreStaticConstructorInit(); // User-implemented function. 43*61c4878aSAndroid Build Coastguard Worker // C++ static constructors are invoked. 44*61c4878aSAndroid Build Coastguard Worker pw_boot_PreMainInit(); // User-implemented function. 45*61c4878aSAndroid Build Coastguard Worker main(); // User-implemented function. 46*61c4878aSAndroid Build Coastguard Worker pw_boot_PostMain(); // User-implemented function. 47*61c4878aSAndroid Build Coastguard Worker PW_UNREACHABLE; 48*61c4878aSAndroid Build Coastguard Worker } 49*61c4878aSAndroid Build Coastguard Worker 50*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-user: 51*61c4878aSAndroid Build Coastguard Worker 52*61c4878aSAndroid Build Coastguard Worker-------------------------- 53*61c4878aSAndroid Build Coastguard WorkerUser-implemented functions 54*61c4878aSAndroid Build Coastguard Worker-------------------------- 55*61c4878aSAndroid Build Coastguard WorkerThis module expects all of the following ``extern "C"`` functions to be defined 56*61c4878aSAndroid Build Coastguard Workeroutside this module. If any of these functions are unimplemented, executables 57*61c4878aSAndroid Build Coastguard Workerwill encounter a link error. 58*61c4878aSAndroid Build Coastguard Worker 59*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-prestaticmemoryinit: 60*61c4878aSAndroid Build Coastguard Worker 61*61c4878aSAndroid Build Coastguard Worker``pw_boot_PreStaticMemoryInit()`` 62*61c4878aSAndroid Build Coastguard Worker--------------------------------- 63*61c4878aSAndroid Build Coastguard WorkerSignature: ``void pw_boot_PreStaticMemoryInit()`` 64*61c4878aSAndroid Build Coastguard Worker 65*61c4878aSAndroid Build Coastguard WorkerThis function executes just before static memory has been zeroed and static 66*61c4878aSAndroid Build Coastguard Workerdata is initialized. This function should set up any early initialization that 67*61c4878aSAndroid Build Coastguard Workershould be done before static memory is initialized, such as: 68*61c4878aSAndroid Build Coastguard Worker 69*61c4878aSAndroid Build Coastguard Worker- Enabling the FPU or other coprocessors. 70*61c4878aSAndroid Build Coastguard Worker- Opting into extra restrictions such as disabling unaligned access to ensure 71*61c4878aSAndroid Build Coastguard Worker the restrictions are active during static RAM initialization. 72*61c4878aSAndroid Build Coastguard Worker- Initial CPU clock, flash, and memory configurations including potentially 73*61c4878aSAndroid Build Coastguard Worker enabling extra memory regions with ``.bss`` and ``.data`` sections, such as 74*61c4878aSAndroid Build Coastguard Worker SDRAM or backup powered SRAM. 75*61c4878aSAndroid Build Coastguard Worker- Fault handler initialization if required before static memory 76*61c4878aSAndroid Build Coastguard Worker initialization. 77*61c4878aSAndroid Build Coastguard Worker 78*61c4878aSAndroid Build Coastguard Worker.. warning:: 79*61c4878aSAndroid Build Coastguard Worker 80*61c4878aSAndroid Build Coastguard Worker Code running in this hook is violating the C spec as static values are not 81*61c4878aSAndroid Build Coastguard Worker yet initialized, meaning they have not been loaded (``.data``) nor 82*61c4878aSAndroid Build Coastguard Worker zero-initialized (``.bss``). 83*61c4878aSAndroid Build Coastguard Worker 84*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-prestaticconstructorinit: 85*61c4878aSAndroid Build Coastguard Worker 86*61c4878aSAndroid Build Coastguard Worker``pw_boot_PreStaticConstructorInit()`` 87*61c4878aSAndroid Build Coastguard Worker-------------------------------------- 88*61c4878aSAndroid Build Coastguard WorkerSignature: ``void pw_boot_PreStaticConstructorInit()`` 89*61c4878aSAndroid Build Coastguard Worker 90*61c4878aSAndroid Build Coastguard WorkerThis function executes just before C++ static constructors are called. At this 91*61c4878aSAndroid Build Coastguard Workerpoint, other static memory has been zero-initialized or data-initialized. This 92*61c4878aSAndroid Build Coastguard Workerfunction should set up any early initialization that should be done before C++ 93*61c4878aSAndroid Build Coastguard Workerstatic constructors are run, such as: 94*61c4878aSAndroid Build Coastguard Worker 95*61c4878aSAndroid Build Coastguard Worker- Run time dependencies such as ``malloc``, and ergo sometimes the RTOS. 96*61c4878aSAndroid Build Coastguard Worker- Persistent memory that survives warm reboots. 97*61c4878aSAndroid Build Coastguard Worker- Enabling the MPU to catch ``nullptr`` dereferences during construction. 98*61c4878aSAndroid Build Coastguard Worker- Main stack watermarking. 99*61c4878aSAndroid Build Coastguard Worker- Further fault handling configuration necessary for your platform which 100*61c4878aSAndroid Build Coastguard Worker was not safe before ``pw_boot_PreStaticRamInit()``. 101*61c4878aSAndroid Build Coastguard Worker- Boot count and/or boot session UUID management. 102*61c4878aSAndroid Build Coastguard Worker 103*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-premaininit: 104*61c4878aSAndroid Build Coastguard Worker 105*61c4878aSAndroid Build Coastguard Worker``pw_boot_PreMainInit()`` 106*61c4878aSAndroid Build Coastguard Worker------------------------- 107*61c4878aSAndroid Build Coastguard WorkerSignature: ``void pw_boot_PreMainInit()`` 108*61c4878aSAndroid Build Coastguard Worker 109*61c4878aSAndroid Build Coastguard WorkerThis function executes just before ``main()``, and can be used for any device 110*61c4878aSAndroid Build Coastguard Workerinitialization that isn't application-specific. Depending on your platform, 111*61c4878aSAndroid Build Coastguard Workerthis might be turning on a UART, setting up default clocks, etc. 112*61c4878aSAndroid Build Coastguard Worker 113*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-main: 114*61c4878aSAndroid Build Coastguard Worker 115*61c4878aSAndroid Build Coastguard Worker``main()`` 116*61c4878aSAndroid Build Coastguard Worker---------- 117*61c4878aSAndroid Build Coastguard WorkerSignature: ``int main()`` 118*61c4878aSAndroid Build Coastguard Worker 119*61c4878aSAndroid Build Coastguard WorkerThis is where applications reside. 120*61c4878aSAndroid Build Coastguard Worker 121*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-postmain: 122*61c4878aSAndroid Build Coastguard Worker 123*61c4878aSAndroid Build Coastguard Worker``pw_boot_PostMain()`` 124*61c4878aSAndroid Build Coastguard Worker---------------------- 125*61c4878aSAndroid Build Coastguard WorkerSignature: ``PW_NO_RETURN void pw_boot_PostMain()`` 126*61c4878aSAndroid Build Coastguard Worker 127*61c4878aSAndroid Build Coastguard WorkerThis function executes after ``main()`` has returned. This could be used for 128*61c4878aSAndroid Build Coastguard Workerdevice-specific teardown such as an infinite loop, soft reset, or QEMU 129*61c4878aSAndroid Build Coastguard Workershutdown. In addition, if relevant for your application, this would be the 130*61c4878aSAndroid Build Coastguard Workerplace to invoke the global static destructors. This function must not return! 131*61c4878aSAndroid Build Coastguard Worker 132*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-backend: 133*61c4878aSAndroid Build Coastguard Worker 134*61c4878aSAndroid Build Coastguard Worker----------------------------- 135*61c4878aSAndroid Build Coastguard WorkerBackend-implemented functions 136*61c4878aSAndroid Build Coastguard Worker----------------------------- 137*61c4878aSAndroid Build Coastguard Worker``pw_boot`` :ref:`backends <docs-facades-definition>` must implement the 138*61c4878aSAndroid Build Coastguard Workerfollowing ``extern "C"`` functions. 139*61c4878aSAndroid Build Coastguard Worker 140*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-entry: 141*61c4878aSAndroid Build Coastguard Worker 142*61c4878aSAndroid Build Coastguard Worker``pw_boot_Entry()`` 143*61c4878aSAndroid Build Coastguard Worker------------------- 144*61c4878aSAndroid Build Coastguard WorkerSignature: ``void pw_boot_Entry()`` 145*61c4878aSAndroid Build Coastguard Worker 146*61c4878aSAndroid Build Coastguard WorkerThis function executes as the entry point for the application, and must 147*61c4878aSAndroid Build Coastguard Workercall the :ref:`module-pw_boot-user` in the correct 148*61c4878aSAndroid Build Coastguard Worker:ref:`module-pw_boot-sequence`. 149*61c4878aSAndroid Build Coastguard Worker 150*61c4878aSAndroid Build Coastguard Worker.. _module-pw_boot-dependencies: 151*61c4878aSAndroid Build Coastguard Worker 152*61c4878aSAndroid Build Coastguard Worker------------ 153*61c4878aSAndroid Build Coastguard WorkerDependencies 154*61c4878aSAndroid Build Coastguard Worker------------ 155*61c4878aSAndroid Build Coastguard Worker- :bdg-ref-primary-line:`module-pw_preprocessor` 156*61c4878aSAndroid Build Coastguard Worker 157*61c4878aSAndroid Build Coastguard Worker.. toctree:: 158*61c4878aSAndroid Build Coastguard Worker :hidden: 159*61c4878aSAndroid Build Coastguard Worker :maxdepth: 1 160*61c4878aSAndroid Build Coastguard Worker 161*61c4878aSAndroid Build Coastguard Worker Backends <backends> 162