Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport v3.5-branch] mgmt: updatehub: Fix mark for update #72401

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions subsys/mgmt/updatehub/updatehub.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,19 +847,31 @@ enum updatehub_response z_impl_updatehub_probe(void)
recv_probe_sh_string_descr,
ARRAY_SIZE(recv_probe_sh_string_descr),
&metadata_any_boards) < 0) {
LOG_ERR("Could not parse json");
LOG_ERR("Could not parse the json");
ctx.code_status = UPDATEHUB_METADATA_ERROR;
goto cleanup;
}

LOG_DBG("elements: %d", metadata_any_boards.objects_len);
for (size_t i = 0; i < metadata_any_boards.objects_len; ++i) {
LOG_DBG("obj[%d].elements: %d",
i, metadata_any_boards.objects[i].objects_len);
for (size_t j = 0; j < metadata_any_boards.objects[i].objects_len; ++j) {
struct resp_probe_objects *obj =
&metadata_any_boards.objects[i].objects[j].objects;
LOG_DBG("\tMode: %s\n\tSHA: %s\n\tSize: %d",
obj->mode, obj->sha256sum, obj->size);
}
}

if (metadata_any_boards.objects_len != 2) {
LOG_ERR("Could not parse json");
LOG_ERR("Object length of type 'any metadata' is incorrect");
ctx.code_status = UPDATEHUB_METADATA_ERROR;
goto cleanup;
}

sha256size = strlen(
metadata_any_boards.objects[1].objects.sha256sum) + 1;
metadata_any_boards.objects[1].objects[0].objects.sha256sum) + 1;

if (sha256size != SHA256_HEX_DIGEST_SIZE) {
LOG_ERR("SHA256 size is invalid");
Expand All @@ -868,14 +880,26 @@ enum updatehub_response z_impl_updatehub_probe(void)
}

memcpy(update_info.sha256sum_image,
metadata_any_boards.objects[1].objects.sha256sum,
metadata_any_boards.objects[1].objects[0].objects.sha256sum,
SHA256_HEX_DIGEST_SIZE);
update_info.image_size = metadata_any_boards.objects[1].objects.size;
update_info.image_size = metadata_any_boards.objects[1].objects[0].objects.size;
LOG_DBG("metadata_any: %s",
update_info.sha256sum_image);
} else {
LOG_DBG("elements: %d\n", metadata_some_boards.objects_len);
for (size_t i = 0; i < metadata_some_boards.objects_len; ++i) {
LOG_DBG("obj[%d].elements: %d\n",
i, metadata_some_boards.objects[i].objects_len);
for (size_t j = 0; j < metadata_some_boards.objects[i].objects_len; ++j) {
struct resp_probe_objects *obj =
&metadata_some_boards.objects[i].objects[j].objects;
LOG_DBG("\tMode: %s\n\tSHA: %s\n\tSize: %d\n",
obj->mode, obj->sha256sum, obj->size);
}
}

if (metadata_some_boards.objects_len != 2) {
LOG_ERR("Could not parse json");
LOG_ERR("Object length of type 'some metadata' is incorrect");
ctx.code_status = UPDATEHUB_METADATA_ERROR;
goto cleanup;
}
Expand All @@ -888,7 +912,7 @@ enum updatehub_response z_impl_updatehub_probe(void)
}

sha256size = strlen(
metadata_some_boards.objects[1].objects.sha256sum) + 1;
metadata_some_boards.objects[1].objects[0].objects.sha256sum) + 1;

if (sha256size != SHA256_HEX_DIGEST_SIZE) {
LOG_ERR("SHA256 size is invalid");
Expand All @@ -897,10 +921,10 @@ enum updatehub_response z_impl_updatehub_probe(void)
}

memcpy(update_info.sha256sum_image,
metadata_some_boards.objects[1].objects.sha256sum,
metadata_some_boards.objects[1].objects[0].objects.sha256sum,
SHA256_HEX_DIGEST_SIZE);
update_info.image_size =
metadata_some_boards.objects[1].objects.size;
metadata_some_boards.objects[1].objects[0].objects.size;
LOG_DBG("metadata_some: %s",
update_info.sha256sum_image);
}
Expand Down Expand Up @@ -942,7 +966,7 @@ enum updatehub_response z_impl_updatehub_update(void)

if (updatehub_storage_mark_partition_to_upgrade(&ctx.storage_ctx,
UPDATEHUB_SLOT_PARTITION_1)) {
LOG_ERR("Could not reporting downloaded state");
LOG_ERR("Could not mark partition to upgrade");
ctx.code_status = UPDATEHUB_INSTALL_ERROR;
goto error;
}
Expand Down
24 changes: 18 additions & 6 deletions subsys/mgmt/updatehub/updatehub_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,20 @@ struct resp_probe_objects_array {
struct resp_probe_objects objects;
};

struct resp_probe_objects_array_array {
struct resp_probe_objects_array objects[4];
size_t objects_len;
};

struct resp_probe_any_boards {
struct resp_probe_objects_array objects[2];
struct resp_probe_objects_array_array objects[2];
size_t objects_len;
const char *product;
const char *supported_hardware;
};

struct resp_probe_some_boards {
struct resp_probe_objects_array objects[2];
struct resp_probe_objects_array_array objects[2];
size_t objects_len;
const char *product;
const char *supported_hardware[CONFIG_UPDATEHUB_SUPPORTED_HARDWARE_MAX];
Expand Down Expand Up @@ -148,6 +153,13 @@ static const struct json_obj_descr recv_probe_objects_descr_array[] = {
objects, recv_probe_objects_descr),
};

static const struct json_obj_descr recv_probe_objects_descr_array_array[] = {
JSON_OBJ_DESCR_ARRAY_ARRAY(struct resp_probe_objects_array_array,
objects, 4, objects_len,
recv_probe_objects_descr_array,
ARRAY_SIZE(recv_probe_objects_descr_array)),
};

static const struct json_obj_descr recv_probe_sh_string_descr[] = {
JSON_OBJ_DESCR_PRIM(struct resp_probe_any_boards,
product, JSON_TOK_STRING),
Expand All @@ -156,8 +168,8 @@ static const struct json_obj_descr recv_probe_sh_string_descr[] = {
JSON_TOK_STRING),
JSON_OBJ_DESCR_ARRAY_ARRAY(struct resp_probe_any_boards,
objects, 2, objects_len,
recv_probe_objects_descr_array,
ARRAY_SIZE(recv_probe_objects_descr_array)),
recv_probe_objects_descr_array_array,
ARRAY_SIZE(recv_probe_objects_descr_array_array)),
};

static const struct json_obj_descr recv_probe_sh_array_descr[] = {
Expand All @@ -169,8 +181,8 @@ static const struct json_obj_descr recv_probe_sh_array_descr[] = {
supported_hardware_len, JSON_TOK_STRING),
JSON_OBJ_DESCR_ARRAY_ARRAY(struct resp_probe_some_boards,
objects, 2, objects_len,
recv_probe_objects_descr_array,
ARRAY_SIZE(recv_probe_objects_descr_array)),
recv_probe_objects_descr_array_array,
ARRAY_SIZE(recv_probe_objects_descr_array_array)),
};

static const struct json_obj_descr device_identity_descr[] = {
Expand Down
2 changes: 1 addition & 1 deletion subsys/mgmt/updatehub/updatehub_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int updatehub_storage_mark_partition_to_upgrade(struct updatehub_storage_context
return -EINVAL;
}

return boot_request_upgrade_multi(partition_id, BOOT_UPGRADE_TEST);
return boot_request_upgrade(BOOT_UPGRADE_TEST);
}

int updatehub_storage_mark_partition_as_confirmed(const uint32_t partition_id)
Expand Down
Loading