tools: otrx: allow own magic
[project/firmware-utils.git] / src / fw.h
1 /*
2 * * Copyright (C) 2007 Ubiquiti Networks, Inc.
3 * *
4 * * This program is free software; you can redistribute it and/or
5 * * modify it under the terms of the GNU General Public License as
6 * * published by the Free Software Foundation; either version 2 of the
7 * * License, or (at your option) any later version.
8 * *
9 * * This program is distributed in the hope that it will be useful, but
10 * * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * * General Public License for more details.
13 * *
14 * * You should have received a copy of the GNU General Public License
15 * * along with this program; if not, write to the Free Software
16 * * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 * */
18
19 #ifndef FW_INCLUDED
20 #define FW_INCLUDED
21
22 #include <stdint.h>
23 #include <sys/types.h>
24
25 #define MAGIC_HEADER "OPEN"
26 #define MAGIC_PART "PART"
27 #define MAGIC_END "END."
28 #define MAGIC_ENDS "ENDS"
29
30 #define MAGIC_LENGTH 4
31 #define PART_NAME_LENGTH 16
32
33 typedef struct header {
34 uint8_t magic[MAGIC_LENGTH];
35 uint8_t version[256];
36 u_int32_t crc;
37 u_int32_t pad;
38 } __attribute__ ((packed)) header_t;
39
40 typedef struct part {
41 uint8_t magic[MAGIC_LENGTH];
42 uint8_t name[PART_NAME_LENGTH];
43 uint8_t pad[12];
44 u_int32_t memaddr;
45 u_int32_t index;
46 u_int32_t baseaddr;
47 u_int32_t entryaddr;
48 u_int32_t data_size;
49 u_int32_t part_size;
50 } __attribute__ ((packed)) part_t;
51
52 typedef struct part_crc {
53 u_int32_t crc;
54 u_int32_t pad;
55 } __attribute__ ((packed)) part_crc_t;
56
57 typedef struct signature {
58 uint8_t magic[MAGIC_LENGTH];
59 u_int32_t crc;
60 u_int32_t pad;
61 } __attribute__ ((packed)) signature_t;
62
63 typedef struct signature_rsa {
64 uint8_t magic[MAGIC_LENGTH];
65 // u_int32_t crc;
66 unsigned char rsa_signature[256];
67 u_int32_t pad;
68 } __attribute__ ((packed)) signature_rsa_t;
69
70 #define VERSION "1.2"
71
72 #define INFO(...) fprintf(stdout, __VA_ARGS__)
73 #define ERROR(...) fprintf(stderr, "ERROR: "__VA_ARGS__)
74 #define WARN(...) fprintf(stderr, "WARN: "__VA_ARGS__)
75 #define DEBUG(...) do {\
76 if (debug) \
77 fprintf(stdout, "DEBUG: "__VA_ARGS__); \
78 } while (0);
79
80 #endif