diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2012-03-28 16:11:36 -0400 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2012-03-28 16:11:36 -0400 |
commit | a9aff3eaaf0966c2a1bb3717d811363d81e52c76 (patch) | |
tree | b442c3d554ff83529deb1783996f6359aebf07ab /arch/x86/boot/tools/build.c | |
parent | e47bb0bda46bf50f81671db502d0c903e0a32604 (diff) | |
parent | a51f4047758d2bcd099ea113b833ed380f4024ba (diff) |
Merge branch x86/build into x86/efi and fix up arch/x86/boot/tools/build.c
Reason for merge:
The updates to the EFI boot stub generation conflicted with the
changes to properly use the get/put_unaligned_le*() macros to
generate images.
This merge commit completes the conversion in
arch/x86/boot/tools/build.c including the places in the code
which had been changed on the x86/efi branch.
Resolved Conflicts:
arch/x86/boot/tools/build.c
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/boot/tools/build.c')
-rw-r--r-- | arch/x86/boot/tools/build.c | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index 2aeab3dc9e5f..45963889891e 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,18 +191,15 @@ 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 image */ | 201 | /* Size of image */ |
206 | *(unsigned int *)&buf[pe_header + 0x50] = file_sz; | 202 | put_unaligned_le32(file_sz, &buf[pe_header + 0x50]); |
207 | 203 | ||
208 | /* | 204 | /* |
209 | * Subtract the size of the first section (512 bytes) which | 205 | * Subtract the size of the first section (512 bytes) which |
@@ -213,42 +209,42 @@ int main(int argc, char ** argv) | |||
213 | file_sz -= 512; | 209 | file_sz -= 512; |
214 | 210 | ||
215 | /* Size of code */ | 211 | /* Size of code */ |
216 | *(unsigned int *)&buf[pe_header + 0x1c] = file_sz; | 212 | put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]); |
217 | 213 | ||
218 | #ifdef CONFIG_X86_32 | 214 | #ifdef CONFIG_X86_32 |
219 | /* Address of entry point */ | 215 | /* Address of entry point */ |
220 | *(unsigned int *)&buf[pe_header + 0x28] = i; | 216 | put_unaligned_le32(i, &buf[pe_header + 0x28]); |
221 | 217 | ||
222 | /* .text size */ | 218 | /* .text size */ |
223 | *(unsigned int *)&buf[pe_header + 0xb0] = file_sz; | 219 | put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]); |
224 | 220 | ||
225 | /* .text vma */ | 221 | /* .text vma */ |
226 | *(unsigned int *)&buf[pe_header + 0xb4] = 0x200; | 222 | put_unaligned_le32(0x200, &buf[pe_header + 0xb4]); |
227 | 223 | ||
228 | /* .text size of initialised data */ | 224 | /* .text size of initialised data */ |
229 | *(unsigned int *)&buf[pe_header + 0xb8] = file_sz; | 225 | put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]); |
230 | 226 | ||
231 | /* .text file offset */ | 227 | /* .text file offset */ |
232 | *(unsigned int *)&buf[pe_header + 0xbc] = 0x200; | 228 | put_unaligned_le32(0x200, &buf[pe_header + 0xbc]); |
233 | #else | 229 | #else |
234 | /* | 230 | /* |
235 | * Address of entry point. startup_32 is at the beginning and | 231 | * Address of entry point. startup_32 is at the beginning and |
236 | * the 64-bit entry point (startup_64) is always 512 bytes | 232 | * the 64-bit entry point (startup_64) is always 512 bytes |
237 | * after. | 233 | * after. |
238 | */ | 234 | */ |
239 | *(unsigned int *)&buf[pe_header + 0x28] = i + 512; | 235 | put_unaligned_le32(i + 512, &buf[pe_header + 0x28]); |
240 | 236 | ||
241 | /* .text size */ | 237 | /* .text size */ |
242 | *(unsigned int *)&buf[pe_header + 0xc0] = file_sz; | 238 | put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]); |
243 | 239 | ||
244 | /* .text vma */ | 240 | /* .text vma */ |
245 | *(unsigned int *)&buf[pe_header + 0xc4] = 0x200; | 241 | put_unaligned_le32(0x200, &buf[pe_header + 0xc4]); |
246 | 242 | ||
247 | /* .text size of initialised data */ | 243 | /* .text size of initialised data */ |
248 | *(unsigned int *)&buf[pe_header + 0xc8] = file_sz; | 244 | put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]); |
249 | 245 | ||
250 | /* .text file offset */ | 246 | /* .text file offset */ |
251 | *(unsigned int *)&buf[pe_header + 0xcc] = 0x200; | 247 | put_unaligned_le32(0x200, &buf[pe_header + 0xcc]); |
252 | #endif /* CONFIG_X86_32 */ | 248 | #endif /* CONFIG_X86_32 */ |
253 | #endif /* CONFIG_EFI_STUB */ | 249 | #endif /* CONFIG_EFI_STUB */ |
254 | 250 | ||
@@ -269,8 +265,9 @@ int main(int argc, char ** argv) | |||
269 | } | 265 | } |
270 | 266 | ||
271 | /* Write the CRC */ | 267 | /* Write the CRC */ |
272 | fprintf(stderr, "CRC %lx\n", crc); | 268 | fprintf(stderr, "CRC %x\n", crc); |
273 | if (fwrite(&crc, 1, 4, stdout) != 4) | 269 | put_unaligned_le32(crc, buf); |
270 | if (fwrite(buf, 1, 4, stdout) != 4) | ||
274 | die("Writing CRC failed"); | 271 | die("Writing CRC failed"); |
275 | 272 | ||
276 | close(fd); | 273 | close(fd); |