Skip to content

Commit 3107209

Browse files
authored
Merge pull request #390 from danielinux/qemu-fsp-docs
Improve documentation for x86 targets
2 parents dd11fad + 091c036 commit 3107209

File tree

4 files changed

+115
-96
lines changed

4 files changed

+115
-96
lines changed

docs/Targets.md

Lines changed: 109 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ This README describes configuration of supported targets.
1313
* [NXP P1021 PPC](#nxp-qoriq-p1021-ppc)
1414
* [NXP T1024 PPC](#nxp-qoriq-t1024-ppc)
1515
* [NXP T2080 PPC](#nxp-qoriq-t2080-ppc)
16-
* [Qemu x86-64 UEFI](#qemu-x86-64-uefi)
1716
* [SiFive HiFive1 RISC-V](#sifive-hifive1-risc-v)
1817
* [STM32F4](#stm32f4)
1918
* [STM32F7](#stm32f7)
@@ -29,6 +28,7 @@ This README describes configuration of supported targets.
2928
* [Xilinx Zynq UltraScale](#xilinx-zynq-ultrascale)
3029
* [Renesas RX72N](#renesas-rx72n)
3130
* [Renesas RA6M4](#renesas-ra6m4)
31+
* [Qemu x86-64 UEFI](#qemu-x86-64-uefi)
3232
* [Intel x86-64 Intel FSP](#Intel-x86_64-with-Intel-FSP-support)
3333

3434
## STM32F4
@@ -1627,84 +1627,6 @@ thread break: Stopped, 0x0, 0x0, cpuPowerPCBig, Connected (state, tid, pid, cpu
16271627
See [/config/examples/ti-tms570lc435.config](/config/examples/ti-tms570lc435.config) for example configuration.
16281628

16291629

1630-
## Qemu x86-64 UEFI
1631-
1632-
x86-64bit machine with UEFI bios can run wolfBoot as EFI application.
1633-
1634-
### Prerequisites:
1635-
1636-
* qemu-system-x86_64
1637-
* [GNU-EFI] (https://sourceforge.net/projects/gnu-efi/)
1638-
* Open Virtual Machine firmware bios images (OVMF) by [Tianocore](https://tianocore.org)
1639-
1640-
On a debian-like system it is sufficient to install the packages as follows:
1641-
1642-
```
1643-
# for wolfBoot and others
1644-
apt install git make gcc
1645-
1646-
# for test scripts
1647-
apt install sudo dosfstools curl
1648-
apt install qemu qemu-system-x86 ovmf gnu-efi
1649-
1650-
# for buildroot
1651-
apt install file bzip2 g++ wget cpio unzip rsync bc
1652-
```
1653-
1654-
### Configuration
1655-
1656-
An example configuration is provided in [config/examples/x86_64_efi.config](config/examples/x86_64_efi.config)
1657-
1658-
### Building and running on qemu
1659-
1660-
The bootloader and the initialization script `startup.nsh` for execution in the EFI environment are stored in a loopback FAT partition.
1661-
1662-
The script [tools/efi/prepare_uefi_partition.sh](tools/efi/prepare_uefi_partition.sh) creates a new empty
1663-
FAT loopback partitions and adds `startup.nsh`.
1664-
1665-
A kernel with an embedded rootfs partition can be now created and added to the image, via the
1666-
script [tools/efi/compile_efi_linux.sh](tools/efi/compile_efi_linux.sh). The script actually adds two instances
1667-
of the target systems: `kernel.img` and `update.img`, both signed for authentication, and tagged with version
1668-
`1` and `2` respectively.
1669-
1670-
Compiling with `make` will produce the bootloader image in `wolfboot.efi`.
1671-
1672-
1673-
The script [tools/efi/run_efi.sh](tools/efi/run_efi.sh) will add `wolfboot.efi` to the bootloader loopback
1674-
partition, and run the system on qemu. If both kernel images are present and valid, wolfBoot will choose the image
1675-
with the higher version number, so `update.img` will be staged as it's tagged with version `2`.
1676-
1677-
The sequence is summarized below:
1678-
1679-
```
1680-
cp config/examples/x86_64_efi.config .config
1681-
tools/efi/prepare_efi_partition.sh
1682-
make
1683-
tools/efi/compile_efi_linux.sh
1684-
tools/efi/run_efi.sh
1685-
```
1686-
1687-
```
1688-
EFI v2.70 (EDK II, 0x00010000)
1689-
[700/1832]
1690-
Mapping table
1691-
FS0: Alias(s):F0a:;BLK0:
1692-
PciRoot(0x0)/Pci(0x1,0x1)/Ata(0x0)
1693-
BLK1: Alias(s):
1694-
PciRoot(0x0)/Pci(0x1,0x1)/Ata(0x0)
1695-
Press ESC in 1 seconds to skip startup.nsh or any other key to continue.
1696-
Starting wolfBoot EFI...
1697-
Image base: 0xE3C6000
1698-
Opening file: kernel.img, size: 6658272
1699-
Opening file: update.img, size: 6658272
1700-
Active Part 1
1701-
Firmware Valid
1702-
Booting at 0D630000
1703-
Staging kernel at address D630100, size: 6658016
1704-
```
1705-
1706-
You can `Ctrl-C` or login as `root` and power off qemu with `poweroff`
1707-
17081630

17091631
## Nordic nRF52840
17101632

@@ -1822,16 +1744,108 @@ Flash Allocation:
18221744

18231745
Detailed steps can be found at [Readme.md](../IDE/Renesas/e2studio/RA6M4/Readme.md).
18241746

1747+
## Qemu x86-64 UEFI
1748+
1749+
The simplest option to compile wolfBoot as a bootloader for x86-64bit machines is
1750+
the UEFI mode. This mechanism requires an UEFI bios, which stages wolfBoot
1751+
by running the binary as an EFI application.
1752+
1753+
The following instructions describe the procedure to configure wolfBoot as EFI
1754+
application and run it on qemu using tianocore as main firmware. A GNU/Linux system
1755+
built via buildroot is then authenticated and staged by wolfBoot.
1756+
1757+
### Prerequisites:
1758+
1759+
* qemu-system-x86_64
1760+
* [GNU-EFI] (https://sourceforge.net/projects/gnu-efi/)
1761+
* Open Virtual Machine firmware bios images (OVMF) by [Tianocore](https://tianocore.org)
1762+
1763+
On a debian-like system it is sufficient to install the packages as follows:
1764+
1765+
```
1766+
# for wolfBoot and others
1767+
apt install git make gcc
1768+
1769+
# for test scripts
1770+
apt install sudo dosfstools curl
1771+
apt install qemu qemu-system-x86 ovmf gnu-efi
1772+
1773+
# for buildroot
1774+
apt install file bzip2 g++ wget cpio unzip rsync bc
1775+
```
1776+
1777+
### Configuration
1778+
1779+
An example configuration is provided in [config/examples/x86_64_efi.config](config/examples/x86_64_efi.config)
1780+
1781+
### Building and running on qemu
1782+
1783+
The bootloader and the initialization script `startup.nsh` for execution in the EFI environment are stored in a loopback FAT partition.
1784+
1785+
The script [tools/efi/prepare_uefi_partition.sh](tools/efi/prepare_uefi_partition.sh) creates a new empty
1786+
FAT loopback partitions and adds `startup.nsh`.
1787+
1788+
A kernel with an embedded rootfs partition can be now created and added to the image, via the
1789+
script [tools/efi/compile_efi_linux.sh](tools/efi/compile_efi_linux.sh). The script actually adds two instances
1790+
of the target systems: `kernel.img` and `update.img`, both signed for authentication, and tagged with version
1791+
`1` and `2` respectively.
1792+
1793+
Compiling with `make` will produce the bootloader image in `wolfboot.efi`.
1794+
1795+
1796+
The script [tools/efi/run_efi.sh](tools/efi/run_efi.sh) will add `wolfboot.efi` to the bootloader loopback
1797+
partition, and run the system on qemu. If both kernel images are present and valid, wolfBoot will choose the image
1798+
with the higher version number, so `update.img` will be staged as it's tagged with version `2`.
1799+
1800+
The sequence is summarized below:
1801+
1802+
```
1803+
cp config/examples/x86_64_efi.config .config
1804+
tools/efi/prepare_efi_partition.sh
1805+
make
1806+
tools/efi/compile_efi_linux.sh
1807+
tools/efi/run_efi.sh
1808+
```
1809+
1810+
```
1811+
EFI v2.70 (EDK II, 0x00010000)
1812+
[700/1832]
1813+
Mapping table
1814+
FS0: Alias(s):F0a:;BLK0:
1815+
PciRoot(0x0)/Pci(0x1,0x1)/Ata(0x0)
1816+
BLK1: Alias(s):
1817+
PciRoot(0x0)/Pci(0x1,0x1)/Ata(0x0)
1818+
Press ESC in 1 seconds to skip startup.nsh or any other key to continue.
1819+
Starting wolfBoot EFI...
1820+
Image base: 0xE3C6000
1821+
Opening file: kernel.img, size: 6658272
1822+
Opening file: update.img, size: 6658272
1823+
Active Part 1
1824+
Firmware Valid
1825+
Booting at 0D630000
1826+
Staging kernel at address D630100, size: 6658016
1827+
```
1828+
1829+
You can `Ctrl-C` or login as `root` and power off qemu with `poweroff`
1830+
1831+
18251832

18261833
## Intel x86_64 with Intel FSP support
18271834

1828-
This feature is experimental. Intel FSP provides a set of common firmware
1829-
services that can be used for memory initialization, power management, and
1830-
silicon initialization. Wolfboot accesses these services by invoking
1831-
machine-dependent binary code provided by the Intel FSP in the form of binary
1832-
blobs.
1835+
This setup is more complex than the UEFI approach described earlier, but allows
1836+
for complete control of the machine since the very first stage after poweron.
1837+
1838+
In other words, wolfBoot can run as a secure replacement of the system BIOS, thanks to the
1839+
integration with the Intel Firmware Support Package (FSP). FSP provides services
1840+
for target-specific initial configuration (memory and silicon initialization,
1841+
power management, etc.). These services are designed to be accessed and invoked
1842+
by the bootloader.
1843+
1844+
If wolfBoot is compiled with FSP support, it invokes the necessary machine-dependent
1845+
binary code, which that can be obtained from the chip manufacturer.
1846+
1847+
The following variables must be set in your `.config` file when using this feature:
18331848

1834-
To use this feature, you will need to configure the following variables:
18351849

18361850
- `ARCH` = `x86_64`
18371851
- `TARGET` = A useful name for the target you want to support. You can refer to
@@ -1847,13 +1861,13 @@ To use this feature, you will need to configure the following variables:
18471861
- `WOLFBOOT_LOAD_BASE`: the address where wolfboot will be loaded in RAM after the first initialization phase
18481862

18491863
While Intel FSP aims to abstract away specific machine details, you still need
1850-
some machine-specific code. Refer to the Intel Integration Guide of the selected
1864+
some machine-specific code. In the next section we show how to retrieve the
1865+
target-specific code for qemu. Refer to the Intel Integration Guide of the selected
18511866
silicon for more information.
18521867

18531868
Note:
1854-
- This feature is experimental, so it may have bugs or limitations.
18551869

1856-
- This feature requires NASM
1870+
- This feature requires `NASM` to be installed on the machine building wolfBoot.
18571871

18581872

18591873
### Running on 64-bit Qemu
@@ -2039,7 +2053,6 @@ booting...
20392053
Linux version 5.17.15 (arch@wb-hg-2) (x86_64-linux-gcc.br_real (Buildroot toolchains.bootlin.com-2021.11-5) 11.2.0, GNU ld (GNU Binutils) 2.37) #24 PREEMPT Wed May 17 13:47:24 UTC 2023
20402054
```
20412055

2042-
20432056
### Running on 64-bit Qemu with swtpm (TPM emulator)
20442057

20452058
The example configuration for this setup can be found in
@@ -2061,12 +2074,16 @@ tools/x86_fsp/qemu/qemu_build_fsp.sh
20612074
make
20622075
20632076
# The next script needs to be run from wolboot root folder and assumes your
2064-
# kernel is in th root folder, named bzImage
2077+
# kernel is in wolfBoot's root folder. The file should be named `bzImage`.
20652078
# If this is not the case, change the path in the script accordingly
2066-
tools/x86_64/qemu/make_hd.sh
2079+
2080+
tools/x86_fsp/qemu/make_hd.sh
20672081
20682082
# Run wolfBoot + linux in qemu, with swTPM connected to the guest machine.
2069-
# The script will take care of starting the emulator before launching the VM.
2083+
# The script will start the TPM emulator before launching the VM.
20702084
tools/scripts/qemu64/qemu64-tpm.sh
20712085
```
20722086

2087+
For more advanced uses of TPM, please check [TPM.md](TPM.md) to configure wolfBoot
2088+
according to your secure boot strategy.
2089+

tools/x86_fsp/qemu/make_hd.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
SIGN=${SIGN:-"--ecc256"}
33
HASH=${HASH:-"--sha256"}
44

5-
IMAGE=bzImage
5+
IMAGE=${IMAGE:-"bzImage"}
6+
7+
set -e
68

79
dd if=/dev/zero of=app.bin bs=1M count=64
8-
fdisk app.bin <<EOF
10+
/sbin/fdisk app.bin <<EOF
911
g
1012
n
1113
1

0 commit comments

Comments
 (0)