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