-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
5,852 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.