1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef H_IMAGE_
21 #define H_IMAGE_
22 
23 #include <inttypes.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define IMAGE_MAGIC                 0x96f3b83d
30 #define IMAGE_TLV_INFO_MAGIC        0x6907
31 #define IMAGE_TLV_PROT_INFO_MAGIC   0x6908
32 
33 #define IMAGE_HEADER_SIZE           32
34 
35 /** Image header flags. */
36 #define IMAGE_F_NON_BOOTABLE        0x00000010 /* Split image app. */
37 #define IMAGE_F_ROM_FIXED_ADDR      0x00000100
38 
39 /** Image trailer TLV types. */
40 #define IMAGE_TLV_SHA256            0x10   /* SHA256 of image hdr and body */
41 
42 /** Image TLV-specific definitions. */
43 #define IMAGE_HASH_LEN              32
44 
45 struct image_version {
46     uint8_t iv_major;
47     uint8_t iv_minor;
48     uint16_t iv_revision;
49     uint32_t iv_build_num;
50 };
51 
52 /** Image header.  All fields are in little endian byte order. */
53 struct image_header {
54     uint32_t ih_magic;
55     uint32_t ih_load_addr;
56     uint16_t ih_hdr_size; /* Size of image header (bytes). */
57     uint16_t _pad2;
58     uint32_t ih_img_size; /* Does not include header. */
59     uint32_t ih_flags;    /* IMAGE_F_[...]. */
60     struct image_version ih_ver;
61     uint32_t _pad3;
62 };
63 
64 /** Image TLV header.  All fields in little endian. */
65 struct image_tlv_info {
66     uint16_t it_magic;
67     uint16_t it_tlv_tot;  /* size of TLV area (including tlv_info header) */
68 };
69 
70 /** Image trailer TLV format. All fields in little endian. */
71 struct image_tlv {
72     uint8_t  it_type;   /* IMAGE_TLV_[...]. */
73     uint8_t  _pad;
74     uint16_t it_len;    /* Data length (not including TLV header). */
75 };
76 
77 _Static_assert(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
78                "struct image_header not required size");
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
85