diff --git a/subsys/mgmt/updatehub/updatehub.c b/subsys/mgmt/updatehub/updatehub.c index 0bc14f3b886371..25a8f54f786f74 100644 --- a/subsys/mgmt/updatehub/updatehub.c +++ b/subsys/mgmt/updatehub/updatehub.c @@ -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"); @@ -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; } @@ -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"); @@ -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); } @@ -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; } diff --git a/subsys/mgmt/updatehub/updatehub_priv.h b/subsys/mgmt/updatehub/updatehub_priv.h index ebfedcbb02a8d7..707e2db6c6dfb2 100644 --- a/subsys/mgmt/updatehub/updatehub_priv.h +++ b/subsys/mgmt/updatehub/updatehub_priv.h @@ -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]; @@ -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), @@ -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[] = { @@ -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[] = { diff --git a/subsys/mgmt/updatehub/updatehub_storage.c b/subsys/mgmt/updatehub/updatehub_storage.c index d18b24be4bc91a..81886a9044e239 100644 --- a/subsys/mgmt/updatehub/updatehub_storage.c +++ b/subsys/mgmt/updatehub/updatehub_storage.c @@ -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)