diff options
Diffstat (limited to 'vm.sh')
-rwxr-xr-x | vm.sh | 69 |
1 files changed, 69 insertions, 0 deletions
@@ -0,0 +1,69 @@ +#!/bin/sh + +set -xe + +function run +{ + # 32 bit does NOT work, even if the kernel is obviously compiled + # for 32 bit, the binary could be broken, but I didn't manage to + # build qemu from source, + # pretty sure that riscv32-unknown-linux-gnu- works fine + qemu-system-riscv64 \ + -machine virt \ + -kernel "$BIN/$KERNEL" \ + -initrd "$BIN/$INITFS" \ + -append "console=ttyS0" -nographic \ + -monitor none \ + -serial stdio +} + +function initramfs +{ + IMG="$(pwd)/$BIN/$INITFS" + DIR="${IMG%.*}" + mkdir -p $DIR + + # copy the program + cp $1 "$DIR/init" + + # make image and delete folder + (cd $DIR; find . | cpio -H newc -o | gzip > $IMG) + rm -rf $DIR +} + +function kernel +{ + DIR="${KERNEL%.*}" + ARCHIVE="$DIR.tar.xz" + + BACKUP="backup" + mkdir -p $BACKUP + + if [[ -n $(find backup/ -type f -name "$KERNEL") ]]; then + cp $BACKUP/$KERNEL $BIN/ + exit 0 + fi + + if [[ -n $(find backup/ -type f -name "$ARCHIVE") ]]; then + cp $BACKUP/$ARCHIVE $BIN/ + else + wget -P $BIN https://cdn.kernel.org/pub/linux/kernel/v5.x/$ARCHIVE + cp $BIN/$ARCHIVE $BACKUP/ + fi + + tar -xf $BIN/$ARCHIVE -C $BIN/ + rm $BIN/$ARCHIVE + + # TOOLCHAIN in the Makefile + cd $BIN/$DIR + make ARCH=riscv CROSS_COMPILE=$TOOLCHAIN defconfig + make ARCH=riscv CROSS_COMPILE=$TOOLCHAIN -j $(nproc) + cd ../../ + + cp $BIN/$DIR/arch/riscv/boot/Image $BIN/$KERNEL + cp $BIN/$KERNEL $BACKUP + + rm -rf $BIN/$DIR +} + +$1 $2 |