Skip to content

Commit 140e08a

Browse files
authored
Merge pull request #1653 from yury-khrustalev/glibc-linux-fvp
Add learning path for Glibc + Linux + FVP
2 parents 854e3e6 + c93b6f8 commit 140e08a

File tree

7 files changed

+902
-0
lines changed

7 files changed

+902
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Glibc + Linux + FVP
3+
4+
minutes_to_complete: 60
5+
6+
who_is_this_for: >
7+
Developers who wish to run a Linux system (optionally using a custom kernel and
8+
a C library) on an Arm Fixed Virtual Platform (FVP) model. For example, this
9+
guide might be useful if you want to test patches for the Linux kernel or Glibc.
10+
11+
learning_objectives:
12+
- Build the Linux kernel.
13+
- Install the Shrinkwrap tool, build firmware for the FVP and run it.
14+
- Configure and boot a Linux system on the FVP.
15+
- Configure guest OS to make running Glibc tests easier.
16+
- Build Glibc and run tests on the system running on the FVP.
17+
18+
prerequisites:
19+
- An AArch64 or x86 host running a Linux system.
20+
- GCC cross toolchain for the `aarch64-none-linux-gnu` target.
21+
- Docker.
22+
- Git to checkout sources.
23+
- Make to build the tools.
24+
- Bash for your shell.
25+
- Python 3.x and `pip` to create a Python virtual environment.
26+
- Common tools like `wget`, `unxz`, `truncate`.
27+
28+
author: Yury Khrustalev
29+
30+
### Tags
31+
skilllevels: Advanced
32+
subjects: Architecture Enablement
33+
armips:
34+
- AArch64
35+
tools_software_languages:
36+
- Glibc
37+
- Shrinkwrap
38+
- Fast Models
39+
operatingsystems:
40+
- Linux
41+
42+
### FIXED, DO NOT MODIFY
43+
# ================================================================================
44+
weight: 1 # _index.md always has weight of 1 to order correctly
45+
layout: "learningpathall" # All files under learning paths have this same wrapper
46+
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
47+
---
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Conventions
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
For a few things you may need root access on your host system to do minimal setup and
10+
install packages that are described in the following sections.
11+
12+
## Naming conventions
13+
14+
In the following sections we use host system to checkout sources and build various
15+
tools and we also make configuration changes to the guest system that will run on
16+
the Arm [Fixed Virtual Platform (FVP)][1] model.
17+
18+
Before we begin, it's important to describe the specifics of our setup making it easier
19+
to write commands and code examples. Wherever possible we use generic commands and code
20+
examples but in certain places we have to use hardcoded values and absolute paths.
21+
22+
Table 1. Directory layout
23+
24+
| Path | Description |
25+
|--------------------------------------|--------------------------------------------|
26+
| `/path/to/cross/gcc` | GCC cross toolchain installation directory |
27+
| `/home/user` | Home directory of your host non-root user |
28+
| `/home/user/workspace` | Workspace directory |
29+
| `/home/user/workspace/linux` | Folder with the Linux kernel sources |
30+
| `/home/user/workspace/linux-headers` | Directory for installing kernel headers |
31+
| `/home/user/workspace/linux-build` | Folder for the Linux kernel build output |
32+
| `/home/user/workspace/glibc` | Foldr for the Glibc sources |
33+
| `/home/user/workspace/glibc-build` | Directory foir the Glibc build output |
34+
35+
36+
37+
We presume that the GCC cross toolchain installation directory contains everything a
38+
cross toolchain would need, for example, the path to the `gcc` tool would be
39+
`/path/to/cross/gcc/bin/aarch64-none-linux-gnu-gcc`.
40+
41+
In the next steps we create a Python virtual environment. It doesn't matter where
42+
it is located, but to avoid ambiguity let's presume it is in `~/workspace/venv`.
43+
44+
[1]: https://developer.arm.com/downloads/-/arm-ecosystem-fvps
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
---
2+
title: Boot Linux on FVP
3+
weight: 5
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Introduction
10+
11+
During this step, we set up everything for the FVP to run and then boot the Linux system
12+
using the kernel and the root file system that we prepared earlier.
13+
14+
Arm [Fixed Virtual Platform (FVP)][1] is a model that allows you to access functionality
15+
of Armv8.x or v9.x hardware. We use the Armv-A Base Rev C Architecture Envelope Model (AEM).
16+
17+
In addition to the model itself, you also need the device tree and the firmware. To simplify
18+
building these components, we use a tool called [Shrinkwrap][2].
19+
20+
This tool comes with a detailed [user guide][3] that covers all of its features and
21+
configuration options. Here, we provide a short quick-start guide.
22+
23+
We also rely on a Docker container to facilitate the building of the firmware and
24+
running the FVP. This helps avoid installing all the dependencies on your host system.
25+
Shrinkwrap can be used without Docker but it requires extra steps to ensure that all
26+
dependencies are of the right version and are installed correctly.
27+
28+
## Install Shrinkwrap
29+
30+
First, we install prerequisites in a Python virtual environment using Python 3.x:
31+
32+
```bash
33+
python -m venv ~/workspace/venv
34+
source ~/workspace/venv/bin/activate
35+
pip install -U pip setuptools wheel
36+
pip install pyyaml termcolor tuxmake
37+
```
38+
39+
Shrinkwrap can be used directly from the source, which can be checked out from its Git
40+
repository. Run this command in the workspace directory:
41+
42+
```bash
43+
git clone https://git.gitlab.arm.com/tooling/shrinkwrap.git
44+
export PATH=${PATH}:$(pwd)/shrinkwrap/shrinkwrap
45+
```
46+
47+
Putting Shrinkwrap's main executable on your `PATH` is all you need to install the tool.
48+
To check that it works, ensure that the Python virtual environment we created earlier
49+
is activated, then run this command:
50+
51+
```bash
52+
shrinkwrap --version
53+
```
54+
55+
## Build firmware for FVP
56+
57+
Before proceeding, ensure that Docker is installed and usable. Follow the installation
58+
instructions for your distro [here][4].
59+
60+
Now, we use the Shrinkwrap tool to build the firmware, the third essential ingredient in our
61+
setup. The following step needs to be done once although you will need to repeat it if you
62+
want to rebuild the firmware:
63+
64+
```bash
65+
shrinkwrap build --overlay=arch/v9.4.yaml ns-edk2.yaml
66+
```
67+
68+
This command uses the `arch/v9.4.yaml` config that enables Armv9.4 hardware features.
69+
This config is included with the Shrinkwrap installation. We also use the `ns-edk2.yaml`
70+
config. This configuration file is also a part of the Shrinkwrap tool. It defines the
71+
settings for building and running the firmware using EDK2 on Arm FVPs. The build
72+
process takes some time. During this step, Shrinkwrap downloads the required Docker
73+
image and starts a container to clone all the required firmware repositories and build
74+
the components including the device tree for the FVP.
75+
76+
## Overlay config
77+
78+
At this point, we have everything required to boot our system. Shrinkwrap uses so called overlay
79+
configuration files. The following file instructs Shrinkwrap to connect all the pieces together
80+
and locate the kernel image, and rootfs. It can also be used to tweak any of the FVP
81+
parameters. Save this file as `~/workspace/aarch64.yaml`:
82+
83+
```yaml
84+
run:
85+
rtvars:
86+
ROOTFS:
87+
value: /home/user/workspace/rootfs.img
88+
CMDLINE:
89+
value: ip=dhcp kpti=off root=/dev/vda2 console=ttyAMA0
90+
KERNEL:
91+
value: /home/user/workspace/linux-build/arch/arm64/boot/Image
92+
params:
93+
-C bp.hostbridge.userNetworking: 1
94+
-C bp.hostbridge.userNetPorts: 8022=22,8123=8123
95+
-C bp.smsc_91c111.enabled: 1
96+
-C bp.virtio_net.enabled: 0
97+
-C cluster0.NUM_CORES: 1
98+
-C cluster1.NUM_CORES: 0
99+
-C pctl.CPU-affinities: 0.0.0.0
100+
```
101+
102+
The most important parts in this configuration file are:
103+
104+
* Paths to the rootfs image and the kernel image.
105+
* The kernel command line, which contains `root=/dev/vda2`, specifying where to locate
106+
the filesystem to be mounted at `/`.
107+
* The port mapping `8022=22`, which is used for SSH access into the guest system.
108+
You can add more ports as needed.
109+
110+
The FVP has many parameters that can be tweaked in this config by adding a `-C param: value`
111+
line to the `params` section. Refer to the [Fast Models Fixed Virtual Platforms Reference Guide][5]
112+
for more details.
113+
114+
## Run FVP with Shrinkwrap
115+
116+
To run the FVP using Docker, execute the following command:
117+
118+
```bash
119+
shrinkwrap run ns-edk2.yaml --overlay ~/workspace/aarch64.yaml
120+
```
121+
122+
At first, Shrinkwrap starts a Docker container and runs the FVP in it. At the beginning
123+
of the output, you may see a line containing the IP address that you need to use for SSH
124+
access into the guest system:
125+
126+
```
127+
Press '^]' to quit shrinkwrap.
128+
All other keys are passed through.
129+
Environment ip address: 172.17.0.2.
130+
```
131+
132+
It also tells you how to stop the FVP execution: press `Ctrl+]` (more on this later).
133+
134+
Booting the Linux on the FVP takes some time. Look out for the system log messages about
135+
growing the root partition to utilize the empty disk space we created earlier.
136+
137+
```
138+
=> Growing root partition
139+
CHANGED: partition=2 ... old: size=1316864 ... new: size=5511135
140+
```
141+
142+
After a couple of minutes, you should be able to SSH in a different terminal into the
143+
guest OS running on the FVP using the IP address reported by the Shrinkwrap tool and the
144+
port number specified earlier in our overlay config:
145+
146+
```bash
147+
ssh [email protected] -p 8022
148+
```
149+
150+
The default password is `voidlinux`.
151+
152+
When you have logged in, check the properties of your guest system, for example:
153+
154+
```bash
155+
uname -a
156+
cat /proc/cpuinfo
157+
```
158+
159+
We will do more setup during the next step. This additional setup is optional but it
160+
helps prepare our guest system for running Glibc tests and doing other complex tasks.
161+
162+
## Powering down
163+
164+
You can always press `Ctrl+]` to stop Shrinkwrap in the terminal where Shrinkwrap is
165+
running. However, this abruptly aborts execution of the FVP. This may leave the filesystem
166+
in your rootfs image, used by the guest system, in a broken state, resulting in errors
167+
during the next boot. To avoid this, it is advisable to shut down the guest system gracefully
168+
from the root console of your guest system, for example:
169+
170+
```bash
171+
ssh [email protected] -p 8022 poweroff
172+
```
173+
174+
[1]: https://developer.arm.com/downloads/-/arm-ecosystem-fvps
175+
[2]: https://gitlab.arm.com/tooling/shrinkwrap
176+
[3]: https://shrinkwrap.docs.arm.com/en/latest/
177+
[4]: https://docs.docker.com/engine/install/
178+
[5]: https://developer.arm.com/documentation/100966/latest/Getting-Started-with-Fixed-Virtual-Platforms/Configuring-the-model

0 commit comments

Comments
 (0)