diff options
Diffstat (limited to 'arch/x86/boot/tools/build.c')
-rw-r--r-- | arch/x86/boot/tools/build.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index 4e9bd6bcafa6..ed549767a231 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c | |||
@@ -29,18 +29,18 @@ | |||
29 | #include <stdarg.h> | 29 | #include <stdarg.h> |
30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
32 | #include <sys/sysmacros.h> | ||
33 | #include <unistd.h> | 32 | #include <unistd.h> |
34 | #include <fcntl.h> | 33 | #include <fcntl.h> |
35 | #include <sys/mman.h> | 34 | #include <sys/mman.h> |
36 | #include <asm/boot.h> | 35 | #include <tools/le_byteshift.h> |
37 | 36 | ||
38 | typedef unsigned char u8; | 37 | typedef unsigned char u8; |
39 | typedef unsigned short u16; | 38 | typedef unsigned short u16; |
40 | typedef unsigned long u32; | 39 | typedef unsigned int u32; |
41 | 40 | ||
42 | #define DEFAULT_MAJOR_ROOT 0 | 41 | #define DEFAULT_MAJOR_ROOT 0 |
43 | #define DEFAULT_MINOR_ROOT 0 | 42 | #define DEFAULT_MINOR_ROOT 0 |
43 | #define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT) | ||
44 | 44 | ||
45 | /* Minimal number of setup sectors */ | 45 | /* Minimal number of setup sectors */ |
46 | #define SETUP_SECT_MIN 5 | 46 | #define SETUP_SECT_MIN 5 |
@@ -159,7 +159,7 @@ int main(int argc, char ** argv) | |||
159 | die("read-error on `setup'"); | 159 | die("read-error on `setup'"); |
160 | if (c < 1024) | 160 | if (c < 1024) |
161 | die("The setup must be at least 1024 bytes"); | 161 | die("The setup must be at least 1024 bytes"); |
162 | if (buf[510] != 0x55 || buf[511] != 0xaa) | 162 | if (get_unaligned_le16(&buf[510]) != 0xAA55) |
163 | die("Boot block hasn't got boot flag (0xAA55)"); | 163 | die("Boot block hasn't got boot flag (0xAA55)"); |
164 | fclose(file); | 164 | fclose(file); |
165 | 165 | ||
@@ -171,8 +171,7 @@ int main(int argc, char ** argv) | |||
171 | memset(buf+c, 0, i-c); | 171 | memset(buf+c, 0, i-c); |
172 | 172 | ||
173 | /* Set the default root device */ | 173 | /* Set the default root device */ |
174 | buf[508] = DEFAULT_MINOR_ROOT; | 174 | put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); |
175 | buf[509] = DEFAULT_MAJOR_ROOT; | ||
176 | 175 | ||
177 | fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i); | 176 | fprintf(stderr, "Setup is %d bytes (padded to %d bytes).\n", c, i); |
178 | 177 | ||
@@ -192,44 +191,42 @@ int main(int argc, char ** argv) | |||
192 | 191 | ||
193 | /* Patch the setup code with the appropriate size parameters */ | 192 | /* Patch the setup code with the appropriate size parameters */ |
194 | buf[0x1f1] = setup_sectors-1; | 193 | buf[0x1f1] = setup_sectors-1; |
195 | buf[0x1f4] = sys_size; | 194 | 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 | 195 | ||
200 | #ifdef CONFIG_EFI_STUB | 196 | #ifdef CONFIG_EFI_STUB |
201 | file_sz = sz + i + ((sys_size * 16) - sz); | 197 | file_sz = sz + i + ((sys_size * 16) - sz); |
202 | 198 | ||
203 | pe_header = *(unsigned int *)&buf[0x3c]; | 199 | pe_header = get_unaligned_le32(&buf[0x3c]); |
204 | 200 | ||
205 | /* Size of code */ | 201 | /* Size of code */ |
206 | *(unsigned int *)&buf[pe_header + 0x1c] = file_sz; | 202 | put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]); |
207 | 203 | ||
208 | /* Size of image */ | 204 | /* Size of image */ |
209 | *(unsigned int *)&buf[pe_header + 0x50] = file_sz; | 205 | put_unaligned_le32(file_sz, &buf[pe_header + 0x50]); |
210 | 206 | ||
211 | #ifdef CONFIG_X86_32 | 207 | #ifdef CONFIG_X86_32 |
212 | /* Address of entry point */ | 208 | /* Address of entry point */ |
213 | *(unsigned int *)&buf[pe_header + 0x28] = i; | 209 | put_unaligned_le32(i, &buf[pe_header + 0x28]); |
214 | 210 | ||
215 | /* .text size */ | 211 | /* .text size */ |
216 | *(unsigned int *)&buf[pe_header + 0xb0] = file_sz; | 212 | put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]); |
217 | 213 | ||
218 | /* .text size of initialised data */ | 214 | /* .text size of initialised data */ |
219 | *(unsigned int *)&buf[pe_header + 0xb8] = file_sz; | 215 | put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]); |
220 | #else | 216 | #else |
221 | /* | 217 | /* |
222 | * Address of entry point. startup_32 is at the beginning and | 218 | * Address of entry point. startup_32 is at the beginning and |
223 | * the 64-bit entry point (startup_64) is always 512 bytes | 219 | * the 64-bit entry point (startup_64) is always 512 bytes |
224 | * after. | 220 | * after. |
225 | */ | 221 | */ |
226 | *(unsigned int *)&buf[pe_header + 0x28] = i + 512; | 222 | put_unaligned_le32(i + 512, &buf[pe_header + 0x28]); |
227 | 223 | ||
228 | /* .text size */ | 224 | /* .text size */ |
229 | *(unsigned int *)&buf[pe_header + 0xc0] = file_sz; | 225 | put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]); |
230 | 226 | ||
231 | /* .text size of initialised data */ | 227 | /* .text size of initialised data */ |
232 | *(unsigned int *)&buf[pe_header + 0xc8] = file_sz; | 228 | put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]); |
229 | |||
233 | #endif /* CONFIG_X86_32 */ | 230 | #endif /* CONFIG_X86_32 */ |
234 | #endif /* CONFIG_EFI_STUB */ | 231 | #endif /* CONFIG_EFI_STUB */ |
235 | 232 | ||
@@ -250,8 +247,9 @@ int main(int argc, char ** argv) | |||
250 | } | 247 | } |
251 | 248 | ||
252 | /* Write the CRC */ | 249 | /* Write the CRC */ |
253 | fprintf(stderr, "CRC %lx\n", crc); | 250 | fprintf(stderr, "CRC %x\n", crc); |
254 | if (fwrite(&crc, 1, 4, stdout) != 4) | 251 | put_unaligned_le32(crc, buf); |
252 | if (fwrite(buf, 1, 4, stdout) != 4) | ||
255 | die("Writing CRC failed"); | 253 | die("Writing CRC failed"); |
256 | 254 | ||
257 | close(fd); | 255 | close(fd); |