In this blog, the eBoot menu is modified to to allow user selection of Clearing of the Hive or not. This is implemented by adding a further parameter to the BOOT_CG and BSP_ARGS structures to handle the boolean selection. The eBoot code is then extended to pass the selection up to the OS args driver. The OS args driver then is modified to get the value when requested by getting it from the structure passed to it through shared memory. This replaces the use of the dummy variable s_bClearHive  as used in args.c in the previous blog.

Context: This discussion is with respect to the Texas Instruments AM335X MPU as used with BeagleBone Black (BBB) and the Variscite VAR-SOM-AM33. This material was developed mainly with the latter but the BBB was also used in parts.

Previous Blog: TI AM335X Windows Embedded Compact Bootloader Args and Clearing Hive Registry


Add an Arg to the Configuration

1. Add an arg to be passed between eboot and the OS, and stored in flash when configuration is saved.

in boot_args.h at the bottom of BOOT_CFG structure add the bClearHive entry:   


    UCHAR ECCtype;
    UINT32 opp_mode;
    UINT16 bClearHive;
} BOOT_CFG;

2. Similarly in BSP_ARGS structure in args.h insert the bCrearHive entry   


     UINT32 ECCtype;
    UINT32 opp_mode;
    UINT16 bClearHive;
    UINT32 RamSize;
   
Note that both structures are similar. The args.h version has more fields.  boot_args.h is used by OSU/OSUpdate….more in a subsequent blog
The args.h version is what is used by args.c which is what we need here.

eBoot Menu Code Changes

Adding two items to main menu. Could do a submenu .. ToDo

  • Keep Hive
  • Clear Hive

In menu.c:
3. List the functions that implement the code for for each new menu item. Add the highlighted change:


static VOID SetMacAddress(OAL_BLMENU_ITEM *pMenu);
static VOID ShowSettings(OAL_BLMENU_ITEM *pMenu);
static VOID ShowNetworkSettings(OAL_BLMENU_ITEM *pMenu);
static VOID SetKitlMode(OAL_BLMENU_ITEM *pMenu);
static VOID SetKitlType(OAL_BLMENU_ITEM *pMenu);
static VOID SetDeviceID(OAL_BLMENU_ITEM *pMenu);
static VOID SaveSettings(OAL_BLMENU_ITEM *pMenu);
static VOID SetRetailMsgMode(OAL_BLMENU_ITEM *pMenu);
static VOID SetDisplayResolution(OAL_BLMENU_ITEM *pMenu);
static VOID SetOPPmode(OAL_BLMENU_ITEM *pMenu);
#ifdef DYNAMIC_OS_BOOT
static     VOID SetBootPart(OAL_BLMENU_ITEM *pMenu);
#endif // DYNAMIC_OS_BOOT

//Added DJ 29/05/15:
static VOID SetClearHive(OAL_BLMENU_ITEM *pMenu);
static VOID UnSetClearHive(OAL_BLMENU_ITEM *pMenu);


In menu.c
4. Add the menu items.  There are two menus. One for Nand and one for SD boots:


#if BUILDING_EBOOT_SD
static OAL_BLMENU_ITEM g_menuMain = {
    {L'1', L"Show Current Settings", ShowSettings,NULL, NULL, NULL},
    {L'2', L"Select Boot Device", OALBLMenuSelectDevice,L"Boot", &g_bootCfg.bootDevLoc, g_bootDevices},
    {L'3', L"Select KITL (Debug) Device", OALBLMenuSelectDevice, L"Debug", &g_bootCfg.kitlDevLoc, g_kitlDevices},
    {L'4', L"Network Settings", OALBLMenuShow,L"Network Settings", &g_menuNetwork, NULL},
    {L'5', L"SDCard Settings", OALBLMenuShow,L"SDCard Settings", &g_menuSDCard, NULL},
    {L'6', L"Set Device ID", SetDeviceID,NULL, NULL, NULL},
    {L'7', L"Save Settings", SaveSettings,NULL, NULL, NULL},
    {L'8', L"Flash Management", OALBLMenuShow,L"Flash Management", &g_menuFlash, NULL},
    {L'9', L"Enable/Disable OAL Retail Messages", SetRetailMsgMode,NULL, NULL, NULL},
#ifdef DYNAMIC_OS_BOOT
    {L'a', L"Set NK Boot Partition", SetBootPart, NULL, NULL, NULL},
#endif // DYNAMIC_OS_BOOT

//    {L'a', L"Select Display Resolution", SetDisplayResolution,NULL, NULL, NULL},   
    {L'b', L"Select OPP Mode", SetOPPmode,NULL, NULL, NULL},
    {L'h', L"HIVE -- Keep Hive (Default)", UnSetClearHive,NULL, NULL, NULL},
    {L'H', L"     -- Clear Hive", SetClearHive,NULL, NULL, NULL},

    {L'0', L"Exit and Continue", NULL,NULL, NULL, NULL},
    {0, NULL, NULL,NULL, NULL, NULL}
};
#else
static OAL_BLMENU_ITEM g_menuMain = {
    {L'1', L"Show Current Settings", ShowSettings,NULL, NULL, NULL},
    {L'2', L"Select Boot Device", OALBLMenuSelectDevice,L"Boot", &g_bootCfg.bootDevLoc, g_bootDevices},
    {L'3', L"Select KITL (Debug) Device", OALBLMenuSelectDevice,L"Debug", &g_bootCfg.kitlDevLoc, g_kitlDevices},
    {L'4', L"Network Settings", OALBLMenuShow,L"Network Settings", &g_menuNetwork, NULL},
    //{L'5', L"Flash Management", OALBLMenuShow,L"Flash Management", &g_menuFlash, NULL},
    {L'6', L"Set Device ID", SetDeviceID,NULL, NULL, NULL},
    {L'7', L"Save Settings", SaveSettings,NULL, NULL, NULL},
    {L'8', L"Flash Management", OALBLMenuShow,L"Flash Management", &g_menuFlash, NULL},
    {L'9', L"Enable/Disable OAL Retail Messages", SetRetailMsgMode,NULL, NULL, NULL},
#ifdef DYNAMIC_OS_BOOT
    {L'a', L"Set NK Boot Partition", SetBootPart, NULL, NULL, NULL},
#endif // DYNAMIC_OS_BOOT
//    {L'a', L"Select Display Resolution", SetDisplayResolution,NULL, NULL, NULL},
    {L'b', L"Select OPP Mode", SetOPPmode,NULL, NULL, NULL},
    {L'h', L"HIVE -- Keep Hive (Default)", UnSetClearHive,NULL, NULL, NULL},
    {L'H', L"     -- Clear Hive", SetClearHive,NULL, NULL, NULL},

    {L'0', L"Exit and Continue", NULL,NULL, NULL, NULL},
    {0, NULL, NULL,NULL, NULL, NULL}
};
#endif


Still in menu.c
5. Implement the functions

I placed them just before:
#ifdef DYNAMIC_OS_BOOT
VOID SetBootPart(OAL_BLMENU_ITEM *pMenu)


//Added DJ 29/05/15
VOID SetClearHive(OAL_BLMENU_ITEM *pMenu)
{
    g_bootCfg.bClearHive=TRUE;
}

VOID UnSetClearHive(OAL_BLMENU_ITEM *pMenu)
{
    g_bootCfg.bClearHive=FALSE;
}


 

The Updated eBoot Menu:


[1] Show Current Settings
[2] Select Boot Device
[3] Select KITL (Debug) Device
[4] Network Settings
[6] Set Device ID
[7] Save Settings
[8] Flash Management
[9] Enable/Disable OAL Retail Messages
[a] Set NK Boot Partition
[b] Select OPP Mode
[h] HIVE -- Keep Hive (Default)
[H]      -- Clear Hive

[0] Exit and Continue


eBoot Main Code


In main.c in OEMPreDownload()
6. Add a default setting for this when no boot config is found by eBoot: 


        g_bootCfg.oalFlags = 0;
        g_bootCfg.flashNKFlags = 0;

        //Added DJ 29/05/15
        g_bootCfg.bClearHive=0;

        g_bootCfg.ECCtype =  (UCHAR)dwEbootECCtype


Also in main.c in OEMPreDownload()

pArgs is what gets passed form eBoot to the OS.

7. Insert the following as highlighted: 


 

        pArgs->oalFlags = g_bootCfg.oalFlags;
        pArgs->dispRes = g_bootCfg.displayRes;
        pArgs->ECCtype = g_bootCfg.ECCtype;
        pArgs->opp_mode = g_bootCfg.opp_mode;
        //DJ 29/05/15
        pArgs->bClearHive = g_bootCfg.bClearHive;
        memcpy(pArgs->DevicePrefix, gDevice_prefix, sizeof(pArgs->DevicePrefix));
        // should we check the size
        /* unset the cfg save flag in bootCfg; pArgs now contains the correct value for this flag*/
        g_bootCfg.oalFlags &= ~BOOT_CFG_OAL_FLAGS_CFG_SAVE;
        memcpy(pArgs->ebootCfg,&g_bootCfg,sizeof(BOOT_CFG));
        pArgs->cfgSize = sizeof(BOOT_CFG);


OS Args Code

Now change the OAL_ARGS_QUERY_CLEAR_HIVE:case to:


case OAL_ARGS_QUERY_CLEAR_HIVE:
    //pData = (VOID *) &s_bClearHive;
    pData = &pArgs->bClearHive;
    break;

8. Build and test he functionality. You will need to install the new eBoot (build as Release no KITL etc) on the target. Run the OS as Debug download so as to observe the messages. test by having an an that write to registry a value that it has just read and incremented.



NB: When "experimenting with this, you might get an error when boot with keep the current hive setting such as :

10814 PID:400002 TID:5a0002 ERROR: d:\bt\2034\private\winceos\coreos\filesys\heap\volume.c line 686: 
10815 PID:400002 TID:5a0002 FSVOL: Aborting init on non-registry hive"


I deduced that this is with a new system. Although its not the first boot, the previous boot was shutdown before any registry was flushed and hence tring to load one leads to an error. A proper shutdown (eg Soft reboot, programmatic reboot etc) or allowing time for an auto-flush should resolve this.

Also, when an new OS is booted you get:

10922 PID:400002 TID:5a0002 FSREG: Existing hive was created with a different ROM, discarding
10941 PID:400002 TID:5a0002 FSREG: Mounting clean system hive