Skip to contentSkip to conversation

configs/pc: refactor to use genimage and grub.cfg

PATCH New Erico Nunes 3 participants 7 messages Oct 22, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 configs/pc: refactor to use genimage and grub.cfg

This simplifies the pc configs and respective post image scripts to use the shared genimage script and separate grub config files. Separate grub files are cleaner to maintain and easier to copy and modify, for example to support booting the pc defconfigs in qemu.

Cc Thomas Petazzoni <[email protected]>

---
Changes v1 -> v2:
- Drop the BR2_TARGET_GRUB2_CFG proposed use since the patch was dropped.

---
 board/pc/grub-bios.cfg           |  6 ++++++
 board/pc/grub-efi.cfg            |  6 ++++++
 board/pc/post-image.sh           | 29 ++++-------------------------
 configs/pc_x86_64_bios_defconfig |  3 ++-
 configs/pc_x86_64_efi_defconfig  |  3 ++-
 5 files changed, 20 insertions(+), 27 deletions(-)
 create mode 100644 board/pc/grub-bios.cfg
 create mode 100755 board/pc/grub-efi.cfg
board/pc/grub-bios.cfg new file +6 -0
new file mode 100644
index 0000000000..bd3e3f0006
@@ -0,0 +1,6 @@
+set default="0"
+set timeout="5"
+
+menuentry "Buildroot" {
+	linux /boot/bzImage root=/dev/sda1 rootwait console=tty1
+}
board/pc/grub-efi.cfg new file +6 -0
new file mode 100755
index 0000000000..222301a4e0
@@ -0,0 +1,6 @@
+set default="0"
+set timeout="5"
+
+menuentry "Buildroot" {
+	linux /bzImage root=/dev/sda2 rootwait console=tty1
+}
board/pc/post-image.sh +4 -25
index c88ecb1dc2..bdd0847ec5 100755
@@ -1,35 +1,14 @@
 #!/bin/sh
 
+BOARD_DIR="$(dirname $0)"
+
 # Detect boot strategy, EFI or BIOS
 if [ -f ${BINARIES_DIR}/efi-part/startup.nsh ]; then
-  BOOT_TYPE=efi
-  # grub.cfg needs customization for EFI since the root partition is
-  # number 2, and bzImage is in the EFI partition (1)
-  cat >${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg <<__EOF__
-set default="0"
-set timeout="5"
-
-menuentry "Buildroot" {
-	linux /bzImage root=/dev/sda2 rootwait console=tty1
-}
-__EOF__
+  cp -f ${BOARD_DIR}/grub-efi.cfg ${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg
 else
-  BOOT_TYPE=bios
+  cp -f ${BOARD_DIR}/grub-bios.cfg ${TARGET_DIR}/boot/grub/grub.cfg
   # Copy grub 1st stage to binaries, required for genimage
   cp -f ${HOST_DIR}/lib/grub/i386-pc/boot.img ${BINARIES_DIR}
 fi
 
-BOARD_DIR="$(dirname $0)"
-GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOOT_TYPE}.cfg"
-GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
-
-rm -rf "${GENIMAGE_TMP}"
-
-genimage                           \
-       --rootpath "${TARGET_DIR}"     \
-       --tmppath "${GENIMAGE_TMP}"    \
-       --inputpath "${BINARIES_DIR}"  \
-       --outputpath "${BINARIES_DIR}" \
-       --config "${GENIMAGE_CFG}"
-
 exit $?
configs/pc_x86_64_bios_defconfig +2 -1
index ddbd776154..47787bc118 100644
@@ -19,7 +19,8 @@ BR2_TARGET_ROOTFS_EXT2=y
 BR2_TARGET_ROOTFS_EXT2_4=y
 BR2_TARGET_ROOTFS_EXT2_SIZE="120M"
 # BR2_TARGET_ROOTFS_TAR is not set
-BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image.sh"
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image.sh support/scripts/genimage.sh"
+BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-bios.cfg"
 
 # Linux headers same as kernel, a 4.13 series
 BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_13=y
configs/pc_x86_64_efi_defconfig +2 -1
index 94385252b9..67ba5bcf5b 100644
@@ -22,7 +22,8 @@ BR2_TARGET_ROOTFS_EXT2=y
 BR2_TARGET_ROOTFS_EXT2_4=y
 BR2_TARGET_ROOTFS_EXT2_SIZE="120M"
 # BR2_TARGET_ROOTFS_TAR is not set
-BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image.sh"
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/pc/post-image.sh support/scripts/genimage.sh"
+BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-efi.cfg"
 
 # Linux headers same as kernel, a 4.13 series
 BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_13=y
Signature · 1 line
2.13.6
#1 lore raw

PATCH v2 2/3 board/pc: add documentation for testing with qemu

Add some documentation about running the pc defconfigs in qemu. In particular, document the use of the -bios parameter to use the OVMF firmware to test the UEFI image.

Cc Peter Korsgaard <[email protected]>

---
Changes v1 -> v2:
- Made the images path relative to output/ to match in-tree Buildroot builds.

---
 board/pc/readme.txt | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
board/pc/readme.txt +42 -0
index 68ca21166f..5277ea5bc6 100644
@@ -35,3 +35,45 @@ Bare PC sample config
   the setup as well.
 
 3. Enjoy
+
+
+Emulation in qemu (BIOS)
+========================
+
+1. Edit grub-bios.cfg
+
+  Since the driver will show up in the virtual machine as /dev/vda,
+  change board/pc/grub-bios.cfg to use root=/dev/vda2 instead of
+  root=/dev/sda2. Then rebuild grub2 and the image.
+
+2. Run the emulation with:
+
+qemu-system-x86_64 \
+	-M pc \
+	-drive file=output/images/disk.img,if=virtio,format=raw \
+	-net nic,model=virtio \
+	-net user
+
+
+Emulation in qemu (UEFI)
+========================
+
+1. Edit grub-efi.cfg
+
+  Since the driver will show up in the virtual machine as /dev/vda,
+  change board/pc/grub-efi.cfg to use root=/dev/vda2 instead of
+  root=/dev/sda2. Then rebuild grub2 and the image.
+
+2. Run the emulation with:
+
+qemu-system-x86_64 \
+	-M pc \
+	-bios </path/to/OVMF_CODE.fd> \
+	-drive file=output/images/disk.img,if=virtio,format=raw \
+	-net nic,model=virtio \
+	-net user
+
+Note that </path/to/QEMU_EFI.fd> needs to point to a valid x86_64 UEFI
+firmware image for qemu.
+It may be provided by your distribution as a edk2 or OVMF package, in
+path such as /usr/share/edk2/ovmf/OVMF_CODE.fd .
Signature · 1 line
2.13.6
#2 lore raw

PATCH v2 2/3 board/pc: add documentation for testing with qemu

Hello,

board/pc/readme.txt Bare PC sample config · line 76

Quoted 8 lines · Erico Nunes
board/pc/readme.txt +8 -0
+qemu-system-x86_64 \
+	-M pc \
+	-bios </path/to/OVMF_CODE.fd> \
+	-drive file=output/images/disk.img,if=virtio,format=raw \
+	-net nic,model=virtio \
+	-net user
+
+Note that </path/to/QEMU_EFI.fd> needs to point to a valid x86_64 UEFI

You meant OVMF_CODE.fd here, so I've fixed that up and applied. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#3 lore raw

PATCH v2 2/3 board/pc: add documentation for testing with qemu

In reply to Erico Nunes
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Erico" == Erico Nunes <[email protected]> writes:

Add some documentation about running the pc defconfigs in qemu. In particular, document the use of the -bios parameter to use the OVMF firmware to test the UEFI image.

Cc Peter Korsgaard <[email protected]>

...

Quoted 5 lines
board/pc/readme.txt +5 -0
+Emulation in qemu (UEFI)
+========================
+
+1. Edit grub-efi.cfg
+

board/pc/readme.txt Bare PC sample config · line 72

Quoted 10 lines
board/pc/readme.txt +10 -0
+  Since the driver will show up in the virtual machine as /dev/vda,
+  change board/pc/grub-efi.cfg to use root=/dev/vda2 instead of
+  root=/dev/sda2. Then rebuild grub2 and the image.
+
+2. Run the emulation with:
+
+qemu-system-x86_64 \
+	-M pc \
+	-bios </path/to/OVMF_CODE.fd> \
+	-drive file=output/images/disk.img,if=virtio,format=raw \

Maybe it would be better to not use virtio for the disk image so we can keep root=/dev/sda? Unless the UEFI firmware doesn't support normal sata controllers?

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH v2 3/3 DEVELOPERS: add maintainer for pc_x86_64_* defconfigs

In reply to Erico Nunes

I've been using this packages to test changes in the grub package, so I can maintain them.

Cc Thomas Petazzoni <[email protected]>
---
 DEVELOPERS | 1 +
 1 file changed, 1 insertion(+)
DEVELOPERS +1 -0
index 448dd4bbce..f0f83b0f42 100644
@@ -535,6 +535,7 @@ F:	package/efivar/
 F:	package/fwts/
 F:	package/spi-tools/
 F:	package/xdotool/
+F:	configs/pc_x86_64_*
 
 N:	Erik Stromdahl <[email protected]>
 F:	package/mxsldr/
Signature · 1 line
2.13.6
#5 lore raw

PATCH v2 3/3 DEVELOPERS: add maintainer for pc_x86_64_* defconfigs

Hello,

Quoted 8 lines · Erico Nunes

I've been using this packages to test changes in the grub package, so I can maintain them.

Cc Thomas Petazzoni <[email protected]>
---
 DEVELOPERS | 1 +
 1 file changed, 1 insertion(+)

Applied to master, thanks.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#6 lore raw

PATCH v2 1/3 configs/pc: refactor to use genimage and grub.cfg

In reply to Erico Nunes

Hello,

Quoted 11 lines · Erico Nunes

This simplifies the pc configs and respective post image scripts to use the shared genimage script and separate grub config files. Separate grub files are cleaner to maintain and easier to copy and modify, for example to support booting the pc defconfigs in qemu.

Cc Thomas Petazzoni <[email protected]>

---
Changes v1 -> v2:
- Drop the BR2_TARGET_GRUB2_CFG proposed use since the patch was dropped.

Quoted 9 lines
---
 board/pc/grub-bios.cfg           |  6 ++++++
 board/pc/grub-efi.cfg            |  6 ++++++
 board/pc/post-image.sh           | 29 ++++-------------------------
 configs/pc_x86_64_bios_defconfig |  3 ++-
 configs/pc_x86_64_efi_defconfig  |  3 ++-
 5 files changed, 20 insertions(+), 27 deletions(-)
 create mode 100644 board/pc/grub-bios.cfg
 create mode 100755 board/pc/grub-efi.cfg

Applied to master, thanks.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com