diff options
Diffstat (limited to 'arch/x86/boot/tools/build.c')
-rw-r--r-- | arch/x86/boot/tools/build.c | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index ed549767a231..3f61f6e2b46f 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c | |||
@@ -198,35 +198,60 @@ int main(int argc, char ** argv) | |||
198 | 198 | ||
199 | pe_header = get_unaligned_le32(&buf[0x3c]); | 199 | pe_header = get_unaligned_le32(&buf[0x3c]); |
200 | 200 | ||
201 | /* Size of code */ | ||
202 | put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]); | ||
203 | |||
204 | /* Size of image */ | 201 | /* Size of image */ |
205 | put_unaligned_le32(file_sz, &buf[pe_header + 0x50]); | 202 | put_unaligned_le32(file_sz, &buf[pe_header + 0x50]); |
206 | 203 | ||
204 | /* | ||
205 | * Subtract the size of the first section (512 bytes) which | ||
206 | * includes the header and .reloc section. The remaining size | ||
207 | * is that of the .text section. | ||
208 | */ | ||
209 | file_sz -= 512; | ||
210 | |||
211 | /* Size of code */ | ||
212 | put_unaligned_le32(file_sz, &buf[pe_header + 0x1c]); | ||
213 | |||
207 | #ifdef CONFIG_X86_32 | 214 | #ifdef CONFIG_X86_32 |
208 | /* Address of entry point */ | 215 | /* |
209 | put_unaligned_le32(i, &buf[pe_header + 0x28]); | 216 | * Address of entry point. |
217 | * | ||
218 | * The EFI stub entry point is +16 bytes from the start of | ||
219 | * the .text section. | ||
220 | */ | ||
221 | put_unaligned_le32(i + 16, &buf[pe_header + 0x28]); | ||
210 | 222 | ||
211 | /* .text size */ | 223 | /* .text size */ |
212 | put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]); | 224 | put_unaligned_le32(file_sz, &buf[pe_header + 0xb0]); |
213 | 225 | ||
226 | /* .text vma */ | ||
227 | put_unaligned_le32(0x200, &buf[pe_header + 0xb4]); | ||
228 | |||
214 | /* .text size of initialised data */ | 229 | /* .text size of initialised data */ |
215 | put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]); | 230 | put_unaligned_le32(file_sz, &buf[pe_header + 0xb8]); |
231 | |||
232 | /* .text file offset */ | ||
233 | put_unaligned_le32(0x200, &buf[pe_header + 0xbc]); | ||
216 | #else | 234 | #else |
217 | /* | 235 | /* |
218 | * Address of entry point. startup_32 is at the beginning and | 236 | * Address of entry point. startup_32 is at the beginning and |
219 | * the 64-bit entry point (startup_64) is always 512 bytes | 237 | * the 64-bit entry point (startup_64) is always 512 bytes |
220 | * after. | 238 | * after. The EFI stub entry point is 16 bytes after that, as |
239 | * the first instruction allows legacy loaders to jump over | ||
240 | * the EFI stub initialisation | ||
221 | */ | 241 | */ |
222 | put_unaligned_le32(i + 512, &buf[pe_header + 0x28]); | 242 | put_unaligned_le32(i + 528, &buf[pe_header + 0x28]); |
223 | 243 | ||
224 | /* .text size */ | 244 | /* .text size */ |
225 | put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]); | 245 | put_unaligned_le32(file_sz, &buf[pe_header + 0xc0]); |
226 | 246 | ||
247 | /* .text vma */ | ||
248 | put_unaligned_le32(0x200, &buf[pe_header + 0xc4]); | ||
249 | |||
227 | /* .text size of initialised data */ | 250 | /* .text size of initialised data */ |
228 | put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]); | 251 | put_unaligned_le32(file_sz, &buf[pe_header + 0xc8]); |
229 | 252 | ||
253 | /* .text file offset */ | ||
254 | put_unaligned_le32(0x200, &buf[pe_header + 0xcc]); | ||
230 | #endif /* CONFIG_X86_32 */ | 255 | #endif /* CONFIG_X86_32 */ |
231 | #endif /* CONFIG_EFI_STUB */ | 256 | #endif /* CONFIG_EFI_STUB */ |
232 | 257 | ||