erase netcore update image

I’m using SMP over UART to send the erase command ({"slot": 1}), and it only erases the application core image (image 0). I also have a network core image (image 1) present in slot 1, but it is not erased by this command.


How can I erase the netcore image too?

Do I need to include the "image": 1 key in the CBOR payload? Or is there another way to target both images?



  • Hello shlomots,

    Yes, you need to specify image ID.

    Hieu

  • thanks for the response,

    I tried that:

    zcbor_new_encode_state(zse, ARRAY_SIZE(zse), smp_cmd.payload,
    sizeof(smp_cmd.payload), 0);

    /* Stop encoding on the error. */
    zse->constant_state->stop_on_error = true;

    zcbor_map_start_encode(zse, 3);
    zcbor_tstr_put_lit(zse, "slot");
    zcbor_uint32_put(zse, slot);
    zcbor_tstr_put_lit(zse, "image");
    zcbor_uint32_put(zse, 1);
    zcbor_map_end_encode(zse, 3);

    if (!zcbor_check_error(zse)) {
    LOG_ERR("Failed to encode SMP erase packet, err: %d", zcbor_pop_error(zse));
    return -EFAULT;
    }


    but it doesnt work.

  • Could you please give more details? What is your setup like? What are you doing? How exactly does it not work?

  • I implented a srv_client with similer logic to this sample. 

    github.com/.../smp_client_ble

    I need the smp_client to run on my board.

    my setup is similer to this sample.
    ncs 2.7.0 on toolchain as well.

    it doesnt work by erasing only the first image in the slot and not the second one, even though I have given it the right image index as you can see in the previous message.

    as you can see in the source code, the command are implemnted there, the list command, the echo command.
    I want to implement the erase command as well. 

    I also found the erase handler in the smp_server
    and I dont see any support for an image index:


    /**
    * Command handler: image erase
    */
    static int
    img_mgmt_erase(struct smp_streamer *ctxt)
    {
    struct image_version ver;
    int rc;
    zcbor_state_t *zse = ctxt->writer->zs;
    zcbor_state_t *zsd = ctxt->reader->zs;
    bool ok;
    uint32_t slot = img_mgmt_get_opposite_slot(img_mgmt_active_slot(img_mgmt_active_image()));
    size_t decoded = 0;

    struct zcbor_map_decode_key_val image_erase_decode[] = {
    ZCBOR_MAP_DECODE_KEY_DECODER("slot", zcbor_uint32_decode, &slot),
    };

    ok = zcbor_map_decode_bulk(zsd, image_erase_decode,
    ARRAY_SIZE(image_erase_decode), &decoded) == 0;

    if (!ok) {
    return MGMT_ERR_EINVAL;
    }

    img_mgmt_take_lock();

    /*
    * First check if image info is valid.
    * This check is done incase the flash area has a corrupted image.
    */
    rc = img_mgmt_read_info(slot, &ver, NULL, NULL);

    if (rc == 0) {
    /* Image info is valid. */
    if (img_mgmt_slot_in_use(slot)) {
    /* No free slot. */
    ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE,
    IMG_MGMT_ERR_NO_FREE_SLOT);
    goto end;
    }
    }

    rc = img_mgmt_erase_slot(slot);
    img_mgmt_reset_upload();

    if (rc != 0) {
    #if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
    int32_t err_rc;
    uint16_t err_group;

    (void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED, NULL, 0, &err_rc,
    &err_group);
    #endif
    ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE, rc);
    goto end;
    }

    if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR)) {
    if (!zcbor_tstr_put_lit(zse, "rc") || !zcbor_int32_put(zse, 0)) {
    img_mgmt_release_lock();
    return MGMT_ERR_EMSGSIZE;
    }
    }

    end:
    img_mgmt_release_lock();

    return MGMT_ERR_EOK;
    }




Related