1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Freescale i.MX28 SB image generator
5 * Copyright (C) 2012 Marek Vasut <marex@denx.de>
12 #include <arpa/inet.h>
14 #define SB_BLOCK_SIZE 16
16 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
17 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
19 struct sb_boot_image_version {
28 struct sb_boot_image_header {
30 /* SHA1 of the header. */
33 /* CBC-MAC initialization vector. */
39 uint8_t signature1[4];
40 /* Major version of the image format. */
41 uint8_t major_version;
42 /* Minor version of the image format. */
43 uint8_t minor_version;
44 /* Flags associated with the image. */
46 /* Size of the image in 16b blocks. */
47 uint32_t image_blocks;
48 /* Offset of the first tag in 16b blocks. */
49 uint32_t first_boot_tag_block;
50 /* ID of the section to boot from. */
51 uint32_t first_boot_section_id;
52 /* Amount of crypto keys. */
54 /* Offset to the key dictionary in 16b blocks. */
55 uint16_t key_dictionary_block;
56 /* Size of this header in 16b blocks. */
57 uint16_t header_blocks;
58 /* Amount of section headers. */
59 uint16_t section_count;
60 /* Section header size in 16b blocks. */
61 uint16_t section_header_size;
62 /* Padding to align timestamp to uint64_t. */
64 /* 'sgtl' (since v1.1) */
65 uint8_t signature2[4];
66 /* Image generation date, in microseconds since 1.1.2000 . */
67 uint64_t timestamp_us;
68 /* Product version. */
69 struct sb_boot_image_version
71 /* Component version. */
72 struct sb_boot_image_version
74 /* Drive tag for the system drive. (since v1.1) */
80 #define SB_VERSION_MAJOR 1
81 #define SB_VERSION_MINOR 1
83 /* Enable to HTLLC boot report. */
84 #define SB_IMAGE_FLAG_DISPLAY_PROGRESS (1 << 0)
85 #define SB_IMAGE_FLAGS_MASK SB_IMAGE_FLAG_DISPLAY_PROGRESS
87 struct sb_key_dictionary_key {
88 /* The CBC-MAC of image and sections header. */
89 uint8_t cbc_mac[SB_BLOCK_SIZE];
90 /* The AES key encrypted by image key (zero). */
91 uint8_t key[SB_BLOCK_SIZE];
94 struct sb_ivt_header {
105 #define SB_HAB_IVT_TAG 0xd1UL
106 #define SB_HAB_DCD_TAG 0xd2UL
108 #define SB_HAB_VERSION 0x40UL
111 * The "size" field in the IVT header is not naturally aligned,
112 * use this macro to fill first 4 bytes of the IVT header without
113 * causing issues on some systems (esp. M68k, PPC, MIPS-BE, ARM-BE).
115 static inline uint32_t sb_hab_ivt_header(void)
118 ret |= SB_HAB_IVT_TAG << 24;
119 ret |= sizeof(struct sb_ivt_header) << 16;
120 ret |= SB_HAB_VERSION;
124 struct sb_sections_header {
125 /* Section number. */
126 uint32_t section_number;
127 /* Offset of this sections first instruction after "TAG". */
128 uint32_t section_offset;
129 /* Size of the section in 16b blocks. */
130 uint32_t section_size;
132 uint32_t section_flags;
135 #define SB_SECTION_FLAG_BOOTABLE (1 << 0)
142 #define ROM_TAG_CMD_FLAG_ROM_LAST_TAG 0x1
143 #define ROM_LOAD_CMD_FLAG_DCD_LOAD 0x1 /* MX28 only */
144 #define ROM_JUMP_CMD_FLAG_HAB 0x1 /* MX28 only */
145 #define ROM_CALL_CMD_FLAG_HAB 0x1 /* MX28 only */
150 uint32_t reserved[3];
153 uint32_t section_number;
154 uint32_t section_length;
155 uint32_t section_flags;
170 /* Passed in register r0 before JUMP */
176 /* Passed in register r0 before CALL */
189 * Most of the mode names are same or at least similar
190 * on i.MX23 and i.MX28, but some of the mode names
191 * differ. The "name" field represents the mode name
192 * on i.MX28 as seen in Table 12-2 of the datasheet.
193 * The "altname" field represents the differently named
194 * fields on i.MX23 as seen in Table 35-3 of the
197 static const struct {
202 { "USB", NULL, 0x00 },
203 { "I2C", NULL, 0x01 },
204 { "SPI2_FLASH", "SPI1_FLASH", 0x02 },
205 { "SPI3_FLASH", "SPI2_FLASH", 0x03 },
206 { "NAND_BCH", NULL, 0x04 },
207 { "JTAG", NULL, 0x06 },
208 { "SPI3_EEPROM", "SPI2_EEPROM", 0x08 },
209 { "SD_SSP0", NULL, 0x09 },
210 { "SD_SSP1", NULL, 0x0A }
223 struct sb_source_entry {
230 #endif /* __MXSSB_H__ */