0

I am working on uboot v2018.07 on beagleboneblack. For my implementation, I have to read boot device on startup as it can be booted from emmc or sd card. While loading the environment in env_load(void) method defined here, I have added a few lines after the environment successfully loads:

int env_load(void)
{
struct env_driver *drv;
int prio, err;
const char *bootdevice;

for (prio = 0; (drv = env_driver_lookup(ENVOP_LOAD, prio)); prio++) {
    int ret;

    if (!drv->load)
        continue;

    if (!env_has_inited(drv->location))
        continue;

    printf("Loading Environment from %s... ", drv->name);

    ret = drv->load();
    if (ret)
        printf("Failed (%d)\n", ret);
    else
    {
        printf("OK\n");
        //my code from here
        printf("Loading environment from mmc-device %d\n", gd->arch.omap_boot_device);
        if(gd->arch.omap_boot_device==9) {
            err = env_set("boot_device", "emmc");
        }
        else {
            err = env_set("boot_device", "sd");
        }

        if (!err) {
#ifdef CONFIG_SPL_SAVEENV
        printf("Saving boot env %d\n", err);
        env_save();
#endif
        }
   //till here
    }

if (!ret)
    return 0;
    
}
return -ENODEV;
}

This reads the boot_device and sets it in a environment variable. The environment seems to successfully load from the mmc and I can set the environment as well but it cannot save the environment. On calling env_save(), it goes on a continuous loop as it tries to save the env but cannot. The bootdevice is read from the SPL loader. Is it possible to achieve something like this, setting and saving the environment from SPL. Write now, what I am doing is hardcoding the bootdevice number in this variable

MENDER_STORAGE_DEVICE_BASE = "/dev/mmcblk1p" (0 if sd card)

so, now I have different images for sd card and emmc. If I can set and save the environment in this way, then would not need to hardcode this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.