ChorusOS 4.0 Porting Guide

bconf_main.c Source File

The kernel/snippet/nucleus/boot_tools/bconf_main.c file contains the bootconf main routine, bconf_main().


Example 3-3 bconf_main()

BootConfRebootEntry __mkimage__label__REF_reboot = 0;

    void
bconf_main(void* cookie)
{
    int i;

    /*
     * Register hot reboot entry
     */
    bootConf->rebootEntry = __mkimage__label__REF_reboot;

    /*
     * Install all standalone sections
     */
    binInstallByMask(BIN_STANDALONE);

    /*
     * Launch bootstrap program
     */
    for (i = 0; i < bootConf->numBins; ++i) {
        BinDesc* bin = &bootConf->binDesc[i];
        if (bin->type == BIN_BOOTSTRAP) {
            (* (BootstrapEntry) bin->entry)(bootConf, cookie);
        }
    }
}

First of all, the bconf_main() routine registers the bootconf hot reboot entry point in the bootConf structure. Note that the registered address must be a reference to the bootconf image. This address can be different from the entry point's link-edit address if the bootconf text segment is not XIP. To provide the reference, the mkimage tool stores the system image address of the location __mkimage__label__rebootin the data location __mkimage__label__REF_reboot.

The bconf_main() routine calls binInstallByMask() to copy (if necessary), the read-write segments of all standalone binaries and to zero their bss. Calling binInstallByMask() at this point, bconf_main() assumes that any memory banks containing standalone binaries have already been installed at the required address. See "binInstallByMask and binInstallByType()" for more information.

The binInstallByMask() function is implemented by the bootstrap framework library (see "Common Bootstrap Implementation Framework").

Finally, the bconf_main() function retrieves the descriptor pointing to the bootstrap program binary in the bootConf structure, and jumps to its entry point. It passes as arguments the address of the bootConf structure and an opaque value from the initial loader.

The kernel/snippet/nucleus/boot_tools/bconf_main.c file also contains the second main routine, bconf_reboot_main(), which is used for performing a hot reboot:


Example 3-4 bconf_reboot_main()

     
    void 
bconf_reboot_main(RebootDesc* rd, void* cookie)
{
		if (rd) {
			/*
			 * Restore the pointer to the persistent memory description
			 */
      bootConf->rebootDesc = rd;
		}

			/*
		 	 * Join the cold bootstrap path
		 	*/
		bconf_main(cookie);
}

bconf_reboot_main() registers a reference to the system state, preserved by the hot reboot (see "Hot Reboot" for details) in the bootConf structure, and then joins the cold reboot pass.