mxssb.h 4.04 KB
Newer Older
Marek Vasut's avatar
Marek Vasut committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Freescale i.MX28 SB image generator
 *
 * Copyright (C) 2012 Marek Vasut <marex@denx.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 */

#ifndef __MXSSB_H__
#define __MXSSB_H__

#include <stdint.h>

#define SB_BLOCK_SIZE		16

#define roundup(x, y)		((((x) + ((y) - 1)) / (y)) * (y))
#define ARRAY_SIZE(x)		(sizeof(x) / sizeof((x)[0]))

struct sb_boot_image_version {
	uint16_t	major;
	uint16_t	pad0;
	uint16_t	minor;
	uint16_t	pad1;
	uint16_t	revision;
	uint16_t	pad2;
};

struct sb_boot_image_header {
	uint8_t		digest[20];		/* SHA1 of the header. */
	uint8_t		signature1[4];		/* 'STMP' */
	uint8_t		major_version;		/* Major version of the image format. */
	uint8_t		minor_version;		/* Minor version of the image format. */
	uint16_t	flags;			/* Flags associated with the image. */
	uint32_t	image_blocks;		/* Size of the image in 16b blocks. */
	uint32_t	first_boot_tag_block;	/* Offset of the first tag in 16b blocks. */
	uint32_t	first_boot_section_id;	/* ID of the section to boot from. */
	uint16_t	key_count;		/* Amount of crypto keys. */
	uint16_t	key_dictionary_block;	/* Offset to the key dictionary in 16b blocks. */
	uint16_t	header_blocks;		/* Size of this header in 16b blocks. */
	uint16_t	section_count;		/* Amount of section headers. */
	uint16_t	section_header_size;	/* Section header size in 16b blocks. */
	uint8_t		padding0[2];		/* Padding to align timestamp to uint64_t. */
	uint8_t		signature2[4];		/* 'sgtl' */
	uint64_t	timestamp_us;		/* Image generation date, in microseconds since 1.1.2000 . */
	struct sb_boot_image_version
			product_version;	/* Product version. */
	struct sb_boot_image_version
			component_version;	/* Component version. */
	uint16_t	drive_tag;		/* Drive tag for the system drive. */
	uint8_t		padding1[6];		/* Padding. */
};

#define	SB_VERSION_MAJOR	1
#define	SB_VERSION_MINOR	1

#define SB_IMAGE_FLAG_VERBOSE	(1 << 0)	/* Enable to HTLLC verbose boot report. */

struct sb_key_dictionary_key {
	uint8_t		cbc_mac[SB_BLOCK_SIZE];	/* The CBC-MAC of image and sections header. */
	uint8_t		key[SB_BLOCK_SIZE];	/* The AES key encrypted by image key (zero). */
};

struct sb_ivt_header {
	uint32_t	header;
	uint32_t	entry;
	uint32_t	reserved1;
	uint32_t	dcd;
	uint32_t	boot_data;
	uint32_t	self;
	uint32_t	csf;
	uint32_t	reserved2;
};

#define	SB_HAB_IVT_TAG			0xd1
#define	SB_HAB_VERSION			0x40

/*
 * The "size" field in the IVT header is not naturally aligned,
 * use this macro to fill first 4 bytes of the IVT header without
 * causing issues on some systems (esp. M68k, PPC, MIPS-BE, ARM-BE).
 */
#define	SB_HAB_IVT_HEADER(size)			\
	(					\
		(SB_HAB_IVT_TAG << 24) |	\
		(__cpu_to_be16(size) << 16) |	\
		SB_HAB_VERSION			\
	)

97
98
#define	ROM_CALL_CMD_FLAG_HAB		0x1
#define ROM_TAG_CMD_FLAG_LAST_TAG	0x1
Marek Vasut's avatar
Marek Vasut committed
99
100
101
102
103
104
105
106
107
108

struct sb_sections_header {
	uint32_t	section_number;	/* Section number. */
	uint32_t	section_offset;	/* Offset of this sections first instruction after "TAG". */
	uint32_t	section_size;	/* Size of the section in 16b blocks. */
	uint32_t	section_flags;	/* Section flags. */
};

#define	SB_SECTION_FLAG_BOOTABLE	(1 << 0)

109
struct sb_command {
Marek Vasut's avatar
Marek Vasut committed
110
111
	struct {
		uint8_t		checksum;
112
		uint8_t		tag;
Marek Vasut's avatar
Marek Vasut committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
		uint16_t	flags;
	} header;

	union {

	struct {
		uint32_t	address;
		uint32_t	length;
		uint32_t	crc32;
	} load;
	struct {
		uint32_t	address;
		uint32_t	reserved;
		uint32_t	argument;
	} call;
	struct {
		uint32_t	section_number;
		uint32_t	section_length;
		uint32_t	section_flags;
	} tag;

	};
};

137
138
139
#define ROM_TAG_CMD		0x1
#define ROM_LOAD_CMD		0x2
#define ROM_CALL_CMD		0x5
Marek Vasut's avatar
Marek Vasut committed
140
141

struct sb_source_entry {
142
	uint8_t		tag;
Marek Vasut's avatar
Marek Vasut committed
143
144
145
146
147
148
149
	uint32_t	address;
	uint32_t	flags;
	uint8_t		*payload;
	uint32_t	length;
};

#endif	/* __MXSSB_H__ */