Exemplo n.º 1
0
/// Write the marker that allows the firmware to boot.
/// \returns true iff successful
bool storage_protect_off(void)
{
    Allocation active;
    if (!find_active_storage(&active))
        return false;

    Allocation marker_sector = next_storage(active);
    flash_erase_word(marker_sector);
    bool ret = flash_write(marker_sector, 0, sizeof(STORAGE_PROTECT_OFF_MAGIC),
                           (const uint8_t *)STORAGE_PROTECT_OFF_MAGIC);
    return ret;
}
Exemplo n.º 2
0
/*
 * storage_init() - Validate storage content and copy data to shadow memory
 *
 * INPUT
 *     none
 * OUTPUT
 *     none
 */
void storage_init(void)
{
    ConfigFlash *stor_config;

    /* Find storage sector with valid data and set storage_location variable */
    if(find_active_storage(&storage_location))
    {
        stor_config = (ConfigFlash *)flash_write_helper(storage_location);
    }
    else
    {
        /* Set to storage sector1 as default if no sector has been initialized */
        storage_location = STORAGE_SECT_DEFAULT;
        stor_config = (ConfigFlash *)flash_write_helper(storage_location);
    }

    /* Reset shadow configuration in RAM */
    storage_reset();

    /* Verify storage partition is initialized */
    if(memcmp((void *)stor_config->meta.magic , STORAGE_MAGIC_STR,
              STORAGE_MAGIC_LEN) == 0)
    {
        /* Clear out stor_config before finding end config node */
        memcpy(shadow_config.meta.uuid, (void *)&stor_config->meta.uuid,
               sizeof(shadow_config.meta.uuid));
        data2hex(shadow_config.meta.uuid, sizeof(shadow_config.meta.uuid),
                 shadow_config.meta.uuid_str);

        if(stor_config->storage.version)
        {
            if(stor_config->storage.version <= STORAGE_VERSION)
            {
                storage_from_flash(stor_config);
            }
        }

        /* New app with storage version changed!  update the storage space */
        if(stor_config->storage.version != STORAGE_VERSION)
        {
            storage_commit();
        }
    }
    else
    {
        /* Keep storage area cleared */
        storage_reset_uuid();
        storage_commit();
    }
}
Exemplo n.º 3
0
uint32_t storage_protect_status(void)
{
    Allocation active;
    if (!find_active_storage(&active))
        return STORAGE_PROTECT_DISABLED;

    Allocation marker_sector = next_storage(active);

    const char *start = sector_start(marker_sector);
    if (!start)
        return STORAGE_PROTECT_ENABLED;

    return memcmp(STORAGE_PROTECT_OFF_MAGIC, start, sizeof(STORAGE_PROTECT_OFF_MAGIC))
                  ? STORAGE_PROTECT_ENABLED : STORAGE_PROTECT_DISABLED;
}
Exemplo n.º 4
0
/// Clear the marker that allows the firmware to boot.
/// \returns true iff successful
bool storage_protect_on(void)
{
    _Static_assert(sizeof(STORAGE_PROTECT_ON_MAGIC) == sizeof(STORAGE_PROTECT_OFF_MAGIC),
                   "Storage protection markers must be the same length");

    Allocation active;
    if (!find_active_storage(&active))
        return false;

    Allocation marker_sector = next_storage(active);
    flash_erase_word(marker_sector);
    bool ret = flash_write(marker_sector, 0, sizeof(STORAGE_PROTECT_ON_MAGIC),
                           (const uint8_t*)STORAGE_PROTECT_ON_MAGIC);
    return ret;
}