Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 7 | #include "cmd_print_metadata_v2.h" |
| 8 | |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 9 | #include <cstdint> |
| 10 | #include <cstdio> |
| 11 | #include <cstdlib> |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 12 | #include <vector> |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 13 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 14 | #include "common/uuid/uuid.h" |
| 15 | #include "print_uuid.h" |
| 16 | #include "protocols/service/fwu/packed-c/fwu_proto.h" |
| 17 | #include "protocols/service/fwu/packed-c/metadata_v2.h" |
| 18 | |
| 19 | void cmd_print_metadata_v2(fwu_app &app) |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 20 | { |
| 21 | std::vector<uint8_t> fetched_object; |
| 22 | struct uuid_octets object_uuid; |
| 23 | |
| 24 | uuid_guid_octets_from_canonical(&object_uuid, FWU_METADATA_CANONICAL_UUID); |
| 25 | |
| 26 | int status = app.read_object(object_uuid, fetched_object); |
| 27 | |
| 28 | if (status) { |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 29 | printf("Error: failed to read metadata\n"); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | if (fetched_object.size() < sizeof(struct fwu_metadata)) { |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 34 | printf("Error: invalid metadata size\n"); |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | /* Print mandatory metadata header */ |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 39 | const struct fwu_metadata *metadata = (const struct fwu_metadata *)fetched_object.data(); |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 40 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 41 | printf("\nfwu_metadata (size %zu bytes) :\n", fetched_object.size()); |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 42 | printf("\tcrc_32 : 0x%x\n", metadata->crc_32); |
| 43 | printf("\tversion : %d\n", metadata->version); |
| 44 | printf("\tmetadata_size : %d\n", metadata->metadata_size); |
| 45 | printf("\theader_size : %d\n", metadata->header_size); |
| 46 | printf("\tactive_index : %d\n", metadata->active_index); |
| 47 | printf("\tprevious_active_index : %d\n", metadata->previous_active_index); |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 48 | printf("\tbank_state : 0x%x 0x%x\n", metadata->bank_state[0], metadata->bank_state[1]); |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 49 | |
| 50 | if (metadata->metadata_size <= metadata->header_size) |
| 51 | return; |
| 52 | |
| 53 | size_t fw_store_desc_size = metadata->metadata_size - metadata->header_size; |
| 54 | |
| 55 | if (fw_store_desc_size < sizeof(fwu_fw_store_desc)) { |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 56 | printf("\tInsufficient space for fw store descriptor\n"); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | /* Print optional fw store descriptor */ |
| 61 | struct fwu_fw_store_desc *fw_store_desc = |
| 62 | (struct fwu_fw_store_desc *)&fetched_object[metadata->header_size]; |
| 63 | |
| 64 | printf("\tfw_store_desc :\n"); |
| 65 | printf("\t\tnum_banks : %d\n", fw_store_desc->num_banks); |
| 66 | printf("\t\tnum_images : %d\n", fw_store_desc->num_images); |
| 67 | printf("\t\timg_entry_size : %d\n", fw_store_desc->img_entry_size); |
| 68 | printf("\t\tbank_entry_size : %d\n", fw_store_desc->bank_entry_size); |
| 69 | |
| 70 | for (unsigned int i = 0; i < fw_store_desc->num_images; i++) { |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 71 | struct fwu_image_entry *img_entry = &fw_store_desc->img_entry[i]; |
| 72 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 73 | printf("\t\timg_entry[%u] :\n", i); |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 74 | printf("\t\t\timg_type_uuid : %s\n", print_uuid(img_entry->img_type_uuid).c_str()); |
| 75 | printf("\t\t\tlocation_uuid : %s\n", print_uuid(img_entry->location_uuid).c_str()); |
| 76 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 77 | for (unsigned int j = 0; j < fw_store_desc->num_banks; j++) { |
| 78 | struct fwu_img_bank_info *bank_info = &img_entry->img_bank_info[j]; |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 79 | |
Gyorgy Szing | 3c44624 | 2023-03-31 01:53:15 +0200 | [diff] [blame] | 80 | printf("\t\t\timg_bank_info[%u] :\n", j); |
Julian Hall | 351a072 | 2023-01-12 11:58:42 +0000 | [diff] [blame] | 81 | printf("\t\t\t\timg_uuid : %s\n", print_uuid(bank_info->img_uuid).c_str()); |
| 82 | printf("\t\t\t\taccepted : %d\n", bank_info->accepted); |
| 83 | } |
| 84 | } |
| 85 | } |