Skip to content

Commit

Permalink
Add support for aarch64, with additional images
Browse files Browse the repository at this point in the history
  • Loading branch information
pguyot committed Feb 14, 2022
1 parent 190178d commit 171180e
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 8 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test-aarch64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test aarch64 cpu option
on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pguyot/arm-runner-action@HEAD
with:
base_image: https://dietpi.com/downloads/images/DietPi_RPi-ARMv8-Bullseye.7z
cpu: cortex-a53
commands: |
echo "Minimal"
test `uname -m` = 'aarch64'
25 changes: 25 additions & 0 deletions .github/workflows/test-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test architecture matrix
on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [armv6l, armv7l, aarch64]
include:
- arch: armv6l
cpu: arm1176
base_image: raspios_lite:latest
- arch: armv7l
cpu: cortex-a7
base_image: raspios_lite:latest
- arch: aarch64
cpu: cortex-a53
base_image: raspios_lite_arm64:latest
steps:
- uses: pguyot/arm-runner-action@HEAD
with:
base_image: ${{ matrix.base_image }}
cpu: ${{ matrix.cpu }}
commands: |
test `uname -m` = ${{ matrix.arch }}
66 changes: 62 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ userland Linux emulation;
- prepare images that are ready to run on Raspberry Pi and other ARM embedded
devices.

This action works with both 32 bits (arm) and 64 bits (aarch64) images.

## Usage

Minimal usage is as follows:
Expand All @@ -35,7 +37,7 @@ Typical usage to upload an image as an artifact:
- uses: pguyot/arm-runner-action@v2
id: build_image
with:
base_image: raspios_lite:2021-11-08
base_image: raspios_lite:2022-01-28
commands: |
commands to build image
- name: Compress the release image
Expand Down Expand Up @@ -78,8 +80,16 @@ The following values are allowed:
- `raspios_lite:2021-05-07`
- `raspios_lite:2021-10-30`
- `raspios_lite:2022-01-28`
- `raspios_lite:latest` (armhf build, default)
- `raspios_lite:latest` (armhf build, *default*)
- `raspios_lite_arm64:2022-01-28` (arm64, requires an ARMv8 CPU)
- `raspios_lite_arm64:latest` (arm64, requires an ARMv8 CPU)
- `dietpi:rpi_armv6_bullseye`
- `dietpi:rpi_armv7_bullseye`
- `dietpi:rpi_armv8_bullseye` (requires an ARMv8 CPU)
- `raspi_1_bullseye:20220121` (armel)
- `raspi_2_bullseye:20220121` (armhf)
- `raspi_3_bullseye:20220121` (arm64, requires an ARMv8 CPU)
- `raspi_4_bullseye:20220121` (arm64, requires an ARMv8 CPU)

The input parameter also accepts any custom URL beginning in http(s)://...

Expand All @@ -92,8 +102,13 @@ Enlarge the image by this number of MB. Default is to not enlarge the image.
#### `cpu`

CPU to pass to qemu.
Default value is `arm1176` which translates to armv6l, suitable for Pi Zero.
Other values include `cortex-a8` which translates to armv7l, suitable for Pi 3/Pi 4.

The following values are recommended:
- `arm1176` (translates to armv6l, suitable for Pi Zero, default)
- `cortex-a8` (translates to armv7l, suitable for Pi 3/Pi 4 and Pi Zero 2)
- `cortex-a53` (translates to aarch64, suitable for 64 bits OSes).

The CPU and the base image should match (see _32 and 64 bits_ below).

#### `copy_artifact_path`

Expand Down Expand Up @@ -172,6 +187,49 @@ Note this parameter does not enable importing any contents written to

Path to the image, useful after the step to upload the image as an artifact.

### 32 and 64 bits

Many RaspberryPis and ARM boards are based on 64-bits chipsets than can run
32 bits and 64 bits kernels. RaspberryPi OS, as well as other distributions,
are now provided in 32 bits and 64 bits flavors.

This action works for images built for 32 bits and 64 bits ARM architectures.
Default input values imply 32 bits images. For 64 bits, the CPU and the
base image should match.

The following matrix will build on armv6l, armv7l and aarch64 using the latest
RaspberryPi OS images.

name: Test architecture matrix
on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [armv6l, armv7l, aarch64]
include:
- arch: armv6l
cpu: arm1176
base_image: raspios_lite:latest
- arch: armv7l
cpu: cortex-a7
base_image: raspios_lite:latest
- arch: aarch64
cpu: cortex-a53
base_image: raspios_lite_arm64:latest
steps:
- uses: pguyot/[email protected]
with:
base_image: ${{ matrix.base_image }}
cpu: ${{ matrix.cpu }}
commands: |
test `uname -m` = ${{ matrix.arch }}

Internally, the `cpu` value is embedded in a wrapper for `qemu-arm-static` and
`qemu-aarch64-static`. The actual qemu invoked depends on executables within
the base image.

## Examples

Real world examples include:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ runs:
- name: Install qemu wrapper
run: |
sudo mv /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static0
sudo mv /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static0
sudo gcc -static ${{ github.action_path }}/qemu-wrapper.c -DQEMU_CPU=${{ inputs.cpu }} -O3 -s -o /usr/bin/qemu-arm-static
sudo cp /usr/bin/qemu-arm-static /usr/bin/qemu-aarch64-static
sudo update-binfmts --disable qemu-arm
sudo update-binfmts --disable qemu-aarch64
sudo update-binfmts --enable qemu-arm
sudo update-binfmts --enable qemu-aarch64
shell: bash
- name: Download base image
run: |
Expand Down
4 changes: 3 additions & 1 deletion cleanup_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ optimize=$4

rm "${mount}/usr/bin/qemu-arm-static0"
rm "${mount}/usr/bin/qemu-arm-static"
mv "${mount}/etc/_ld.so.preload" "${mount}/etc/ld.so.preload"
rm "${mount}/usr/bin/qemu-aarch64-static0"
rm "${mount}/usr/bin/qemu-aarch64-static"
[ -e "${mount}/etc/_ld.so.preload" ] && mv "${mount}/etc/_ld.so.preload" "${mount}/etc/ld.so.preload"
mv "${mount}/etc/_resolv.conf" "${mount}/etc/resolv.conf"

[[ -f "${mount}/tmp/commands.sh" ]] && rm "${mount}/tmp/commands.sh"
Expand Down
25 changes: 25 additions & 0 deletions download_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ case $1 in
url=https://downloads.raspberrypi.org/raspios_lite_armhf_latest
uncompress="unzip -u"
;;
"raspios_lite_arm64:latest")
url=https://downloads.raspberrypi.org/raspios_lite_arm64_latest
uncompress="unzip -u"
;;
"raspbian_lite:2020-02-13")
url=https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2020-02-14/2020-02-13-raspbian-buster-lite.zip
;;
Expand All @@ -25,9 +29,30 @@ case $1 in
"raspios_lite:2022-01-28")
url=https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2022-01-28/2022-01-28-raspios-bullseye-armhf-lite.zip
;;
"raspios_lite_arm64:2022-01-28")
url=https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2022-01-28/2022-01-28-raspios-bullseye-arm64-lite.zip
;;
"dietpi:rpi_armv6_bullseye")
url=https://dietpi.com/downloads/images/DietPi_RPi-ARMv6-Bullseye.7z
;;
"dietpi:rpi_armv7_bullseye")
url=https://dietpi.com/downloads/images/DietPi_RPi-ARMv7-Bullseye.7z
;;
"dietpi:rpi_armv8_bullseye")
url=https://dietpi.com/downloads/images/DietPi_RPi-ARMv8-Bullseye.7z
;;
"raspi_1_bullseye:20220121")
url=https://raspi.debian.net/tested/20220121_raspi_1_bullseye.img.xz
;;
"raspi_2_bullseye:20220121")
url=https://raspi.debian.net/tested/20220121_raspi_2_bullseye.img.xz
;;
"raspi_3_bullseye:20220121")
url=https://raspi.debian.net/tested/20220121_raspi_3_bullseye.img.xz
;;
"raspi_4_bullseye:20220121")
url=https://raspi.debian.net/tested/20220121_raspi_4_bullseye.img.xz
;;
https:/*|http:/*)
url="$1"
;;
Expand Down
8 changes: 6 additions & 2 deletions mount_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ cp "${mount}/etc/resolv.conf" "${mount}/etc/_resolv.conf"
cp /etc/resolv.conf "${mount}/etc/resolv.conf"
cp /usr/bin/qemu-arm-static0 ${mount}/usr/bin/qemu-arm-static0
cp /usr/bin/qemu-arm-static ${mount}/usr/bin/qemu-arm-static
cp "${mount}/etc/ld.so.preload" "${mount}/etc/_ld.so.preload"
echo "" > "${mount}/etc/ld.so.preload"
cp /usr/bin/qemu-aarch64-static0 ${mount}/usr/bin/qemu-aarch64-static0
cp /usr/bin/qemu-aarch64-static ${mount}/usr/bin/qemu-aarch64-static
if [ -e "${mount}/etc/ld.so.preload" ]; then
cp "${mount}/etc/ld.so.preload" "${mount}/etc/_ld.so.preload"
echo > "${mount}/etc/ld.so.preload"
fi
6 changes: 5 additions & 1 deletion qemu-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define STR(cpu) #cpu

int main(int argc, char **argv, char **envp) {
int this_len = strlen(argv[0]);
char staticpath[this_len + 2];
char *newargv[argc + 3];

newargv[0] = argv[0];
Expand All @@ -19,5 +21,7 @@ int main(int argc, char **argv, char **envp) {

memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc -1));
newargv[argc + 2] = NULL;
return execve("/usr/bin/qemu-arm-static0", newargv, envp);
strncpy(staticpath, argv[0], this_len + 2);
staticpath[this_len] = '0';
return execve(staticpath, newargv, envp);
}

0 comments on commit 171180e

Please sign in to comment.