add mktitanimg to create Titan (AR7-based) images (#6632)
[openwrt/openwrt.git] / tools / firmware-utils / src / mktitanimg.h
1 #ifndef __MKTITANIMG_H
2 #define __MKTITANIMG_H
3
4 #ifndef CFGMGR_CKSUM_H
5 #define CFGMGR_CKSUM_H
6
7 #define CKSUM_MAGIC_NUMBER 0xC453DE23
8
9 #include <inttypes.h>
10 #include <stdio.h>
11 #include <errno.h>
12
13 int cs_is_tagged(FILE*);
14 unsigned long cs_read_sum(FILE*);
15 int cs_calc_sum(FILE*, unsigned long*, int);
16 int cs_set_sum(FILE*, unsigned long, int);
17 void cs_get_sum(FILE*, unsigned long*);
18 unsigned long cs_calc_buf_sum(char*, int);
19 int cs_validate_file(char*);
20
21 #endif
22 #ifndef ___CMDLINE_H___
23 #define ___CMDLINE_H___
24
25 /* ********* Library Configuration ********* */
26 typedef struct CMDLINE_OPT
27 {
28 int min; /* Minimum number of arguments this option takes */
29 int max; /* Maximum number of arguments this option takes */
30 int flags; /* Controlling flags (whether to accept or not, etc) */
31 } CMDLINE_OPT;
32
33 typedef struct CMDLINE_CFG
34 {
35 CMDLINE_OPT opts[26]; /* Options 'a' through 'z' */
36 CMDLINE_OPT global; /* Global option (outside 'a'..'z') */
37 } CMDLINE_CFG;
38 /* ******************************************** */
39
40 #define CMDLINE_OPTFLAG_ALLOW 0x1 /* The option is allowed */
41 #define CMDLINE_OPTFLAG_MANDAT 0x2 /* The option is mandatory */
42
43 extern void cmdline_print(char* argv[]);
44
45 extern int cmdline_configure(CMDLINE_CFG* p_cfg);
46 extern int cmdline_read(int argc, char* argv[]);
47
48 extern void* cmdline_getarg_list(char opt);
49 extern int cmdline_getarg_count(void* list);
50 extern int cmdline_getopt_count(char opt);
51 extern int cmdline_getarg(void* list, int num);
52
53 extern char* cmdline_error(int err);
54 #endif
55
56
57 #ifndef _NSPIMGHDR_H_
58 #define _NSPIMGHDR_H_
59
60 /* This file describes the header format for the single image. The image is broken
61 up into several pieces. The image contains this header plus 1 or more sections.
62 Each section contains a binary block that could be a kernel, filesystem, etc. The
63 only garentee for this is that the very first section MUST be executable. Meaning
64 that the bootloader will be able to take the address of the header start, add the
65 header size, and execute that binary block. The header has its own checksum. It
66 starts hdr_size-4 bytes from the start of the header.
67 */
68
69 struct nsp_img_hdr_head
70 {
71 unsigned int magic; /* Magic number to identify this image header */
72 unsigned int boot_offset; /* Offset from start of header to kernel code. */
73 unsigned int flags; /* Image flags. */
74 unsigned int hdr_version; /* Version of this header. */
75 unsigned int hdr_size; /* The complete size of all portions of the header */
76 unsigned int prod_id; /* This product id */
77 unsigned int rel_id; /* Which release this is */
78 unsigned int version; /* name-MMM.nnn.ooo-rxx => 0xMMnnooxx. See comment
79 below */
80 unsigned int image_size; /* Image size (including header) */
81 unsigned int info_offset; /* Offset from start of header to info block */
82 unsigned int sect_info_offset; /* Offset from start of header to section desc */
83 unsigned int chksum_offset; /* Offset from start of header to chksum block */
84 // unsigned int pad1;
85 };
86
87 /* The patch id is a machine readable value that takes the normal patch level, and encodes
88 the correct numbers inside of it. The format of the patches are name-MM.NN.oo-rxx.bin.
89 Convert MM, NN, oo, and xx into hex, and encode them as 0xMMNNooxx. Thus:
90 att-1.2.18-r14.bin => 0x0102120e */
91
92 /* The following are the flag bits for the above flags variable */
93 /* List of NSP status flags: */
94 #define NSP_IMG_FLAG_FAILBACK_MASK 0xF8000000
95
96 /* NSP Image status flag: Flag indicates individual sections image */
97 #define NSP_IMG_FLAG_INDIVIDUAL 0x00000001
98
99 /* NSP Image status flag 1: Image contains a bootable image when this bit is 0 */
100 #define NSP_IMG_FLAG_FAILBACK_1 0x08000000
101
102 /* NSP Image status flag 2: Image contains a non-bootable image when this bit is 0 */
103 #define NSP_IMG_FLAG_FAILBACK_2 0x10000000
104
105 /* NSP Image status flag 3: PSPBoot has tried the image when this bit is 0 */
106 #define NSP_IMG_FLAG_FAILBACK_3 0x20000000
107
108 /* NSP Image status flag 4: Image is now secondary image when this bit is 0 */
109 #define NSP_IMG_FLAG_FAILBACK_4 0x40000000
110
111 /* NSP Image status flag 5: Image contains a valid image when this bit is 0 */
112 #define NSP_IMG_FLAG_FAILBACK_5 0x80000000
113
114 /* NSP Single image magic number */
115 #define NSP_IMG_MAGIC_NUMBER 0x4D544443
116
117
118 struct nsp_img_hdr_info
119 {
120 char release_name[64]; /* Name of release */
121 char image_filename[64]; /* name-mm.nn.oo-rxx.bin format */
122 };
123
124 struct nsp_img_hdr_section_info
125 {
126 unsigned int num_sects; /* Number of section (and section desc blocks) in this
127 image */
128 unsigned int sect_size; /* Size of a SINGLE section_desc block */
129 unsigned int sections_offset; /* Offset to from start of header to the start of
130 the section blocks */
131 };
132
133 /* There will be one of more of the following stuctures in the image header. Each
134 section will have one of these blocks. */
135 struct nsp_img_hdr_sections
136 {
137 unsigned int offset; /* Offset of section from start of NSP_IMG_HDR_HEAD */
138 unsigned int total_size; /* Size of section (including pad size.) */
139 unsigned int raw_size; /* Size of section only */
140 unsigned int flags; /* Section flags */
141 unsigned int chksum; /* Section checksum */
142 unsigned int type; /* Section type. What kind of info does this section
143 describe */
144 char name[16]; /* Reference name for this section. */
145 };
146 #define NSP_IMG_SECTION_TYPE_KERNEL (0x01)
147 #define NSP_IMG_SECTION_TYPE_FILESYSTEM_ROOT (0x02)
148 #define NSP_IMG_SECTION_TYPE_FILESYSTEM (0x03)
149
150 struct nsp_img_hdr
151 {
152 struct nsp_img_hdr_head head; /* Head portion */
153 struct nsp_img_hdr_info info; /* Info */
154 struct nsp_img_hdr_section_info sect_info; /* Section block */
155 struct nsp_img_hdr_sections sections; /* 1 or more section_description blocks. More
156 section_desc blocks will be appended here
157 for each additional section needed */
158 };
159
160 struct nsp_img_hdr_chksum
161 {
162 unsigned int hdr_chksum; /* The checksum for the complete header. Excepting the
163 checksum block */
164 };
165
166 struct nsp_img_hdr_sections *nsp_img_hdr_get_section_ptr_by_name(struct nsp_img_hdr *hdr, char *name);
167 unsigned int nsp_img_hdr_get_section_offset_by_name(struct nsp_img_hdr *hdr, char *name);
168 unsigned int nsp_img_hdr_get_section_size_by_name(struct nsp_img_hdr *hdr, char *name);
169
170 #endif
171 #endif /* __MKTITANIMG_H */