コード例 #1
0
ファイル: split.c プロジェクト: bgiori/incubator-mynewt-core
/**
 * This validates and provides the loader image data
 *
 * @return                      0 on success; nonzero on failure.
 */
int
split_app_go(void **entry, int toboot)
{
    split_mode_t split_mode;
    int run_app;
    int rc;

    if (toboot) {
        split_mode = split_mode_get();

        /* if we are told not to, then we don't boot an app */
        if (split_mode == SPLIT_MODE_LOADER) {
            return -1;
        }

        /* if this is a one-time test, reset the split mode */
        switch (split_mode) {
        case SPLIT_MODE_LOADER:
            run_app = 0;
            break;

        case SPLIT_MODE_TEST_APP:
            split_write_split(SPLIT_MODE_LOADER);
            run_app = 1;
            break;

        case SPLIT_MODE_TEST_LOADER:
            split_write_split(SPLIT_MODE_APP);
            run_app = 0;
            break;

        case SPLIT_MODE_APP:
            run_app = 1;
            break;

        default:
            run_app = 0;
            break;
        }

        if (!run_app) {
            return -1;
        }
    }

    rc = split_go(LOADER_IMAGE_SLOT, SPLIT_IMAGE_SLOT, entry);
    if (rc != 0) {
        /* Images don't match; clear split status. */
        split_write_split(SPLIT_MODE_LOADER);
    }

    return rc;
}
コード例 #2
0
uint8_t
imgmgr_state_flags(int query_slot)
{
    split_mode_t split_mode;
    uint8_t flags;
    int swap_type;

    assert(query_slot == 0 || query_slot == 1);

    flags = 0;

    /* Determine if this is is pending or confirmed (only applicable for
     * unified images and loaders.
     */
    swap_type = boot_swap_type();
    switch (swap_type) {
    case BOOT_SWAP_TYPE_NONE:
        if (query_slot == 0) {
            flags |= IMGMGR_STATE_F_CONFIRMED;
            flags |= IMGMGR_STATE_F_ACTIVE;
        }
        break;

    case BOOT_SWAP_TYPE_TEST:
        if (query_slot == 0) {
            flags |= IMGMGR_STATE_F_CONFIRMED;
        } else if (query_slot == 1) {
            flags |= IMGMGR_STATE_F_PENDING;
        }
        break;

    case BOOT_SWAP_TYPE_REVERT:
        if (query_slot == 0) {
            flags |= IMGMGR_STATE_F_ACTIVE;
        } else if (query_slot == 1) {
            flags |= IMGMGR_STATE_F_CONFIRMED;
        }
        break;
    }

    /* Slot 0 is always active.  Slot 1 is also active if a split app is
     * currently running.
     */
    /* XXX: The slot 0 assumption only holds when running from flash. */
    if (query_slot == 0 || split_app_active_get()) {
        flags |= IMGMGR_STATE_F_ACTIVE;
    }

    /* Read the split/status config state to determine any pending split-image
     * state changes.
     */
    split_mode = split_mode_get();
    switch (split_mode) {
    case SPLIT_MODE_LOADER:
        break;

    case SPLIT_MODE_APP:
        if (query_slot == 1) {
            flags |= IMGMGR_STATE_F_CONFIRMED;
        }
        break;

    case SPLIT_MODE_TEST_LOADER:
        if (query_slot == 0) {
            flags |= IMGMGR_STATE_F_PENDING;
        }
        break;

    case SPLIT_MODE_TEST_APP:
        if (query_slot == 1) {
            flags |= IMGMGR_STATE_F_PENDING;
        }
        break;

    default:
        assert(0);
        break;
    }

    return flags;
}