David Brown | 297029a | 2019-08-13 14:29:51 -0600 | [diff] [blame] | 1 | // Copyright (C) 2019, Linaro Ltd |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | // not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | // This file is a Binary Template file for the 010 Editor |
| 18 | // (http://www.sweetscape.com/010editor/) to allow it to show the |
| 19 | // structure of an MCUboot image. |
| 20 | |
| 21 | LittleEndian(); |
| 22 | |
| 23 | struct ENTRY { |
| 24 | uint32 id; |
| 25 | uint32 offset; |
| 26 | uint32 size; |
| 27 | uint32 pad; |
| 28 | }; |
| 29 | |
| 30 | // The simulator writes the partition table at the beginning of the |
| 31 | // image, so that we can tell where the partitions are. If you are |
| 32 | // trying to view an image captured from a device, you can either |
| 33 | // construct a synthetic partition table in the file, or change code |
| 34 | // described below to hardcode one. |
| 35 | struct PTABLE { |
| 36 | uchar pheader[8]; |
| 37 | if (ptable.pheader != "mcuboot\0") { |
| 38 | // NOTE: Put code here to hard code a partition table, and |
| 39 | // continue. |
| 40 | Warning("Invalid magic on ptable header"); |
| 41 | return -1; |
| 42 | } else { |
| 43 | uint32 count; |
| 44 | struct ENTRY entries[count]; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | struct PTABLE ptable; |
| 49 | |
| 50 | struct IMAGE_VERSION { |
| 51 | uchar major; |
| 52 | uchar minor; |
| 53 | uint16 revision; |
| 54 | uint32 build_num; |
| 55 | }; |
| 56 | |
| 57 | struct IHDR { |
| 58 | uint32 magic <format=hex>; |
| 59 | uint32 load_addr <format=hex>; |
| 60 | uint16 hdr_size <format=hex>; |
| 61 | uint16 protect_size <format=hex>; |
| 62 | uint32 img_size <format=hex>; |
| 63 | uint32 flags; |
| 64 | struct IMAGE_VERSION ver; |
| 65 | uint32 _pad1; |
| 66 | }; |
| 67 | |
| 68 | struct TLV_HDR { |
| 69 | uint16 magic; |
| 70 | uint16 tlv_tot; |
| 71 | }; |
| 72 | |
| 73 | struct TLV { |
| 74 | uchar type <format=hex>; |
| 75 | uchar pad; |
| 76 | uint16 len; |
| 77 | |
| 78 | switch (type) { |
| 79 | case 0x01: // keyhash |
| 80 | uchar keyhash[len]; |
| 81 | break; |
| 82 | case 0x40: // dependency |
| 83 | if (len != 12) { |
| 84 | Warning("Invalid dependency size"); |
| 85 | return -1; |
| 86 | } |
| 87 | uchar image_id; |
| 88 | uchar pad1; |
| 89 | uint16 pad2; |
| 90 | struct IMAGE_VERSION version; |
| 91 | break; |
| 92 | default: |
| 93 | // Other, just consume the data. |
| 94 | uchar data[len]; |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | local int i; |
| 99 | local int epos; |
| 100 | |
| 101 | for (i = 0; i < ptable.count; i++) { |
| 102 | FSeek(ptable.entries[i].offset); |
| 103 | switch (ptable.entries[i].id) { |
| 104 | case 1: |
| 105 | case 2: |
| 106 | case 4: |
| 107 | case 5: |
| 108 | struct IMAGE { |
| 109 | struct IHDR ihdr; |
| 110 | |
| 111 | if (ihdr.magic == 0x96f3b83d) { |
| 112 | uchar payload[ihdr.img_size]; |
| 113 | |
| 114 | epos = FTell(); |
| 115 | struct TLV_HDR tlv_hdr; |
| 116 | |
| 117 | if (tlv_hdr.magic == 0x6907) { |
| 118 | epos += tlv_hdr.tlv_tot; |
| 119 | while (FTell() < epos) { |
| 120 | struct TLV tlv; |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | // uchar block[ptable.entries[i].size]; |
| 125 | } image; |
| 126 | break; |
| 127 | case 3: |
| 128 | struct SCRATCH { |
| 129 | uchar data[ptable.entries[i].size]; |
| 130 | } scratch; |
| 131 | break; |
| 132 | default: |
| 133 | break; |
| 134 | } |
| 135 | } |