diff --git a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c index afa3e6e..096c47c 100644 --- a/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c +++ b/cmd/img_mgmt/port/zephyr/src/zephyr_img_mgmt.c @@ -131,20 +131,29 @@ zephyr_img_mgmt_flash_area_id(int slot) } /** - * The function will check if given slot is available, and allowed, for DFU; - * providing -1 as a parameter means find any unused and non-active available; - * if checks area positive, then area ID is returned, -1 is returned otherwise. - * Note that auto-selection is performed only between two first slots. + * In normal operation this function will select between first two slot + * (in reality it just checks whether second slot can be used), ignoring the + * slot parameter. + * When CONFIG_IMG_MGMT_DIRECT_IMAGE_UPLOAD is defined it will check if given + * slot is available, and allowed, for DFU; providing 0 as a parameter means + * find any unused and non-active available (auto-select); any other positive + * value is direct (slot + 1) to be used; if checks are positive, then area + * ID is returned, -1 is returned otherwise. + * Note that auto-selection is performed only between two two first slots. */ static int img_mgmt_get_unused_slot_area_id(int slot) { - /* Auto select slot; note that this is performed only between two first - * slots, at this pointi, which will require fix when Direct-XIP, which may - * support more slots, gets support within Zephyr. */ +#if defined(CONFIG_IMG_MGMT_DIRECT_IMAGE_UPLOAD) + slot--; if (slot < -1) { return -1; } else if (slot == -1) { +#endif + /* Auto select slot; note that this is performed only between two first + * slots, at this point, which will require fix when Direct-XIP, which + * may support more slots, gets support within Zephyr. + */ for (slot = 0; slot < 2; slot++) { if (img_mgmt_slot_in_use(slot) == 0) { int area_id = zephyr_img_mgmt_flash_area_id(slot); @@ -154,6 +163,7 @@ img_mgmt_get_unused_slot_area_id(int slot) } } return -1; +#if defined(CONFIG_IMG_MGMT_DIRECT_IMAGE_UPLOAD) } /* Direct selection; the first two slots are checked for being available * and unused; the all other slots are just checked for availability. */ @@ -163,6 +173,7 @@ img_mgmt_get_unused_slot_area_id(int slot) /* Return area ID for the slot or -1 */ return slot != -1 ? zephyr_img_mgmt_flash_area_id(slot) : -1; +#endif } /** @@ -505,7 +516,7 @@ img_mgmt_impl_upload_inspect(const struct img_mgmt_upload_req *req, } } - action->area_id = img_mgmt_get_unused_slot_area_id(req->image - 1); + action->area_id = img_mgmt_get_unused_slot_area_id(req->image); if (action->area_id < 0) { /* No slot where to upload! */ *errstr = img_mgmt_err_str_no_slot; diff --git a/transport/smp-console.md b/transport/smp-console.md index d9804f9..0b12f3c 100644 --- a/transport/smp-console.md +++ b/transport/smp-console.md @@ -39,7 +39,7 @@ below: | ----- | ----------- | | 0x06 0x09 | Byte pair indicating the start of a packet. | | 0x04 0x14 | Byte pair indicating the start of a continuation frame. | -| Packet length | The combined total length of the *unencoded* body. | +| Packet length | The combined total length of the *unencoded* body plus the final CRC (2 bytes). Length is in Big-Endian format. | | Body | The actual SMP data (i.e., 8-byte header and CBOR key-value map). | | CRC16 | A CRC16 of the *unencoded* body of the entire packet. This field is only present in the final frame of a packet. | | Newline | A 0x0a byte; terminates a frame. |