Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 1 | ================= |
| 2 | The EFI Boot Stub |
| 3 | ================= |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 4 | |
Roy Franz | 719e284 | 2013-09-28 08:44:21 -0700 | [diff] [blame] | 5 | On the x86 and ARM platforms, a kernel zImage/bzImage can masquerade |
| 6 | as a PE/COFF image, thereby convincing EFI firmware loaders to load |
| 7 | it as an EFI executable. The code that modifies the bzImage header, |
| 8 | along with the EFI-specific entry point that the firmware loader |
| 9 | jumps to are collectively known as the "EFI boot stub", and live in |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 10 | arch/x86/boot/header.S and arch/x86/boot/compressed/eboot.c, |
Roy Franz | 719e284 | 2013-09-28 08:44:21 -0700 | [diff] [blame] | 11 | respectively. For ARM the EFI stub is implemented in |
| 12 | arch/arm/boot/compressed/efi-header.S and |
| 13 | arch/arm/boot/compressed/efi-stub.c. EFI stub code that is shared |
Alan Ott | 3bb9eee | 2015-11-30 09:36:54 -0500 | [diff] [blame] | 14 | between architectures is in drivers/firmware/efi/libstub. |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 15 | |
Mark Salter | cdd7857 | 2013-11-29 16:00:14 -0500 | [diff] [blame] | 16 | For arm64, there is no compressed kernel support, so the Image itself |
| 17 | masquerades as a PE/COFF image and the EFI stub is linked into the |
| 18 | kernel. The arm64 EFI stub lives in arch/arm64/kernel/efi-entry.S |
Alan Ott | 3bb9eee | 2015-11-30 09:36:54 -0500 | [diff] [blame] | 19 | and drivers/firmware/efi/libstub/arm64-stub.c. |
Mark Salter | cdd7857 | 2013-11-29 16:00:14 -0500 | [diff] [blame] | 20 | |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 21 | By using the EFI boot stub it's possible to boot a Linux kernel |
| 22 | without the use of a conventional EFI boot loader, such as grub or |
| 23 | elilo. Since the EFI boot stub performs the jobs of a boot loader, in |
| 24 | a certain sense it *IS* the boot loader. |
| 25 | |
| 26 | The EFI boot stub is enabled with the CONFIG_EFI_STUB kernel option. |
| 27 | |
| 28 | |
Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 29 | How to install bzImage.efi |
| 30 | -------------------------- |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 31 | |
| 32 | The bzImage located in arch/x86/boot/bzImage must be copied to the EFI |
Silvan Jegen | bf65188 | 2013-12-18 20:16:31 +0100 | [diff] [blame] | 33 | System Partition (ESP) and renamed with the extension ".efi". Without |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 34 | the extension the EFI firmware loader will refuse to execute it. It's |
| 35 | not possible to execute bzImage.efi from the usual Linux file systems |
Roy Franz | 719e284 | 2013-09-28 08:44:21 -0700 | [diff] [blame] | 36 | because EFI firmware doesn't have support for them. For ARM the |
| 37 | arch/arm/boot/zImage should be copied to the system partition, and it |
Mark Salter | cdd7857 | 2013-11-29 16:00:14 -0500 | [diff] [blame] | 38 | may not need to be renamed. Similarly for arm64, arch/arm64/boot/Image |
| 39 | should be copied but not necessarily renamed. |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 40 | |
| 41 | |
Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 42 | Passing kernel parameters from the EFI shell |
| 43 | -------------------------------------------- |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 44 | |
Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 45 | Arguments to the kernel can be passed after bzImage.efi, e.g.:: |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 46 | |
| 47 | fs0:> bzImage.efi console=ttyS0 root=/dev/sda4 |
| 48 | |
| 49 | |
Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 50 | The "initrd=" option |
| 51 | -------------------- |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 52 | |
| 53 | Like most boot loaders, the EFI stub allows the user to specify |
| 54 | multiple initrd files using the "initrd=" option. This is the only EFI |
| 55 | stub-specific command line parameter, everything else is passed to the |
| 56 | kernel when it boots. |
| 57 | |
| 58 | The path to the initrd file must be an absolute path from the |
| 59 | beginning of the ESP, relative path names do not work. Also, the path |
| 60 | is an EFI-style path and directory elements must be separated with |
Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 61 | backslashes (\). For example, given the following directory layout:: |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 62 | |
Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 63 | fs0:> |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 64 | Kernels\ |
| 65 | bzImage.efi |
| 66 | initrd-large.img |
| 67 | |
| 68 | Ramdisks\ |
| 69 | initrd-small.img |
| 70 | initrd-medium.img |
| 71 | |
| 72 | to boot with the initrd-large.img file if the current working |
Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 73 | directory is fs0:\Kernels, the following command must be used:: |
Matt Fleming | 0c75966 | 2012-03-16 12:03:13 +0000 | [diff] [blame] | 74 | |
| 75 | fs0:\Kernels> bzImage.efi initrd=\Kernels\initrd-large.img |
| 76 | |
| 77 | Notice how bzImage.efi can be specified with a relative path. That's |
| 78 | because the image we're executing is interpreted by the EFI shell, |
| 79 | which understands relative paths, whereas the rest of the command line |
| 80 | is passed to bzImage.efi. |
Roy Franz | 719e284 | 2013-09-28 08:44:21 -0700 | [diff] [blame] | 81 | |
| 82 | |
Mauro Carvalho Chehab | ef16bcc | 2017-05-14 13:19:44 -0300 | [diff] [blame] | 83 | The "dtb=" option |
| 84 | ----------------- |
Roy Franz | 719e284 | 2013-09-28 08:44:21 -0700 | [diff] [blame] | 85 | |
Mark Salter | cdd7857 | 2013-11-29 16:00:14 -0500 | [diff] [blame] | 86 | For the ARM and arm64 architectures, we also need to be able to provide a |
| 87 | device tree to the kernel. This is done with the "dtb=" command line option, |
Roy Franz | 719e284 | 2013-09-28 08:44:21 -0700 | [diff] [blame] | 88 | and is processed in the same manner as the "initrd=" option that is |
| 89 | described above. |