5b47f80cbb49fbf3f5974418d1ee076e14988010
[oweals/openwrt.git] / tools / mkimage / patches / 050-image_h_portability.patch
1 Some of the Linux header files are not available on non Linux host
2 systems like FreeBSD or MacOSX.
3
4 The __le32 and __be32 types are only defined in Linux in
5 asm/byteorder.h, but not on all other BSD systems.
6 Use uint32_t instead of __le32 and __be32.
7
8 __swab32 is also a Linux only function, it looks like be32_to_cpu()
9 would be better here anyway.
10
11 --- a/include/image.h
12 +++ b/include/image.h
13 @@ -16,7 +16,6 @@
14  #define __IMAGE_H__
15  
16  #include "compiler.h"
17 -#include <asm/byteorder.h>
18  #include <stdbool.h>
19  
20  /* Define this to avoid #ifdefs later on */
21 @@ -317,13 +316,13 @@ enum {
22   * all data in network byte order (aka natural aka bigendian).
23   */
24  typedef struct image_header {
25 -       __be32          ih_magic;       /* Image Header Magic Number    */
26 -       __be32          ih_hcrc;        /* Image Header CRC Checksum    */
27 -       __be32          ih_time;        /* Image Creation Timestamp     */
28 -       __be32          ih_size;        /* Image Data Size              */
29 -       __be32          ih_load;        /* Data  Load  Address          */
30 -       __be32          ih_ep;          /* Entry Point Address          */
31 -       __be32          ih_dcrc;        /* Image Data CRC Checksum      */
32 +       uint32_t        ih_magic;       /* Image Header Magic Number    */
33 +       uint32_t        ih_hcrc;        /* Image Header CRC Checksum    */
34 +       uint32_t        ih_time;        /* Image Creation Timestamp     */
35 +       uint32_t        ih_size;        /* Image Data Size              */
36 +       uint32_t        ih_load;        /* Data  Load  Address          */
37 +       uint32_t        ih_ep;          /* Entry Point Address          */
38 +       uint32_t        ih_dcrc;        /* Image Data CRC Checksum      */
39         uint8_t         ih_os;          /* Operating System             */
40         uint8_t         ih_arch;        /* CPU architecture             */
41         uint8_t         ih_type;        /* Image Type                   */
42 --- a/tools/mtk_image.h
43 +++ b/tools/mtk_image.h
44 @@ -15,8 +15,8 @@
45  union gen_boot_header {
46         struct {
47                 char name[12];
48 -               __le32 version;
49 -               __le32 size;
50 +               uint32_t version;
51 +               uint32_t size;
52         };
53  
54         uint8_t pad[0x200];
55 @@ -32,14 +32,14 @@ union nand_boot_header {
56                 char name[12];
57                 char version[4];
58                 char id[8];
59 -               __le16 ioif;
60 -               __le16 pagesize;
61 -               __le16 addrcycles;
62 -               __le16 oobsize;
63 -               __le16 pages_of_block;
64 -               __le16 numblocks;
65 -               __le16 writesize_shift;
66 -               __le16 erasesize_shift;
67 +               uint16_t ioif;
68 +               uint16_t pagesize;
69 +               uint16_t addrcycles;
70 +               uint16_t oobsize;
71 +               uint16_t pages_of_block;
72 +               uint16_t numblocks;
73 +               uint16_t writesize_shift;
74 +               uint16_t erasesize_shift;
75                 uint8_t dummy[60];
76                 uint8_t ecc_parity[28];
77         };
78 @@ -54,14 +54,14 @@ union nand_boot_header {
79  /* BootROM layout header */
80  struct brom_layout_header {
81         char name[8];
82 -       __le32 version;
83 -       __le32 header_size;
84 -       __le32 total_size;
85 -       __le32 magic;
86 -       __le32 type;
87 -       __le32 header_size_2;
88 -       __le32 total_size_2;
89 -       __le32 unused;
90 +       uint32_t version;
91 +       uint32_t header_size;
92 +       uint32_t total_size;
93 +       uint32_t magic;
94 +       uint32_t type;
95 +       uint32_t header_size_2;
96 +       uint32_t total_size_2;
97 +       uint32_t unused;
98  };
99  
100  #define BRLYT_NAME             "BRLYT"
101 @@ -90,8 +90,8 @@ struct gen_device_header {
102  struct gfh_common_header {
103         uint8_t magic[3];
104         uint8_t version;
105 -       __le16 size;
106 -       __le16 type;
107 +       uint16_t size;
108 +       uint16_t type;
109  };
110  
111  #define GFH_HEADER_MAGIC       "MMM"
112 @@ -106,17 +106,17 @@ struct gfh_common_header {
113  struct gfh_file_info {
114         struct gfh_common_header gfh;
115         char name[12];
116 -       __le32 unused;
117 -       __le16 file_type;
118 +       uint32_t unused;
119 +       uint16_t file_type;
120         uint8_t flash_type;
121         uint8_t sig_type;
122 -       __le32 load_addr;
123 -       __le32 total_size;
124 -       __le32 max_size;
125 -       __le32 hdr_size;
126 -       __le32 sig_size;
127 -       __le32 jump_offset;
128 -       __le32 processed;
129 +       uint32_t load_addr;
130 +       uint32_t total_size;
131 +       uint32_t max_size;
132 +       uint32_t hdr_size;
133 +       uint32_t sig_size;
134 +       uint32_t jump_offset;
135 +       uint32_t processed;
136  };
137  
138  #define GFH_FILE_INFO_NAME     "FILE_INFO"
139 @@ -129,16 +129,16 @@ struct gfh_file_info {
140  
141  struct gfh_bl_info {
142         struct gfh_common_header gfh;
143 -       __le32 attr;
144 +       uint32_t attr;
145  };
146  
147  struct gfh_brom_cfg {
148         struct gfh_common_header gfh;
149 -       __le32 cfg_bits;
150 -       __le32 usbdl_by_auto_detect_timeout_ms;
151 +       uint32_t cfg_bits;
152 +       uint32_t usbdl_by_auto_detect_timeout_ms;
153         uint8_t unused[0x48];
154 -       __le32 usbdl_by_kcol0_timeout_ms;
155 -       __le32 usbdl_by_flag_timeout_ms;
156 +       uint32_t usbdl_by_kcol0_timeout_ms;
157 +       uint32_t usbdl_by_flag_timeout_ms;
158         uint32_t pad;
159  };
160  
161 @@ -157,15 +157,15 @@ struct gfh_anti_clone {
162         uint8_t ac_b2k;
163         uint8_t ac_b2c;
164         uint16_t pad;
165 -       __le32 ac_offset;
166 -       __le32 ac_len;
167 +       uint32_t ac_offset;
168 +       uint32_t ac_len;
169  };
170  
171  struct gfh_brom_sec_cfg {
172         struct gfh_common_header gfh;
173 -       __le32 cfg_bits;
174 +       uint32_t cfg_bits;
175         char customer_name[0x20];
176 -       __le32 pad;
177 +       uint32_t pad;
178  };
179  
180  #define BROM_SEC_CFG_JTAG_EN   1
181 @@ -184,11 +184,11 @@ struct gfh_header {
182  
183  union lk_hdr {
184         struct {
185 -               __le32 magic;
186 -               __le32 size;
187 +               uint32_t magic;
188 +               uint32_t size;
189                 char name[32];
190 -               __le32 loadaddr;
191 -               __le32 mode;
192 +               uint32_t loadaddr;
193 +               uint32_t mode;
194         };
195  
196         uint8_t data[512];
197 --- a/tools/zynqmpbif.c
198 +++ b/tools/zynqmpbif.c
199 @@ -517,7 +517,7 @@ static int bif_add_bit(struct bif_entry
200         debug("Bitstream Length: 0x%x\n", bitlen);
201         for (i = 0; i < bitlen; i += sizeof(uint32_t)) {
202                 uint32_t *bitbin32 = (uint32_t *)&bitbin[i];
203 -               *bitbin32 = __swab32(*bitbin32);
204 +               *bitbin32 = be32_to_cpu(*bitbin32);
205         }
206  
207         if (!bf->dest_dev)