summaryrefslogtreecommitdiffstats
path: root/pickles/uimage.pk
blob: 3656f75e93752821e4abb0c4fb3258069c5c403b (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/* uimage.pk - U-Boot Image Format.  */

/* Copyright (C) 2022 The poke authors */

/* 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 3 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* U-Boot Image Format
 *
 * U-Boot operates on "image" files which can be basically anything,
 * preceeded by a special header.
 *
 * The header defines the following image properties:
 *   - Target operating system
 *   - Target CPU architecture
 *   - Image compression type
 *   - Local address
 *   - Entry point
 *   - Image name
 *   - Image timestamp
 *
 * The header is marked by a special magic number, and both the header
 * and the data portions of the image are secured against corruption
 * by CRC32 checksums.
 *
 * Ref:
 *   https://www.denx.de/wiki/DULG/UBootImages
 *   https://github.com/u-boot/u-boot/blob/master/include/image.h
 *   https://github.com/u-boot/u-boot/blob/master/common/image.c
 */

/* set_endian(ENDIAN_BIG); */

type UImage_TableEntry =
  struct
  {
    int id;
    string sname; /* short name */
    string lname; /* long name */
  };

var UImage_OS_INVALID = 0UB,    /* Invalid OS */
    UImage_OS_OPENBSD = 1UB,    /* OpenBSD */
    UImage_OS_NETBSD = 2UB,     /* NetBSD */
    UImage_OS_FREEBSD = 3UB,    /* FreeBSD */
    UImage_OS_4_4BSD = 4UB,     /* 4.4BSD */
    UImage_OS_LINUX = 5UB,      /* Linux */
    UImage_OS_SVR4 = 6UB,       /* SVR4 */
    UImage_OS_ESIX = 7UB,       /* Esix */
    UImage_OS_SOLARIS = 8UB,    /* Solaris */
    UImage_OS_IRIX = 9UB,       /* Irix */
    UImage_OS_SCO = 10UB,       /* SCO */
    UImage_OS_DELL = 11UB,      /* Dell */
    UImage_OS_NCR = 12UB,       /* NCR */
    UImage_OS_LYNXOS = 13UB,    /* LynxOS */
    UImage_OS_VXWORKS = 14UB,   /* VxWorks */
    UImage_OS_PSOS = 15UB,      /* pSOS */
    UImage_OS_QNX = 16UB,       /* QNX */
    UImage_OS_U_BOOT = 17UB,    /* Firmware */
    UImage_OS_RTEMS = 18UB,     /* RTEMS */
    UImage_OS_ARTOS = 19UB,     /* ARTOS */
    UImage_OS_UNITY = 20UB,     /* Unity OS */
    UImage_OS_INTEGRITY = 21UB, /* INTEGRITY */
    UImage_OS_OSE = 22UB,       /* OSE */
    UImage_OS_PLAN9 = 23UB,     /* Plan 9 */
    UImage_OS_OPENRTOS = 24UB,  /* OpenRTOS */
    UImage_OS_ARM_TRUSTED_FIRMWARE = 25UB, /* ARM Trusted Firmware */
    UImage_OS_TEE = 26UB,       /* Trusted Execution Environment */
    UImage_OS_OPENSBI = 27UB,   /* RISC-V OpenSBI */
    UImage_OS_EFI = 28UB;       /* EFI Firmware (e.g. GRUB2) */

var UImage_OS = [
  UImage_TableEntry{
    id = UImage_OS_INVALID, sname = "invalid", lname = "Invalid OS",
  },
  UImage_TableEntry{
    id = UImage_OS_OPENBSD, sname = "openbsd", lname = "OpenBSD",
  },
  UImage_TableEntry{
    id = UImage_OS_NETBSD, sname = "netbsd", lname = "NetBSD",
  },
  UImage_TableEntry{
    id = UImage_OS_FREEBSD, sname = "freebsd", lname = "FreeBSD",
  },
  UImage_TableEntry{
    id = UImage_OS_4_4BSD, sname = "4_4bsd", lname = "4.4BSD",
  },
  UImage_TableEntry{
    id = UImage_OS_LINUX, sname = "linux", lname = "Linux",
  },
  UImage_TableEntry{
    id = UImage_OS_SVR4, sname = "svr4", lname = "SVR4",
  },
  UImage_TableEntry{
    id = UImage_OS_ESIX, sname = "esix", lname = "Esix",
  },
  UImage_TableEntry{
    id = UImage_OS_SOLARIS, sname = "solaris", lname = "Solaris",
  },
  UImage_TableEntry{
    id = UImage_OS_IRIX, sname = "irix", lname = "Irix",
  },
  UImage_TableEntry{
    id = UImage_OS_SCO, sname = "sco", lname = "SCO",
  },
  UImage_TableEntry{
    id = UImage_OS_DELL, sname = "dell", lname = "Dell",
  },
  UImage_TableEntry{
    id = UImage_OS_NCR, sname = "ncr", lname = "NCR",
  },
  UImage_TableEntry{
    id = UImage_OS_LYNXOS, sname = "lynxos", lname = "LynxOS",
  },
  UImage_TableEntry{
    id = UImage_OS_VXWORKS, sname = "vxworks", lname = "VxWorks",
  },
  UImage_TableEntry{
    id = UImage_OS_PSOS, sname = "psos", lname = "pSOS",
  },
  UImage_TableEntry{
    id = UImage_OS_QNX, sname = "qnx", lname = "QNX",
  },
  UImage_TableEntry{
    id = UImage_OS_U_BOOT, sname = "u-boot", lname = "U-Boot",
  },
  UImage_TableEntry{
    id = UImage_OS_RTEMS, sname = "rtems", lname = "RTEMS",
  },
  UImage_TableEntry{
    id = UImage_OS_ARTOS, sname = "artos", lname = "ARTOS",  /* CHKME */
  },
  UImage_TableEntry{
    id = UImage_OS_UNITY, sname = "", lname = "Unity OS",
  },
  UImage_TableEntry{
    id = UImage_OS_INTEGRITY, sname = "", lname = "INTEGRITY",
  },
  UImage_TableEntry{
    id = UImage_OS_OSE, sname = "", lname = "OSE",
  },
  UImage_TableEntry{
    id = UImage_OS_PLAN9, sname = "", lname = "Plan 9",
  },
  UImage_TableEntry{
    id = UImage_OS_OPENRTOS, sname = "", lname = "OpenRTOS",
  },
  UImage_TableEntry{
    id = UImage_OS_ARM_TRUSTED_FIRMWARE, sname = "", lname = "ARM Trusted Firmware",
  },
  UImage_TableEntry{
    id = UImage_OS_TEE, sname = "", lname = "Trusted Execution Environment",
  },
  UImage_TableEntry{
    id = UImage_OS_OPENSBI, sname = "", lname = "RISC-V OpenSBI",
  },
  UImage_TableEntry{
    id = UImage_OS_EFI, sname = "", lname = "EFI Firmware (e.g. GRUB2)",
  },
];

var UImage_ARCH_INVALID = 0UB,     /* Invalid CPU */
    UImage_ARCH_ALPHA = 1UB,       /* Alpha */
    UImage_ARCH_ARM = 2UB,         /* ARM */
    UImage_ARCH_I386 = 3UB,        /* Intel x86 */
    UImage_ARCH_IA64 = 4UB,        /* IA64 */
    UImage_ARCH_MIPS = 5UB,        /* MIPS */
    UImage_ARCH_MIPS64 = 6UB,      /* MIPS 64 Bit */
    UImage_ARCH_PPC = 7UB,         /* PowerPC */
    UImage_ARCH_S390 = 8UB,        /* IBM S390 */
    UImage_ARCH_SH = 9UB,          /* SuperH */
    UImage_ARCH_SPARC = 10UB,      /* Sparc */
    UImage_ARCH_SPARC64 = 11UB,    /* Sparc 64 Bit */
    UImage_ARCH_M68K = 12UB,       /* M68K */
    UImage_ARCH_NIOS = 13UB,       /* Nios-32 */
    UImage_ARCH_MICROBLAZE = 14UB, /* MicroBlaze */
    UImage_ARCH_NIOS2 = 15UB,      /* Nios-II */
    UImage_ARCH_BLACKFIN = 16UB,   /* Blackfin */
    UImage_ARCH_AVR32 = 17UB,      /* AVR32 */
    UImage_ARCH_ST200 = 18UB,      /* STMicroelectronics ST200 */
    UImage_ARCH_SANDBOX = 19UB,    /* Sandbox architecture (test only) */
    UImage_ARCH_NDS32 = 20UB,      /* ANDES Technology - NDS32 */
    UImage_ARCH_OPENRISC = 21UB,   /* OpenRISC 1000 */
    UImage_ARCH_ARM64 = 22UB,      /* ARM64 */
    UImage_ARCH_ARC = 23UB,        /* Synopsys DesignWare ARC */
    UImage_ARCH_X86_64 = 24UB,     /* AMD x86_64 Intel and Via */
    UImage_ARCH_XTENSA = 25UB,     /* Xtensa */
    UImage_ARCH_RISCV = 26UB;      /* RISC-V */

/*
var UImage_ARCH_NAMES = [
  [.UImage_ARCH_INVALID] = "invalid",
  [.UImage_ARCH_ALPHA] = "alpha",
  [.UImage_ARCH_ARM] = "arm",
  [.UImage_ARCH_I386] = "x86",
  [.UImage_ARCH_IA64] = "ia64",
  [.UImage_ARCH_MIPS] = "mips",
  [.UImage_ARCH_MIPS64] = "mips64",
  [.UImage_ARCH_PPC] = "powerpc",
  [.UImage_ARCH_S390] = "s390",
  [.UImage_ARCH_SH] = "sh",
  [.UImage_ARCH_SPARC] = "sparc",
  [.UImage_ARCH_SPARC64] = "sparc64",
  [.UImage_ARCH_M68K] = "m68k",
  [.UImage_ARCH_NIOS] = "nios",
  [.UImage_ARCH_MICROBLAZE] = "microblaze",
  [.UImage_ARCH_NIOS2] = "nios2",
  [.UImage_ARCH_BLACKFIN] = "blackfin",
  [.UImage_ARCH_AVR32] = "avr32",
  [.UImage_ARCH_ST200] = "st200",               // CHKME
  [.UImage_ARCH_SANDBOX] = "sandbox",
  [.UImage_ARCH_NDS32] = "nds32",
  [.UImage_ARCH_OPENRISC] = "openrisc",
  [.UImage_ARCH_ARM64] = "arm64",
  [.UImage_ARCH_ARC] = "arc",
  [.UImage_ARCH_X86_64] = "x86_64",
  [.UImage_ARCH_XTENSA] = "xtensa",
  [.UImage_ARCH_RISCV] = "riscv",
];
*/

var UImage_TYPE_INVALID = 0,      /* Invaild Image */
    UImage_TYPE_STANDALONE = 1UB, /* Standalone Program */
    UImage_TYPE_KERNEL = 2UB,     /* OS Kernel Image */
    UImage_TYPE_RAMDISK = 3UB,    /* RAMDisk Image */
    UImage_TYPE_MULTI = 4UB,      /* Multi-File Image */
    UImage_TYPE_FIRMWARE = 5UB,   /* Firmware Image */
    UImage_TYPE_SCRIPT = 6UB,     /* Script file */
    UImage_TYPE_FILESYSTEM = 7UB, /* Filesystem Image (any type) */
    UImage_TYPE_FLATDT = 8UB,     /* Binary Flat Device Tree Blob */
    UImage_TYPE_KWBIMAGE = 9UB,   /* Kirkwood Boot Image */
    UImage_TYPE_IMXIMAGE = 10UB,  /* Freescale IMXBoot Image */
    UImage_TYPE_UBLIMAGE = 11UB,  /* Davinci UBL Image */
    UImage_TYPE_OMAPIMAGE = 12UB, /* TI OMAP Config Header Image */
    UImage_TYPE_AISIMAGE = 13UB,  /* TI Davinci AIS Image */
    /* OS Kernel Image, can run from any load address */
    UImage_TYPE_KERNEL_NOLOAD = 14UB,
    UImage_TYPE_PBLIMAGE = 15UB,     /* Freescale PBL Boot Image */
    UImage_TYPE_MXSIMAGE = 16UB,     /* Freescale MXSBoot Image */
    UImage_TYPE_GPIMAGE = 17UB,      /* TI Keystone GPHeader Image */
    UImage_TYPE_ATMELIMAGE = 18UB,   /* ATMEL ROM bootable Image */
    UImage_TYPE_SOCFPGAIMAGE = 19UB, /* Altera SOCFPGA CV/AV Preloader */
    UImage_TYPE_X86_SETUP = 20UB,    /* x86 setup.bin Image */
    UImage_TYPE_LPC32XXIMAGE = 21UB, /* x86 setup.bin Image */
    UImage_TYPE_LOADABLE = 22UB,     /* A list of typeless images */
    UImage_TYPE_RKIMAGE = 23UB,      /* Rockchip Boot Image */
    UImage_TYPE_RKSD = 24UB,         /* Rockchip SD card */
    UImage_TYPE_RKSPI = 25UB,        /* Rockchip SPI image */
    UImage_TYPE_ZYNQIMAGE = 26UB,    /* Xilinx Zynq Boot Image */
    UImage_TYPE_ZYNQMPIMAGE = 27UB,  /* Xilinx ZynqMP Boot Image */
    UImage_TYPE_ZYNQMPBIF = 28UB,    /* Xilinx ZynqMP Boot Image (bif) */
    UImage_TYPE_FPGA = 29UB,         /* FPGA Image */
    UImage_TYPE_VYBRIDIMAGE = 30UB,  /* VYBRID .vyb Image */
    UImage_TYPE_TEE = 31UB,   /* Trusted Execution Environment OS Image */
    UImage_TYPE_FIRMWARE_IVT = 32UB, /* Firmware Image with HABv4 IVT */
    /* TI Power Management Micro-Controller Firmware */
    UImage_TYPE_PMMC = 33UB,
    UImage_TYPE_STM32IMAGE = 34UB,   /* STMicroelectronics STM32 Image */
    UImage_TYPE_SOCFPGAIMAGE_V1 = 35UB, /* Altera SOCFPGA A10 Preloader */
    UImage_TYPE_MTKIMAGE = 36UB,     /* MediaTek BootROM loadable Image */
    UImage_TYPE_IMX8MIMAGE = 37UB,   /* Freescale IMX8MBoot Image */
    UImage_TYPE_IMX8IMAGE = 38UB,    /* Freescale IMX8Boot Image */
    UImage_TYPE_COPRO = 39UB,        /* Coprocessor Image for remoteproc*/
    UImage_TYPE_SUNXI_EGON = 40UB;   /* Allwinner eGON Boot Image */

/*
var UImage_TYPE_names = [
  [.UImage_TYPE_INVALID] =
  [.UImage_TYPE_STANDALONE] =
  [.UImage_TYPE_KERNEL] =
  [.UImage_TYPE_RAMDISK] =
  [.UImage_TYPE_MULTI] =
  [.UImage_TYPE_FIRMWARE] =
  [.UImage_TYPE_SCRIPT] =
  [.UImage_TYPE_FILESYSTEM] =
  [.UImage_TYPE_FLATDT] =
  [.UImage_TYPE_KWBIMAGE] =
  [.UImage_TYPE_IMXIMAGE] =
  [.UImage_TYPE_UBLIMAGE] =
  [.UImage_TYPE_OMAPIMAGE] =
  [.UImage_TYPE_AISIMAGE] =
  [.UImage_TYPE_KERNEL_NOLOAD] =
  [.UImage_TYPE_PBLIMAGE] =
  [.UImage_TYPE_MXSIMAGE] =
  [.UImage_TYPE_GPIMAGE] =
  [.UImage_TYPE_ATMELIMAGE] =
  [.UImage_TYPE_SOCFPGAIMAGE] =
  [.UImage_TYPE_X86_SETUP] =
  [.UImage_TYPE_LPC32XXIMAGE] =
  [.UImage_TYPE_LOADABLE] =
  [.UImage_TYPE_RKIMAGE] =
  [.UImage_TYPE_RKSD] =
  [.UImage_TYPE_RKSPI] =
  [.UImage_TYPE_ZYNQIMAGE] =
  [.UImage_TYPE_ZYNQMPIMAGE] =
  [.UImage_TYPE_ZYNQMPBIF] =
  [.UImage_TYPE_FPGA] =
  [.UImage_TYPE_VYBRIDIMAGE] =
  [.UImage_TYPE_TEE] =
  [.UImage_TYPE_FIRMWARE_IVT] =
  [.UImage_TYPE_PMMC] =
  [.UImage_TYPE_STM32IMAGE] =
  [.UImage_TYPE_SOCFPGAIMAGE_V1] =
  [.UImage_TYPE_MTKIMAGE] =
  [.UImage_TYPE_IMX8MIMAGE] =
  [.UImage_TYPE_IMX8IMAGE] =
  [.UImage_TYPE_COPRO] =
  [.UImage_TYPE_SUNXI_EGON] =
];
*/

var UImage_COMP_NONE = 0,    /* No Compression Used */
    UImage_COMP_GZIP = 1UB,  /* gzip Compression Used */
    UImage_COMP_BZIP2 = 2UB, /* bzip2 Compression Used */
    UImage_COMP_LZMA = 3UB,  /* lzma Compression Used */
    UImage_COMP_LZO = 4UB,   /* lzo Compression Used */
    UImage_COMP_LZ4 = 5UB,   /* lz4 Compression Used */
    UImage_COMP_ZSTD = 6UB;  /* zstd Compression Used */


type UImage_Header =
  struct
  {
    uint32 magic = 0x27051956U;
    uint32 hcrc;     /* Image header CRC checksum */
    uint32 time;     /* Image creation timestamp */
    offset<uint32,B> size; /* Image data size */
    uint32 load_adr; /* Data load address */
    uint32 ep;       /* Entry point address */
    uint32 dcrc;     /* Image data CRC checksum */
    uint8 os;        /* Operating system */
    uint8 arch;      /* CPU architecture */
    uint8 itype;     /* Image type */
    uint8 comp;      /* Compression type */
    string name :    /* Image name */
      name'length <= 32;

    uint8[32#B - name'size];

    method _print = void:
      {
      }
  };

assert(UImage_Header{}'size == 64#B);

type UImage =
  struct
  {
    UImage_Header header;
    byte[header.size] data;
  };
Generated by cgit on ageinghacker.net.
I am Luca Saiu. If you have reason to request commit access to one of these repositories please contact me. You may also send me patches by email.