Skip to content

Commit

Permalink
Merge branch 'arm'
Browse files Browse the repository at this point in the history
  • Loading branch information
WeirdTreeThing committed Dec 10, 2023
2 parents 051bed9 + 29ace87 commit a682493
Show file tree
Hide file tree
Showing 4 changed files with 5,852 additions and 34 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ on:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform: ["x86_64", "arm64"]
runs-on: ${{ matrix.platform == 'x86_64' && 'ubuntu-latest' || 'ARM64' }}
container:
image: registry.fedoraproject.org/fedora-minimal:39

steps:
- name: Install dependencies
run: |
dnf5 update -y
dnf5 install -y git make gcc ccache flex bison elfutils-devel parted vboot-utils golang xz bc tar
dnf5 install -y git make gcc ccache flex bison elfutils-devel parted vboot-utils golang xz bc tar openssl-devel
- uses: actions/checkout@v3
with:
Expand All @@ -39,30 +42,30 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ env.GOCACHE }}
key: go-${{ env.UROOT_COMMIT }}
key: go-${{ matrix.platform }}-${{ env.UROOT_COMMIT }}
restore-keys: |
go-
go-${{ matrix.platform }}-
- name: Setup ccache cache
uses: actions/cache@v3
with:
path: ${{ env.CCACHE_DIR }}
key: ccache-${{ env.KERNEL_COMMIT }}-${{ hashFiles('kernel.config') }}
key: ccache-${{ matrix.platform }}-${{ env.KERNEL_COMMIT }}-${{ hashFiles('kernel.config') }}
restore-keys: |
ccache-${{ env.KERNEL_COMMIT }}-
ccache-
ccache-${{ matrix.platform }}-${{ env.KERNEL_COMMIT }}-
ccache-${{ matrix.platform }}-
- name: Install u-root
run: go install github.com/u-root/u-root@$UROOT_COMMIT

- name: Copy submarine kernel config
run: cp kernel.config kernel/.config
- name: Copy submarine kernel configuration
run: cp configs/kernel.${{ matrix.platform == 'x86_64' && 'x86' || 'mt8183' }} kernel/.config

- name: Build submarine
run: make CC="ccache gcc" -j$(nproc)
run: make CC="ccache gcc" -j$(nproc) ${{ matrix.platform }}

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: submarine
name: submarine-${{ matrix.platform }}
path: build
97 changes: 75 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,86 @@
BZIMAGE=build/bzImage
INITFS=build/initramfs.cpio
INITFSZ=build/initramfs.cpio.xz
KPART=build/submarine.kpart
IMG=build/submarine.bin
project_name = submarine

.PHONY: clean
# Common directories
WORKDIR=build
CONFDIR=configs
OUTPUTDIR=images
TMPFILE=/tmp/$(project_name)

all: $(IMG)
# x86 machines use common kernel configuration
CONFIG_X64=kernel.x86
BZIMAGE_X64=bzImage.x86
INITFS_X64=u-root-x86.cpio
INITFSZ_X64=u-root-x86.cpio.xz
KPART_X64=$(project_name)-x86.kpart
IMG_X64=$(project_name)-x86.bin

$(IMG): $(KPART)
fallocate -l 18M $(IMG)
parted $(IMG) mklabel gpt --script
cgpt add -i 1 -t kernel -b 2048 -s 32767 -P 15 -T 1 -S 1 $(IMG)
dd if=$(KPART) of=$(IMG) bs=512 seek=2048 conv=notrunc
# The only supported ARM64 platform right now is MediaTek MT8183.
CONFIG_MT8183=kernel.mt8183
BZIMAGE_A64=bzImage.a64
INITFS_A64=u-root-a64.cpio
INITFSZ_A64=u-root-a64.cpio.xz
KPART_A64=$(project_name)-a64.kpart
IMG_A64=$(project_name)-a64.bin

$(KPART): $(BZIMAGE)
echo submarine > /tmp/submarine
futility vbutil_kernel --pack $(KPART) --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --keyblock /usr/share/vboot/devkeys/kernel.keyblock --config /tmp/submarine --bootloader /tmp/submarine --vmlinuz $(BZIMAGE) --version 1 --arch x86
.PHONY: usage

$(BZIMAGE): $(INITFSZ)
usage:
@echo "usage: make [x86_64|arm64]"

# Use 'make: x86_64' to build x86 image.
x86_64: $(IMG_X64)
$(IMG_X64): $(KPART_X64)
fallocate -l 18M $(WORKDIR)/$(IMG_X64)
parted $(WORKDIR)/$(IMG_X64) mklabel gpt --script
cgpt add -i 1 -t kernel -b 2048 -s 32767 -P 15 -T 1 -S 1 $(WORKDIR)/$(IMG_X64)
dd if=$(WORKDIR)/$(KPART_X64) of=$(WORKDIR)/$(IMG_X64) bs=512 seek=2048 conv=notrunc
mkdir -p $(OUTPUTDIR)
cp $(WORKDIR)/$(IMG_X64) $(OUTPUTDIR)/$(IMG_X64)
@echo 'Build complete! Resulting file saved as "$(IMG_X64)" in "images" directory.'

$(KPART_X64): $(BZIMAGE_X64)
echo $(project_name) > $(TMPFILE)
futility vbutil_kernel --pack $(WORKDIR)/$(KPART_X64) --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --keyblock /usr/share/vboot/devkeys/kernel.keyblock --config $(TMPFILE) --bootloader $(TMPFILE) --vmlinuz $(WORKDIR)/$(BZIMAGE_X64) --version 1 --arch x86

$(BZIMAGE_X64): $(INITFSZ_X64)
cp $(CONFDIR)/$(CONFIG_X64) kernel/.config
make -C kernel
cp kernel/arch/x86/boot/bzImage $(BZIMAGE)
cp kernel/arch/x86/boot/bzImage $(WORKDIR)/$(BZIMAGE_X64)

$(INITFSZ): $(INITFS)
xz -kf -9 --check=crc32 $(INITFS)
$(INITFSZ_X64): $(INITFS_X64)
xz -kf -9 --check=crc32 $(WORKDIR)/$(INITFS_X64)

$(INITFS):
$(INITFS_X64):
mkdir -p build
GBB_PATH=u-root u-root -o $(INITFS) -uinitcmd="elvish -c 'sleep 3; boot'" core ./cmds/boot/boot
GBB_PATH=u-root u-root -o $(WORKDIR)/$(INITFS_X64) -uinitcmd="elvish -c 'sleep 3; boot'" core ./cmds/boot/boot


# Use 'make arm64' to build ARM64 (cross-compiling is supported).
arm64: $(IMG_A64)
$(IMG_A64): $(KPART_A64)
fallocate -l 18M $(WORKDIR)/$(IMG_A64)
parted $(WORKDIR)/$(IMG_A64) mklabel gpt --script
cgpt add -i 1 -t kernel -b 2048 -s 32767 -P 15 -T 1 -S 1 $(WORKDIR)/$(IMG_A64)
dd if=$(WORKDIR)/$(KPART_A64) of=$(WORKDIR)/$(IMG_A64) bs=512 seek=2048 conv=notrunc
mkdir -p $(OUTPUTDIR)
cp $(WORKDIR)/$(IMG_A64) $(OUTPUTDIR)/$(IMG_A64)
@echo 'Build complete! Resulting file saved as "$(IMG_A64)" in "images" directory.'

$(KPART_A64): $(BZIMAGE_A64)
echo $(project_name) > $(TMPFILE)
futility vbutil_kernel --pack $(WORKDIR)/$(KPART_A64) --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --keyblock /usr/share/vboot/devkeys/kernel.keyblock --config $(TMPFILE) --bootloader $(TMPFILE) --vmlinuz $(WORKDIR)/$(BZIMAGE_A64) --version 1 --arch arm64

$(BZIMAGE_A64): $(INITFSZ_A64)
cp $(CONFDIR)/$(CONFIG_MT8183) kernel/.config
[ uname -m = x86_64 ] && ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -C kernel || make -C kernel
cp kernel/arch/arm64/boot/Image.gz $(WORKDIR)/$(BZIMAGE_A64)

$(INITFSZ_A64): $(INITFS_A64)
xz -kf -9 --check=crc32 $(WORKDIR)/$(INITFS_A64)

$(INITFS_A64):
mkdir -p build images
GBB_PATH=u-root GOOS=linux GOARCH=arm64 u-root -o $(WORKDIR)/$(INITFS_A64) -uinitcmd="elvish -c 'sleep 3; boot'" core ./cmds/boot/boot

clean:
rm -rf build
rm -rf $(WORKDIR)
Loading

0 comments on commit a682493

Please sign in to comment.