aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/boot/tools/build.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 4e9bd6bcafa6..f2ac95ece0cc 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -34,6 +34,7 @@
34#include <fcntl.h> 34#include <fcntl.h>
35#include <sys/mman.h> 35#include <sys/mman.h>
36#include <asm/boot.h> 36#include <asm/boot.h>
37#include <tools/le_byteshift.h>
37 38
38typedef unsigned char u8; 39typedef unsigned char u8;
39typedef unsigned short u16; 40typedef unsigned short u16;
@@ -41,6 +42,7 @@ typedef unsigned long u32;
41 42
42#define DEFAULT_MAJOR_ROOT 0 43#define DEFAULT_MAJOR_ROOT 0
43#define DEFAULT_MINOR_ROOT 0 44#define DEFAULT_MINOR_ROOT 0
45#define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT)
44 46
45/* Minimal number of setup sectors */ 47/* Minimal number of setup sectors */
46#define SETUP_SECT_MIN 5 48#define SETUP_SECT_MIN 5
@@ -159,7 +161,7 @@ int main(int argc, char ** argv)
159 die("read-error on `setup'"); 161 die("read-error on `setup'");
160 if (c < 1024) 162 if (c < 1024)
161 die("The setup must be at least 1024 bytes"); 163 die("The setup must be at least 1024 bytes");
162 if (buf[510] != 0x55 || buf[511] != 0xaa) 164 if (get_unaligned_le16(&buf[510]) != 0xAA55)
163 die("Boot block hasn't got boot flag (0xAA55)"); 165 die("Boot block hasn't got boot flag (0xAA55)");
164 fclose(file); 166 fclose(file);
165 167
@@ -171,8 +173,7 @@ int main(int argc, char ** argv)
171 memset(buf+c, 0, i-c); 173 memset(buf+c, 0, i-c);
172 174
173 /* Set the default root device */ 175 /* Set the default root device */
174 buf[508] = DEFAULT_MINOR_ROOT; 176 put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]);
175 buf[509] = DEFAULT_MAJOR_ROOT;
176 177
177 fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i); 178 fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i);
178 179
@@ -192,44 +193,42 @@ int main(int argc, char ** argv)
192 193
193 /* Patch the setup code with the appropriate size parameters */ 194 /* Patch the setup code with the appropriate size parameters */
194 buf[0x1f1] = setup_sectors-1; 195 buf[0x1f1] = setup_sectors-1;
195 buf[0x1f4] = sys_size; 196 put_unaligned_le32(sys_size, &buf[0x1f4]);
196 buf[0x1f5] = sys_size >> 8;
197 buf[0x1f6] = sys_size >> 16;
198 buf[0x1f7] = sys_size >> 24;
199 197
200#ifdef CONFIG_EFI_STUB 198#ifdef CONFIG_EFI_STUB
201 file_sz = sz + i + ((sys_size * 16) - sz); 199 file_sz = sz + i + ((sys_size * 16) - sz);
202 200
203 pe_header = *(unsigned int *)&buf[0x3c]; 201 pe_header = get_unaligned_le32(&buf[0x3c]);
204 202
205 /* Size of code */ 203 /* Size of code */
206 *(unsigned int *)&buf[pe_header + 0x1c] = file_sz; 204 put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]);
207 205
208 /* Size of image */ 206 /* Size of image */
209 *(unsigned int *)&buf[pe_header + 0x50] = file_sz; 207 put_unaligned_le32(file_sz, &buf[pe_header + 0x50]);
210 208
211#ifdef CONFIG_X86_32 209#ifdef CONFIG_X86_32
212 /* Address of entry point */ 210 /* Address of entry point */
213 *(unsigned int *)&buf[pe_header + 0x28] = i; 211 put_unaligned_le32(i, &buf[pe_header + 0x28]);
214 212
215 /* .text size */ 213 /* .text size */
216 *(unsigned int *)&buf[pe_header + 0xb0] = file_sz; 214 put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]);
217 215
218 /* .text size of initialised data */ 216 /* .text size of initialised data */
219 *(unsigned int *)&buf[pe_header + 0xb8] = file_sz; 217 put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]);
220#else 218#else
221 /* 219 /*
222 * Address of entry point. startup_32 is at the beginning and 220 * Address of entry point. startup_32 is at the beginning and
223 * the 64-bit entry point (startup_64) is always 512 bytes 221 * the 64-bit entry point (startup_64) is always 512 bytes
224 * after. 222 * after.
225 */ 223 */
226 *(unsigned int *)&buf[pe_header + 0x28] = i + 512; 224 put_unaligned_le32(i + 512, &buf[pe_header + 0x28]);
227 225
228 /* .text size */ 226 /* .text size */
229 *(unsigned int *)&buf[pe_header + 0xc0] = file_sz; 227 put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]);
230 228
231 /* .text size of initialised data */ 229 /* .text size of initialised data */
232 *(unsigned int *)&buf[pe_header + 0xc8] = file_sz; 230 put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]);
231
233#endif /* CONFIG_X86_32 */ 232#endif /* CONFIG_X86_32 */
234#endif /* CONFIG_EFI_STUB */ 233#endif /* CONFIG_EFI_STUB */
235 234