snapshot: Update mcumgr to commit 4fa869142f from upstream

The commit applies changes that have appeared between the last snapshot
update from the upstream:
  apache/mynewt-mcumgr 64f5060bd8bb466367e0da94da8b425d5b9f6388
and the current top of the upstream:
  apache/mynewt-mcumgr 4fa869142f16e00d42415bc6dbcb7f1f92ba4abd

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
Dominik Ermel 2021-07-22 12:15:17 +00:00 committed by Carles Cufí
parent 5c5055f5a7
commit a15a953e35
5 changed files with 77 additions and 48 deletions

View File

@ -74,6 +74,7 @@ extern struct img_mgmt_state g_img_mgmt_state;
/** Represents an individual upload request. */
struct img_mgmt_upload_req {
unsigned long long int image; /* 0 by default */
unsigned long long int off; /* -1 if unspecified */
unsigned long long int size; /* -1 if unspecified */
size_t data_len;

View File

@ -91,9 +91,12 @@ zephyr_img_mgmt_flash_check_empty(uint8_t fa_id, bool *out_empty)
}
/**
* Get flash_area ID for a image slot number.
* Get flash_area ID for a image number; actually the slots are images
* for Zephyr, as slot 0 of image 0 is image_0, slot 0 of image 1 is
* image_2 and so on. The function treats slot numbers as absolute
* slot number starting at 0.
*/
static uint8_t
static int
zephyr_img_mgmt_flash_area_id(int slot)
{
uint8_t fa_id;
@ -107,49 +110,59 @@ zephyr_img_mgmt_flash_area_id(int slot)
fa_id = FLASH_AREA_ID(image_1);
break;
#if FLASH_AREA_LABEL_EXISTS(image_2)
case 2:
fa_id = FLASH_AREA_ID(image_2);
break;
#endif
#if FLASH_AREA_LABEL_EXISTS(image_3)
case 3:
fa_id = FLASH_AREA_ID(image_3);
break;
#endif
default:
assert(0);
fa_id = FLASH_AREA_ID(image_1);
fa_id = -1;
break;
}
return fa_id;
}
/**
* 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.
*/
static int
img_mgmt_find_best_area_id(void)
img_mgmt_get_unused_slot_area_id(int slot)
{
struct image_version ver;
int best = -1;
int i;
int rc;
for (i = 0; i < 2; i++) {
rc = img_mgmt_read_info(i, &ver, NULL, NULL);
if (rc < 0) {
continue;
}
if (rc == 0) {
/* Image in slot is ok. */
if (img_mgmt_slot_in_use(i)) {
/* Slot is in use; can't use this. */
continue;
} else {
/*
* Not active slot, but image is ok. Use it if there are
* no better candidates.
*/
best = i;
/* 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 (slot < -1) {
return -1;
} else if (slot == -1) {
for (slot = 0; slot < 2; slot++) {
if (img_mgmt_slot_in_use(slot) == 0) {
int area_id = zephyr_img_mgmt_flash_area_id(slot);
if (area_id != -1) {
return area_id;
}
}
continue;
}
best = i;
break;
return -1;
}
if (best >= 0) {
best = zephyr_img_mgmt_flash_area_id(best);
/* Direct selection; the first two slots are checked for being available
* and unused; the all other slots are just checked for availability. */
if (slot < 2) {
slot = img_mgmt_slot_in_use(slot) == 0 ? slot : -1;
}
return best;
/* Return area ID for the slot or -1 */
return slot != -1 ? zephyr_img_mgmt_flash_area_id(slot) : -1;
}
/**
@ -192,11 +205,13 @@ int
img_mgmt_impl_erase_slot(void)
{
bool empty;
int rc;
/* Select non-active slot */
const int best_id = img_mgmt_find_best_area_id();
int rc, best_id;
/* Select any non-active, unused slot */
best_id = img_mgmt_get_unused_slot_area_id(-1);
if (best_id < 0) {
return MGMT_ERR_EUNKNOWN;
}
rc = zephyr_img_mgmt_flash_check_empty(best_id, &empty);
if (rc != 0) {
return MGMT_ERR_EUNKNOWN;
@ -292,7 +307,7 @@ img_mgmt_impl_write_image_data(unsigned int offset, const void *data,
}
}
#endif
rc = flash_img_init_id(ctx, img_mgmt_find_best_area_id());
rc = flash_img_init_id(ctx, g_img_mgmt_state.area_id);
if (rc != 0) {
return MGMT_ERR_EUNKNOWN;
@ -330,7 +345,7 @@ img_mgmt_impl_erase_image_data(unsigned int off, unsigned int num_bytes)
goto end;
}
rc = flash_area_open(img_mgmt_find_best_area_id(), &fa);
rc = flash_area_open(g_img_mgmt_state.area_id, &fa);
if (rc != 0) {
LOG_ERR("Can't bind to the flash area (err %d)", rc);
rc = MGMT_ERR_EUNKNOWN;
@ -490,7 +505,7 @@ img_mgmt_impl_upload_inspect(const struct img_mgmt_upload_req *req,
}
}
action->area_id = img_mgmt_find_best_area_id();
action->area_id = img_mgmt_get_unused_slot_area_id(req->image - 1);
if (action->area_id < 0) {
/* No slot where to upload! */
*errstr = img_mgmt_err_str_no_slot;

View File

@ -314,6 +314,10 @@ img_mgmt_erase(struct mgmt_ctxt *ctxt)
rc = img_mgmt_impl_erase_slot();
if (!rc) {
img_mgmt_dfu_stopped();
}
err = 0;
err |= cbor_encode_text_stringz(&ctxt->encoder, "rc");
err |= cbor_encode_int(&ctxt->encoder, rc);
@ -394,42 +398,49 @@ img_mgmt_upload(struct mgmt_ctxt *ctxt)
.data_len = 0,
.data_sha_len = 0,
.upgrade = false,
.image = 0,
};
const struct cbor_attr_t off_attr[] = {
[0] = {
.attribute = "image",
.type = CborAttrUnsignedIntegerType,
.addr.uinteger = &req.image,
.nodefault = true
},
[1] = {
.attribute = "data",
.type = CborAttrByteStringType,
.addr.bytestring.data = req.img_data,
.addr.bytestring.len = &req.data_len,
.len = sizeof(req.img_data)
},
[1] = {
[2] = {
.attribute = "len",
.type = CborAttrUnsignedIntegerType,
.addr.uinteger = &req.size,
.nodefault = true
},
[2] = {
[3] = {
.attribute = "off",
.type = CborAttrUnsignedIntegerType,
.addr.uinteger = &req.off,
.nodefault = true
},
[3] = {
[4] = {
.attribute = "sha",
.type = CborAttrByteStringType,
.addr.bytestring.data = req.data_sha,
.addr.bytestring.len = &req.data_sha_len,
.len = sizeof(req.data_sha)
},
[4] = {
[5] = {
.attribute = "upgrade",
.type = CborAttrBooleanType,
.addr.boolean = &req.upgrade,
.dflt.boolean = false,
},
[5] = { 0 },
[6] = { 0 },
};
int rc;
const char *errstr = NULL;

View File

@ -2,13 +2,14 @@
CONFIG_MCUMGR=y
# Some command handlers require a large stack.
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
# Ensure an MCUboot-compatible binary is generated.
CONFIG_BOOTLOADER_MCUBOOT=y
# Allow for large Bluetooth data packets.
CONFIG_BT_L2CAP_TX_MTU=260
CONFIG_BT_L2CAP_TX_MTU=252
CONFIG_BT_L2CAP_RX_MTU=252
CONFIG_BT_RX_BUF_LEN=260
# Enable the Bluetooth (unauthenticated) and shell mcumgr transports.

View File

@ -6,13 +6,14 @@
CONFIG_MCUMGR=y
# Some command handlers require a large stack.
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
# Ensure an MCUboot-compatible binary is generated.
CONFIG_BOOTLOADER_MCUBOOT=y
# Allow for large Bluetooth data packets.
CONFIG_BT_L2CAP_TX_MTU=260
CONFIG_BT_L2CAP_TX_MTU=252
CONFIG_BT_L2CAP_RX_MTU=252
CONFIG_BT_RX_BUF_LEN=260
# Enable the Bluetooth (unauthenticated) and UART mcumgr transports.