Skip to content

Commit

Permalink
more separation between devices and add option to build image
Browse files Browse the repository at this point in the history
  • Loading branch information
Maccraft123 committed Dec 11, 2020
1 parent 08e049d commit 62b3689
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tmp/*
vmlinux.kpart
vmlinux.kpart.mmc
*.img
40 changes: 31 additions & 9 deletions build-all
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,56 @@ set -e

sleep 1 # let's give user time if they commit a typo

dd if=/dev/zero of=$1 bs=1M count=64
# Usage:
# build-all <device>
# build-all <file> <size>

if [ -n "$2" ]; then # if $2 is set, it means that user wants a file
echo "Making file $1 with size of $2"
fallocate $CADMIUMROOT/$1 -l $2
DEVICE=$(losetup -f)
losetup $DEVICE $CADMIUMROOT/$1

KERNPART=${DEVICE}p1
ROOTPART=${DEVICE}p2
else
DEVICE=$1
KERNPART=${DEVICE}1
ROOTPART=${DEVICE}2
dd if=/dev/zero of=$DEVICE bs=1M count=64
fi


sync

# make partition table
parted --script $1 mklabel gpt # cgpt dislikes if i don't do that, so do that
parted --script $DEVICE mklabel gpt # cgpt dislikes if i don't do that, so do that

# now this is _real_ partition table
cgpt create $1
cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $1
cgpt add -i 2 -t data -b 73728 -s $(expr $(cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}') - 73728) -l Root $1
cgpt add -i 1 -t kernel -b 8192 -s 65536 -l Kernel -S 1 -T 5 -P 10 $DEVICE
cgpt add -i 2 -t data -b 73728 -s $(expr $(cgpt show $1 | grep 'Sec GPT table' | awk '{print $1}') - 73728) -l Root $DEVICE
sync

# reread partition table
partx -a $1 || true
partx -a $DEVICE || true
sync

# build and write kernel
./kernel/build $CADMIUMROOT $TARGET
dd if=tmp/linux/vmlinux.kpart of=${1}1
./kernel/build $CADMIUMROOT
dd if=$CADMIUMROOT/tmp/linux-$TARGET/vmlinux.kpart of=$KERNPART

# write filesystem
./fs/build $CADMIUMROOT $TARGET ${1}2
./fs/build $CADMIUMROOT $ROOTPART

# install modules
make -C $CADMIUMROOT/tmp/linux ARCH=arm64 INSTALL_MOD_PATH=$CADMIUMROOT/tmp/root modules_install
make -C $CADMIUMROOT/tmp/linux-$TARGET ARCH=arm64 INSTALL_MOD_PATH=$CADMIUMROOT/tmp/root modules_install

# we don't umount it in fs/build
umount $CADMIUMROOT/tmp/root

losetup -d $DEVICE || true

sync

echo "Done!"
1 change: 1 addition & 0 deletions config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/false

# Target device
# It is sorta using codenames, but "kukui" sounds stupid so i won't use it
# One of: duet, kevin
TARGET=duet

Expand Down
10 changes: 5 additions & 5 deletions fs/build
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/bin/bash
CADMIUMROOT=$1
PART=$3
ROOTPART=$2

set -e

source $CADMIUMROOT/config

cd $CADMIUMROOT/tmp
mkdir -p root
mkfs.ext4 $PART
mount $PART root
mkfs.ext4 $ROOTPART
mount $ROOTPART root

# if we are on arm64 machine, don't use qemu to execute arm64 code
if [ "$(uname -m)" = "aarch64" ]; then
debootstrap --arch=arm64 sid root/ https://deb.debian.org/debian/ || true
debootstrap --arch=arm64 sid $CADMIUMROOT/tmp/root/ https://deb.debian.org/debian/ || true
echo "Running on ARM64 machine"
else
cp $(which qemu-aarch64-static) root/
qemu-debootstrap --arch=arm64 sid root/ https://deb.debian.org/debian/ || true
qemu-debootstrap --arch=arm64 sid $CADMIUMROOT/tmp/root/ https://deb.debian.org/debian/ || true
qemu=/qemu-aarch64-static
echo "Running on not-ARM64 machine"
fi
Expand Down
43 changes: 24 additions & 19 deletions kernel/build
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,33 @@ cd $CADMIUMROOT/tmp


# check if kernel has been downloaded this week, if not download/update it
if [ "$(date +'%V%y')" != "$(cat kern-dl-date || true)" ]; then
if [ "$(date +'%V%y')" != "$(cat kern-dl-date)" ]; then
case $TARGET in
duet)
if [ -d "$CADMIUMROOT/tmp/linux" ]; then
cd linux
git pull
duet)
if [ -d "$CADMIUMROOT/tmp/linux-duet" ]; then
echo "Updating kernel for duet"
cd linux-duet
git pull
echo $(date +'%V%y') > kern-dl-date
else
echo "Downloading kernel for duet"
git clone https://github.com/Maccraft123/linux-duet -b panfrost/duet linux-duet
echo $(date +'%V%y') > kern-dl-date
cd linux-duet
fi
;;
*)
echo "Downloading kernel for kevin"
rm -rf linux-kevin
curl -L "$(curl -sL https://www.kernel.org/ | grep "Download complete tarball" | head -n1 | tr '"' ' ' | awk '{print $3}')" -o Linux-archive
mkdir linux-kevin
bsdtar xf Linux-archive --strip-components=1 -C linux-kevin
echo $(date +'%V%y') > kern-dl-date
else
git clone https://github.com/Maccraft123/linux-duet -b panfrost/duet linux
echo $(date +'%V%y') > kern-dl-date
cd linux
fi
;;
*)
rm -rf linux
curl -L "$(curl -sL https://www.kernel.org/ | grep "Download complete tarball" | head -n1 | tr '"' ' ' | awk '{print $3}')" -o Linux-archive
mkdir linux
bsdtar xf Linux-archive --strip-components=1 -C linux
echo $(date +'%V%y') > kern-dl-date
;;
esac
fi

cd linux
cd $CADMIUMROOT/tmp/linux-$TARGET

cp $CADMIUMROOT/kernel/config-$TARGET .config
cp $CADMIUMROOT/kernel/kernel-$TARGET.its kernel.its
Expand All @@ -49,7 +53,7 @@ cp $CADMIUMROOT/kernel/cmdline cmdline
# patch -p1 < $CADMIUMROOT/kernel/patches/$x
#done

make nconfig # if you want to customize config just uncomment this
#make nconfig # if you want to customize config just uncomment this

# backup old config if it's different, and copy new custom config
if [ "$(sha1sum $CADMIUMROOT/kernel/config-$TARGET)" = "$(sha1sum .config)" ]; then
Expand All @@ -72,5 +76,6 @@ vbutil_kernel --pack vmlinux.kpart \
--signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
--config cmdline \
--bootloader bootloader.bin
rm vmlinux.uimg

cp vmlinux.kpart $CADMIUMROOT/
23 changes: 17 additions & 6 deletions kernel/install
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#!/bin/bash
CADMIUMROOT=$1
DEV=$2
DEVICE=$2
KERNPART=$3
ROOTPART=$4

if [ -z "$4" ]; then
KERNPART=${DEVICE}1
ROOTPART=${DEVICE}2
fi

shopt -s expand_aliases # needed for aliases
set -e

source $CADMIUMROOT/config

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-

# set up alias areweontarget so "if areweontarget; then X" works fine
if cat /sys/firmware/devicetree/base/compatible | grep -s krane; then
if cat /sys/firmware/devicetree/base/compatible 2>/dev/null | grep -s krane; then
if [ -z "$DEV" ]; then
alias areweontarget=true
else
Expand All @@ -19,9 +28,9 @@ else
alias areweontarget=false
fi

areweontarget || mount ${DEV}2 /mnt
areweontarget || mount $ROOTPART /mnt

cd $CADMIUMROOT/tmp/linux
cd $CADMIUMROOT/tmp/linux-$TARGET

mkimage -D "-I dts -O dtb -p 2048" -f kernel.its vmlinux.uimg || true

Expand Down Expand Up @@ -65,8 +74,10 @@ if areweontarget; then
else
make INSTALL_MOD_PATH=/mnt/ modules_install
umount /mnt
dd if=${DEV}1 of=$CADMIUMROOT/tmp/backup bs=1M count=32 # backup kernel partition, just in case
dd if=$CADMIUMROOT/tmp/linux/vmlinux.kpart.pad of=${DEV}1
dd if=$KERNPART of=$CADMIUMROOT/tmp/backup bs=1M count=32 # backup kernel partition, just in case
dd if=$CADMIUMROOT/tmp/linux-$TARGET/vmlinux.kpart.pad of=$KERNPART
fi

rm $CADMIUMROOT/tmp/linux-$TARGET/vmlinux.uimg

sync

0 comments on commit 62b3689

Please sign in to comment.