Build multiple images and nice errors

This commit is contained in:
Martijn Braam 2020-03-17 19:19:34 +01:00
parent 7dfbc13bc2
commit 0257d43859
No known key found for this signature in database
GPG Key ID: C4280ACB000B060F
14 changed files with 155 additions and 87 deletions

17
.gitignore vendored
View File

@ -1,13 +1,12 @@
/Image.gz /*.img
/fat.img
/jumpdrive.img
/jumpdrive.img.xz
/u-boot-sunxi-with-spl.bin
/*.apk /*.apk
/initramfs.gz
/initramfs.cpio
/initramfs/bin/busybox /initramfs/bin/busybox
/initramfs/splash.ppm.gz /initramfs-*
/build /build
/boot.scr /dtbs
/*.scr
/*.dtb /*.dtb
/*.img.xz
/*.gz
/*.bin
/splash/*.gz

154
Makefile
View File

@ -1,74 +1,112 @@
CROSS_FLAGS = ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- CROSS_FLAGS = ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
all: jumpdrive.img.xz all: pine64-pinephone.img.xz pine64-pinetab.img.xz
jumpdrive.img.xz: jumpdrive.img
xz -c jumpdrive.img > jumpdrive.img.xz pine64-pinephone.img: fat-pine64-pinephone.img u-boot-sunxi-with-spl.bin
rm -f $@
truncate --size 50M $@
parted -s $@ mktable msdos
parted -s $@ mkpart primary fat32 2048s 100%
parted -s $@ set 1 boot on
dd if=u-boot-sunxi-with-spl.bin of=$@ bs=8k seek=1
dd if=fat-$@ of=$@ seek=1024 bs=1k
fat-pine64-pinephone.img: initramfs-pine64-pinephone.gz kernel-sunxi.gz pine64-pinephone.scr dtbs/sunxi/sun50i-a64-pinephone.dtb
@echo "MKFS $@"
@rm -f $@
@truncate --size 40M $@
@mkfs.fat -F32 $@
@mcopy -i $@ kernel-sunxi.gz ::Image.gz
@mcopy -i $@ dtbs/sunxi/sun50i-a64-pinephone.dtb ::sun50i-a64-pinephone.dtb
@mcopy -i $@ initramfs-pine64-pinephone.gz ::initramfs.gz
@mcopy -i $@ pine64-pinephone.scr ::boot.scr
pine64-pinetab.img: fat-pine64-pinetab.img u-boot-sunxi-with-spl.bin
rm -f $@
truncate --size 50M $@
parted -s $@ mktable msdos
parted -s $@ mkpart primary fat32 2048s 100%
parted -s $@ set 1 boot on
dd if=u-boot-sunxi-with-spl.bin of=$@ bs=8k seek=1
dd if=fat-$@ of=$@ seek=1024 bs=1k
fat-pine64-pinetab.img: initramfs-pine64-pinetab.gz kernel-sunxi.gz pine64-pinetab.scr dtbs/sunxi/sun50i-a64-pinetab.dtb
@echo "MKFS $@"
@rm -f $@
@truncate --size 40M $@
@mkfs.fat -F32 $@
@mcopy -i $@ kernel-sunxi.gz ::Image.gz
@mcopy -i $@ dtbs/sunxi/sun50i-a64-pinetab.dtb ::sun50i-a64-pinetab.dtb
@mcopy -i $@ initramfs-pine64-pinetab.gz ::initramfs.gz
@mcopy -i $@ pine64-pinetab.scr ::boot.scr
%.img.xz: %.img
@echo "XZ $@"
@xz -c $< > $@
initramfs/bin/busybox: src/busybox src/busybox_config initramfs/bin/busybox: src/busybox src/busybox_config
mkdir -p build/busybox @echo "MAKE $@"
cp src/busybox_config build/busybox/.config @mkdir -p build/busybox
make -C src/busybox O=../../build/busybox $(CROSS_FLAGS) @cp src/busybox_config build/busybox/.config
cp build/busybox/busybox initramfs/bin/busybox @$(MAKE) -C src/busybox O=../../build/busybox $(CROSS_FLAGS)
@cp build/busybox/busybox initramfs/bin/busybox
initramfs/splash.ppm.gz: splash/jumpdrive.ppm splash/%.ppm.gz: splash/%.ppm
gzip < splash/jumpdrive.ppm > initramfs/splash.ppm.gz @echo "GZ $@"
@gzip < $< > $@
initramfs.cpio: initramfs/bin/busybox initramfs/init initramfs/init_functions.sh initramfs/splash.ppm.gz initramfs-%.cpio: initramfs/bin/busybox initramfs/init initramfs/init_functions.sh splash/%.ppm.gz splash/%-error.ppm.gz
cd initramfs; find . | cpio -H newc -o > ../initramfs.cpio @echo "CPIO $@"
@rm -rf initramfs-$*
@cp -r initramfs initramfs-$*
@cp src/info-$*.sh initramfs-$*/info.sh
@cp splash/$*.ppm.gz initramfs-$*/splash.ppm.gz
@cp splash/$*-error.ppm.gz initramfs-$*/error.ppm.gz
@cp src/info-$*.sh initramfs-$*/info.sh
@cd initramfs-$*; find . | cpio -H newc -o > ../$@
initramfs.gz: initramfs.cpio initramfs-%.gz: initramfs-%.cpio
gzip < initramfs.cpio > initramfs.gz @echo "GZ $@"
@gzip < $< > $@
Image.gz: src/linux_config kernel-sunxi.gz: src/linux_config
mkdir -p build/linux @echo "MAKE $@"
cp src/linux_config build/linux/.config @mkdir -p build/linux-sunxi
make -C src/linux O=../../build/linux $(CROSS_FLAGS) olddefconfig @mkdir -p dtbs/sunxi
make -C src/linux O=../../build/linux $(CROSS_FLAGS) @cp src/linux_config build/linux-sunxi/.config
cp build/linux/arch/arm64/boot/Image.gz Image.gz @$(MAKE) -C src/linux O=../../build/linux-sunxi $(CROSS_FLAGS) olddefconfig
cp build/linux/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtb sun50i-a64-pinephone.dtb @$(MAKE) -C src/linux O=../../build/linux-sunxi $(CROSS_FLAGS)
@cp build/linux-sunxi/arch/arm64/boot/Image.gz $@
@cp build/linux-sunxi/arch/arm64/boot/dts/allwinner/*.dtb dtbs/sunxi/
jumpdrive.img: fat.img u-boot-sunxi-with-spl.bin %.scr: src/%.txt
rm -f jumpdrive.img @echo "MKIMG $@"
truncate --size 50M jumpdrive.img @mkimage -A arm -O linux -T script -C none -n "U-Boot boot script" -d $< $@
parted -s jumpdrive.img mktable msdos
parted -s jumpdrive.img mkpart primary fat32 2048s 100%
parted -s jumpdrive.img set 1 boot on
dd if=u-boot-sunxi-with-spl.bin of=jumpdrive.img bs=8k seek=1
dd if=fat.img of=jumpdrive.img seek=1024 bs=1k
boot.scr: src/boot.txt
mkimage -A arm -O linux -T script -C none -n "U-Boot boot script" -d src/boot.txt boot.scr
u-boot-sunxi-with-spl.bin: u-boot-sunxi-with-spl.bin:
wget http://dl-cdn.alpinelinux.org/alpine/edge/main/aarch64/u-boot-pine64-2020.01-r0.apk @echo "WGET $@"
tar -xvf u-boot-pine64-2020.01-r0.apk usr/share/u-boot/pine64-lts/u-boot-sunxi-with-spl.bin --strip-components 4 @wget http://dl-cdn.alpinelinux.org/alpine/edge/main/aarch64/u-boot-pine64-2020.01-r0.apk
@tar -xvf u-boot-pine64-2020.01-r0.apk usr/share/u-boot/pine64-lts/u-boot-sunxi-with-spl.bin --strip-components 4
fat.img: initramfs.gz Image.gz boot.scr
rm -f fat.img
truncate --size 40M fat.img
mkfs.fat -F32 fat.img
mcopy -i fat.img Image.gz ::Image.gz
mcopy -i fat.img sun50i-a64-pinephone.dtb ::sun50i-a64-pinephone.dtb
mcopy -i fat.img initramfs.gz ::initramfs.gz
mcopy -i fat.img boot.scr ::boot.scr
.PHONY: clean .PHONY: clean cleanfast
clean: cleanfast:
rm -rf build @rm -rvf build
rm -f initramfs/bin/busybox @rm -vf *.img
rm -f fat.img @rm -vf *.img.xz
rm -f jumpdrive.img @rm -vf *.apk
rm -f jumpdrive.img.xz @rm -vf *.bin
rm -f *.dtb @rm -vf *.cpio
rm -f u-boot-pine64-2020.01-r0.apk @rm -vf *.gz
rm -f u-boot-sunxi-with-spl.bin @rm -vf *.scr
rm -f initramfs/splash.ppm.gz @rm -vf splash/*.gz
rm -f initramfs/bin/busybox
rm -f initramfs.cpio clean: cleanfast
rm -f initramfs.gz @rm -vf kernel*.gz
rm -f Image.gz @rm -vf initramfs/bin/busybox
rm -f boot.scr @rm -vrf dtbs

View File

@ -7,6 +7,9 @@
echo "Welcome to JumpDrive" echo "Welcome to JumpDrive"
. /info.sh
echo "Running on $PLATFORM"
. /init_functions.sh . /init_functions.sh
# Environment variables that we want: # Environment variables that we want:
@ -32,10 +35,10 @@ mount -t configfs -o nodev,noexec,nosuid configfs /config
mkdir -p /dev/pts mkdir -p /dev/pts
mount -t devpts devpts /dev/pts mount -t devpts devpts /dev/pts
# Amber LED indicator for MMC r/w access # LED indicator for MMC r/w access
echo mmc2 > /sys/class/leds/pinephone\:green\:user/trigger if [ -n "$LED" ]; then
echo mmc2 > /sys/class/leds/pinephone\:red\:user/trigger echo $TRIGGER > /sys/class/leds/$LED/trigger
fi
# Create device nodes # Create device nodes
echo "Creating device nodes..." echo "Creating device nodes..."

View File

@ -8,8 +8,7 @@ setup_usb_configfs() {
CONFIGFS=/config/usb_gadget CONFIGFS=/config/usb_gadget
if ! [ -e "$CONFIGFS" ]; then if ! [ -e "$CONFIGFS" ]; then
echo "$CONFIGFS does not exist, this is not good." fatal_error "$CONFIGFS does not exist"
crash_kernel
fi fi
# Default values for USB-related deviceinfo variables # Default values for USB-related deviceinfo variables
@ -21,7 +20,7 @@ setup_usb_configfs() {
echo "Setting up an USB gadget through configfs..." echo "Setting up an USB gadget through configfs..."
# Create an usb gadet configuration # Create an usb gadet configuration
mkdir $CONFIGFS/g1 || ( echo "Couldn't create $CONFIGFS/g1" ; crash_kernel ) mkdir $CONFIGFS/g1 || ( fatal_error "Couldn't create $CONFIGFS/g1" )
echo "$usb_idVendor" > "$CONFIGFS/g1/idVendor" echo "$usb_idVendor" > "$CONFIGFS/g1/idVendor"
echo "$usb_idProduct" > "$CONFIGFS/g1/idProduct" echo "$usb_idProduct" > "$CONFIGFS/g1/idProduct"
@ -48,14 +47,13 @@ setup_usb_configfs() {
echo "rndis" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration \ echo "rndis" > $CONFIGFS/g1/configs/c.1/strings/0x409/configuration \
|| echo " Couldn't write configration name" || echo " Couldn't write configration name"
# Make sure there is a mmcblk2 (eMMC)... # Make sure the node for the eMMC exists
if [ -z "$(ls /dev/mmcblk2)" ]; then if [ -z "$(ls $EMMC)" ]; then
echo "/dev/mmcblk2 could not be opened, possible eMMC defect" fatal_error "$EMMC could not be opened, possible eMMC defect"
crash_kernel
fi fi
# Set up mass storage to internal EMMC # Set up mass storage to internal EMMC
echo /dev/mmcblk2 > $CONFIGFS/g1/functions/"$usb_mass_storage_function"/lun.0/file echo $EMMC > $CONFIGFS/g1/functions/"$usb_mass_storage_function"/lun.0/file
# Link the rndis/mass_storage instance to the configuration # Link the rndis/mass_storage instance to the configuration
ln -s $CONFIGFS/g1/functions/"$usb_rndis_function" $CONFIGFS/g1/configs/c.1 \ ln -s $CONFIGFS/g1/functions/"$usb_rndis_function" $CONFIGFS/g1/configs/c.1 \
@ -65,12 +63,11 @@ setup_usb_configfs() {
# Check if there's an USB Device Controller # Check if there's an USB Device Controller
if [ -z "$(ls /sys/class/udc)" ]; then if [ -z "$(ls /sys/class/udc)" ]; then
echo "No USB Device Controller available" fatal_error "No USB Device Controller available"
crash_kernel
fi fi
# shellcheck disable=SC2005 # shellcheck disable=SC2005
echo "$(ls /sys/class/udc)" > $CONFIGFS/g1/UDC || ( echo "Couldn't write UDC." ; crash_kernel ) echo "$(ls /sys/class/udc)" > $CONFIGFS/g1/UDC || ( fatal_error "Couldn't write to UDC" )
} }
setup_telnetd() { setup_telnetd() {
@ -124,11 +121,19 @@ start_udhcpd() {
udhcpd udhcpd
} }
crash_kernel() { fatal_error() {
echo "panic: We're hanging here..." clear
# shellcheck disable=SC1001
echo panic > /sys/class/leds/pinephone\:red\:user/trigger # Move cursor into position for error message
echo c > /proc/sysrq-trigger echo -e "\033[$ERRORLINES;0H"
gzip -c -d error.ppm.gz > /error.ppm
fbsplash -s /error.ppm
# Print the error message over the error splash
echo " $1"
loop_forever
} }
loop_forever() { loop_forever() {

Binary file not shown.

Binary file not shown.

BIN
splash/pine64-pinetab.ppm Normal file

Binary file not shown.

BIN
splash/pine64-pinetab.xcf Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
PLATFORM=pine64-pinephone
EMMC=/dev/mmcblk2
LED=pinephone\:red\:user
TRIGGER=mmc2
ERRORLINES=80

View File

@ -0,0 +1,2 @@
PLATFORM=pine64-pinetab
EMMC=/dev/mmcblk2

16
src/pine64-pinetab.txt Normal file
View File

@ -0,0 +1,16 @@
setenv kernel_addr_z 0x44080000
setenv bootargs loglevel=0 silent console=tty0
gpio set 114
if load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_z} /Image.gz; then
unzip ${kernel_addr_z} ${kernel_addr_r}
if load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} /sun50i-a64-pinetab.dtb; then
if load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /initramfs.gz; then
booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
else
booti ${kernel_addr_r} - ${fdt_addr_r};
fi;
fi;
fi