UEFI [DRAFT]
Created at 2017-06-04T19:34:27+09:00

TODO

  • UEFI 2.7
  • [x] gpt
  • [ ] grub2
  • nvram (kernel driver ?)
  • rEFInd
  • efibootmgr, efivar
  • build linux image
  • linux boot steps
    • uncompression
    • jump from protected mode to long mode
  • testing on qemu ?
  • secure boot

Grub2

- (grub-install) main =>
  - (consider the case GRUB_INSTALL_PLATFORM_X86_64_EFI)
  - core_name = "core.efi"
  - img_file = ??
  - grub_install_make_image_wrap =>
    - spwan "grub-mkimage"
    - grub_install_generate_image =>
      - (case IMAGE_EFI)
      - ??
  - efi_file = "grubx64.efi"
  - grub_install_copy_file => ??

- (grub-mkimage) main => ??

Linux kernel image

  • learn from arch package
  • arch/x86/boot/bzImage how it's made
arch/x86/
- boot/
  - header.S, setup.ld
  - compressed/vmlinux.lds.S
  - tools/build.c
- kernel/
  - head_64.S
  - vmlinux.lds.S

Exploring GPT

See UEFI 2.7, Chapter 5 for spec.

# Show the 2nd sector of the disk (0x200 = 512byte)
$ sudo hexdump -C -s 0x200 -n 0x200 /dev/sda
00000200  45 46 49 20 50 41 52 54  00 00 01 00 5c 00 00 00  |EFI PART....\...|
00000210  30 60 c0 5b 00 00 00 00  01 00 00 00 00 00 00 00  |0`.[............|
00000220  2f 60 38 3a 00 00 00 00  22 00 00 00 00 00 00 00  |/`8:....".......|
00000230  0e 60 38 3a 00 00 00 00  55 4d ff 81 7a 21 d9 4d  |.`8:....UM..z!.M|
00000240  b5 7a 90 2f 86 f5 a4 87  02 00 00 00 00 00 00 00  |.z./............|
00000250  80 00 00 00 80 00 00 00  f9 cb 58 f9 00 00 00 00  |..........X.....|
00000260  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400

=> from this we can see:
  - PartitionEntryLBA        (0x0248 - 0x024F) => 0x02
  - NumberOfPartitionEntries (0x0250 - 0x0254) => 0x80
  - SizeOfPartitionEntry     (0x0254 - 0x0258) => 0x80 (= 128)

# Show partition entry
$ sudo hexdump -C -s 0x400 -n $(( 0x80 * 0x80 )) /dev/sda
00000400  28 73 2a c1 1f f8 d2 11  ba 4b 00 a0 c9 3e c9 3b  |(s*......K...>.;|
00000410  ed 1c e4 e0 5f be 91 42  bd 68 2d 5d e8 43 a5 88  |...._..B.h-].C..|
00000420  00 08 00 00 00 00 00 00  ff 27 08 00 00 00 00 00  |.........'......|
00000430  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000480  6d fd 57 06 ab a4 c4 43  84 e5 09 33 c8 4b 4f 4f  |m.W....C...3.KOO|
00000490  94 74 66 3d 0b 9f 60 44  b5 ee 50 c7 1a b2 13 59  |.tf=..`D..P....Y|
000004a0  00 28 08 00 00 00 00 00  ff 27 08 01 00 00 00 00  |.(.......'......|
000004b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000500  af 3d c6 0f 83 84 72 47  8e 79 3d 69 d8 47 7d e4  |.=....rG.y=i.G}.|
00000510  23 0d 77 73 12 74 5b 44  b5 dd 76 c1 ae 54 f4 57  |#.ws.t[D..v..T.W|
00000520  00 28 08 01 00 00 00 00  ff 27 08 21 00 00 00 00  |.(.......'.!....|
00000530  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000580  af 3d c6 0f 83 84 72 47  8e 79 3d 69 d8 47 7d e4  |.=....rG.y=i.G}.|
00000590  44 d0 81 c4 17 7c 52 48  bc 7e eb 41 e0 3b 8f 3e  |D....|RH.~.A.;.>|
000005a0  00 28 08 21 00 00 00 00  ff 27 88 2d 00 00 00 00  |.(.!.....'.-....|
000005b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000600  af 3d c6 0f 83 84 72 47  8e 79 3d 69 d8 47 7d e4  |.=....rG.y=i.G}.|
00000610  ba 1c f5 6b 72 2a fd 43  9d f2 82 50 b8 c0 44 52  |...kr*.C...P..DR|
00000620  00 28 88 2d 00 00 00 00  ff 27 c8 33 00 00 00 00  |.(.-.....'.3....|
00000630  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00004400

=> there are 5 non-zero sections, which correspond to this disk's 5 partitions.