ChorusOS 4.0 Porting Guide

Reboot Program Initialization

Example 4-1is the reboot program initialization source code provided in src/nucleus/bsp/powerpc/sbc8260/src/reboot/reboot.c.


Example 4-1 reboot_main

#define MAX_CHUNKS 16
#define STR_LENGTH 256

PrstChunk chunks[MAX_CHUNKS];
char chunk_id_buf[STR_LENGTH];

RebootDesc rebootDesc;
BootConfRebootEntry rebootEntry;

DbgOps_reset	resetOp;

BootParams bootParams;

    void
reboot_main(BootConf* conf, BootParams* bootp)
{
		if (conf->rebootDesc == 0) {
       /*
        * This is a cold reboot.
        */

       /*
        * Intialize printf()/scanf() support library
        */
       _stdc_consInit(conf->dbgOps.consRead, conf->dbgOps.consWrite);

       /*
        * Register hot reboot descriptor
        */
       rebootDesc.rebootOp = do_reboot;
       rebootDesc.hot.prstMem.numChunks = 0;
       rebootDesc.hot.prstMem.chunks = chunks;
       rebootDesc.hot.prstMem.maxChunks = MAX_CHUNKS;
       rebootDesc.hot.prstMem.curStrLen = 0;
       rebootDesc.hot.prstMem.maxStrLen = STR_LENGTH;
       rebootDesc.hot.prstMem.str = chunk_id_buf;

       conf->rebootDesc = &rebootdesc;

       /*
        * Save hot reboot entry point
        */
       rebootEntry = conf->rebootEntry;

       /*
        * Save reset entry point
        */
       resetOp = conf->dbgOps.reset;

       /*
        * Save bootparams
        */
       if (bootp) {
           bootParams = *bootp;
       }
		} else {
       /*
        * This is a hot reboot. 
        *
        * Nothing to do as the reboot program was intialized at the last cold 
        * reboot.
        */
		}
}

The reboot program is installed only once during a cold boot. For subsequent hot reboots, the reboot program maintains the section of the system state that must be kept. reboot_main() is the reboot program entry point and is called by the bootstrap program each time the system boots.

For a cold boot, when the rebootDesc field of the conf argument is NULL, the reboot program intializes its static data. Whereas for a hot boot the reboot program re-intialization is empty.

One purpose of the program is to maintain a stable system state during hot reboots. This state is represented by a generic HotRebootDesc structure (see "HotRebootDesc Structure") and a board specific BootParams structure (see "Bootstrap Program Implementation").

The bootstrap program exports the address of the reboot service routine, do_reboot(), in the rebootOp field of the rebootDesc structure. The microkernel jumps to this routine to proceed with any kind of reboot. See "HotRebootDesc Structure" for details.