Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'efi-arm-no-relocate-for-rmk' of git://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux into misc

Simplify EFI handover to decompressor

The EFI stub in the ARM kernel runs in the context of the firmware, which
means it usually runs with the caches and MMU on. Currently, we relocate
the zImage so it appears in the first 128 MiB, disable the MMU and caches
and invoke the decompressor via its ordinary entry point. However, since we
can pass the base of DRAM directly, there is no need to relocate the zImage,
which also means there is no need to disable and re-enable the caches and
create new page tables etc.

This also allows systems whose DRAM start address is not a round multiple
of 128 MB to decompress the kernel proper to the base of memory, ensuring
that all memory is usable at runtime.

+44 -87
+33 -48
arch/arm/boot/compressed/head.S
··· 287 287 */ 288 288 mov r0, pc 289 289 cmp r0, r4 290 - ldrcc r0, LC0+28 290 + ldrcc r0, .Lheadroom 291 291 addcc r0, r0, pc 292 292 cmpcc r4, r0 293 293 orrcc r4, r4, #1 @ remember we skipped cache_on 294 294 blcs cache_on 295 295 296 - restart: adr r0, LC0 297 - ldmia r0, {r1, r2, r3, r6, r11, r12} 298 - ldr sp, [r0, #24] 299 - 300 - /* 301 - * We might be running at a different address. We need 302 - * to fix up various pointers. 303 - */ 304 - sub r0, r0, r1 @ calculate the delta offset 305 - add r6, r6, r0 @ _edata 296 + restart: adr r0, LC1 297 + ldr sp, [r0] 298 + ldr r6, [r0, #4] 299 + add sp, sp, r0 300 + add r6, r6, r0 306 301 307 302 get_inflated_image_size r9, r10, lr 308 303 309 304 #ifndef CONFIG_ZBOOT_ROM 310 305 /* malloc space is above the relocated stack (64k max) */ 311 - add sp, sp, r0 312 306 add r10, sp, #0x10000 313 307 #else 314 308 /* ··· 316 322 mov r5, #0 @ init dtb size to 0 317 323 #ifdef CONFIG_ARM_APPENDED_DTB 318 324 /* 319 - * r0 = delta 320 - * r2 = BSS start 321 - * r3 = BSS end 322 325 * r4 = final kernel address (possibly with LSB set) 323 326 * r5 = appended dtb size (still unknown) 324 327 * r6 = _edata ··· 323 332 * r8 = atags/device tree pointer 324 333 * r9 = size of decompressed image 325 334 * r10 = end of this image, including bss/stack/malloc space if non XIP 326 - * r11 = GOT start 327 - * r12 = GOT end 328 335 * sp = stack pointer 329 336 * 330 337 * if there are device trees (dtb) appended to zImage, advance r10 so that the ··· 370 381 /* temporarily relocate the stack past the DTB work space */ 371 382 add sp, sp, r5 372 383 373 - stmfd sp!, {r0-r3, ip, lr} 374 384 mov r0, r8 375 385 mov r1, r6 376 386 mov r2, r5 ··· 388 400 mov r2, r5 389 401 bleq atags_to_fdt 390 402 391 - ldmfd sp!, {r0-r3, ip, lr} 392 403 sub sp, sp, r5 393 404 #endif 394 405 ··· 524 537 mov pc, r0 525 538 526 539 wont_overwrite: 540 + adr r0, LC0 541 + ldmia r0, {r1, r2, r3, r11, r12} 542 + sub r0, r0, r1 @ calculate the delta offset 543 + 527 544 /* 528 545 * If delta is zero, we are running at the address we were linked at. 529 546 * r0 = delta ··· 651 660 LC0: .word LC0 @ r1 652 661 .word __bss_start @ r2 653 662 .word _end @ r3 654 - .word _edata @ r6 655 663 .word _got_start @ r11 656 664 .word _got_end @ ip 657 - .word .L_user_stack_end @ sp 658 - .word _end - restart + 16384 + 1024*1024 659 665 .size LC0, . - LC0 666 + 667 + .type LC1, #object 668 + LC1: .word .L_user_stack_end - LC1 @ sp 669 + .word _edata - LC1 @ r6 670 + .size LC1, . - LC1 671 + 672 + .Lheadroom: 673 + .word _end - restart + 16384 + 1024*1024 660 674 661 675 .Linflated_image_size_offset: 662 676 .long (input_data_end - 4) - . ··· 1430 1434 1431 1435 #ifdef CONFIG_EFI_STUB 1432 1436 ENTRY(efi_enter_kernel) 1433 - mov r7, r0 @ preserve image base 1434 - mov r4, r1 @ preserve DT pointer 1437 + mov r4, r0 @ preserve image base 1438 + mov r8, r1 @ preserve DT pointer 1435 1439 1436 - mov r0, r4 @ DT start 1437 - add r1, r4, r2 @ DT end 1440 + mrc p15, 0, r0, c1, c0, 0 @ read SCTLR 1441 + tst r0, #0x1 @ MMU enabled? 1442 + orreq r4, r4, #1 @ set LSB if not 1443 + 1444 + mov r0, r8 @ DT start 1445 + add r1, r8, r2 @ DT end 1438 1446 bl cache_clean_flush 1439 1447 1440 - mov r0, r7 @ relocated zImage 1441 - ldr r1, =_edata @ size of zImage 1442 - add r1, r1, r0 @ end of zImage 1443 - bl cache_clean_flush 1448 + adr r0, 0f @ switch to our stack 1449 + ldr sp, [r0] 1450 + add sp, sp, r0 1444 1451 1445 - @ The PE/COFF loader might not have cleaned the code we are 1446 - @ running beyond the PoU, and so calling cache_off below from 1447 - @ inside the PE/COFF loader allocated region is unsafe unless 1448 - @ we explicitly clean it to the PoC. 1449 - adr r0, call_cache_fn @ region of code we will 1450 - adr r1, 0f @ run with MMU off 1451 - bl cache_clean_flush 1452 - bl cache_off 1453 - 1454 - @ Set parameters for booting zImage according to boot protocol 1455 - @ put FDT address in r2, it was returned by efi_entry() 1456 - @ r1 is the machine type, and r0 needs to be 0 1457 - mov r0, #0 1458 - mov r1, #0xFFFFFFFF 1459 - mov r2, r4 1460 - add r7, r7, #(__efi_start - start) 1461 - mov pc, r7 @ no mode switch 1452 + mov r5, #0 @ appended DTB size 1453 + mov r7, #0xFFFFFFFF @ machine ID 1454 + b wont_overwrite 1462 1455 ENDPROC(efi_enter_kernel) 1463 - 0: 1456 + 0: .long .L_user_stack_end - . 1464 1457 #endif 1465 1458 1466 1459 .align
+5
arch/arm/boot/compressed/vmlinux.lds.S
··· 63 63 _etext = .; 64 64 65 65 .got.plt : { *(.got.plt) } 66 + #ifndef CONFIG_EFI_STUB 66 67 _got_start = .; 67 68 .got : { *(.got) } 68 69 _got_end = .; 70 + #endif 69 71 70 72 /* ensure the zImage file size is always a multiple of 64 bits */ 71 73 /* (without a dummy byte, ld just ignores the empty section) */ ··· 76 74 #ifdef CONFIG_EFI_STUB 77 75 .data : ALIGN(4096) { 78 76 __pecoff_data_start = .; 77 + _got_start = .; 78 + *(.got) 79 + _got_end = .; 79 80 /* 80 81 * The EFI stub always executes from RAM, and runs strictly before the 81 82 * decompressor, so we can make an exception for its r/w data, and keep it
+6 -39
drivers/firmware/efi/libstub/arm32-stub.c
··· 199 199 unsigned long kernel_base; 200 200 efi_status_t status; 201 201 202 - /* 203 - * Verify that the DRAM base address is compatible with the ARM 204 - * boot protocol, which determines the base of DRAM by masking 205 - * off the low 27 bits of the address at which the zImage is 206 - * loaded. These assumptions are made by the decompressor, 207 - * before any memory map is available. 208 - */ 209 - kernel_base = round_up(dram_base, SZ_128M); 202 + /* use a 16 MiB aligned base for the decompressed kernel */ 203 + kernel_base = round_up(dram_base, SZ_16M) + TEXT_OFFSET; 210 204 211 205 /* 212 206 * Note that some platforms (notably, the Raspberry Pi 2) put ··· 209 215 * base of the kernel image is only partially used at the moment. 210 216 * (Up to 5 pages are used for the swapper page tables) 211 217 */ 212 - kernel_base += TEXT_OFFSET - 5 * PAGE_SIZE; 213 - 214 - status = reserve_kernel_base(kernel_base, reserve_addr, reserve_size); 218 + status = reserve_kernel_base(kernel_base - 5 * PAGE_SIZE, reserve_addr, 219 + reserve_size); 215 220 if (status != EFI_SUCCESS) { 216 221 pr_efi_err("Unable to allocate memory for uncompressed kernel.\n"); 217 222 return status; 218 223 } 219 224 220 - /* 221 - * Relocate the zImage, so that it appears in the lowest 128 MB 222 - * memory window. 223 - */ 224 - *image_addr = (unsigned long)image->image_base; 225 - *image_size = image->image_size; 226 - status = efi_relocate_kernel(image_addr, *image_size, *image_size, 227 - kernel_base + MAX_UNCOMP_KERNEL_SIZE, 0, 0); 228 - if (status != EFI_SUCCESS) { 229 - pr_efi_err("Failed to relocate kernel.\n"); 230 - efi_free(*reserve_size, *reserve_addr); 231 - *reserve_size = 0; 232 - return status; 233 - } 234 - 235 - /* 236 - * Check to see if we were able to allocate memory low enough 237 - * in memory. The kernel determines the base of DRAM from the 238 - * address at which the zImage is loaded. 239 - */ 240 - if (*image_addr + *image_size > dram_base + ZIMAGE_OFFSET_LIMIT) { 241 - pr_efi_err("Failed to relocate kernel, no low memory available.\n"); 242 - efi_free(*reserve_size, *reserve_addr); 243 - *reserve_size = 0; 244 - efi_free(*image_size, *image_addr); 245 - *image_size = 0; 246 - return EFI_LOAD_ERROR; 247 - } 225 + *image_addr = kernel_base; 226 + *image_size = 0; 248 227 return EFI_SUCCESS; 249 228 }