Files
meta-mortsgna/scripts/include/machine-raspberrypi.inc
Andreas Müller 5d484f1a8a Card write all supported machines: Show progress
Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
2022-05-06 10:34:30 +02:00

77 lines
2.7 KiB
Bash

#! /bin/bash
# machine-raspberrypi.inc
# (c) Copyright 2021 Andreas Müller <schnitzeltony@gmail.com>
# Licensed under terms of GPLv2
#
# This script contains settings and callbacks fir raspberrypi boards
# default settings
DEFAULT_MACHINE_FAMILY='raspberrypi*'
DEFAULT_FIND_ROOTFS='-name *.rpi-sdimg -type l -o -name *.wic -type l -o -name *.wic.bz2 -type l'
DEFAULT_KERNEL_IMAGE_TYPE='Image'
# callback for card-write
RootCardWriteCallback() {
# rootfs write/resize to card fit
time(
# evt. write partition table
CheckPartitionTable "$DevicePath"
# write
StartMessage="\nWrite $DeployedFile to $DevicePath..."
if echo $DeployedFile | grep -q '.wic.bz2'; then
EvalExAuto "bunzip2 -c $DeployedFile | dd of=$DevicePath status=progress oflag=nocache bs=1024K" "$StartMessage"
else
EvalExAuto "dd of=$DevicePath status=progress oflag=nocache if=$DeployedFile bs=1024K" "$StartMessage"
fi
# resize I
EvalExAuto "parted -s $DevicePath -- resizepart 2 -0" "\nResize I ${DevicePath}2..."
# resize II
EvalExAuto "resize2fs ${DevicePath}2" "\nResize II ${DevicePath}2..."
)
}
# callback for card-kernel-write
RootCardKernelWriteCallback() {
tmpdir=`mktemp -d`
# mount boot partition
EvalExAuto "mount ${DevicePath}1 $tmpdir" "\nMount boot partition ${DevicePath}1 to $tmpdir..."
# initial kernel (REVISIT for aarch64)
EvalExAuto "cp -f $DeployedFile $tmpdir/kernel7.img" "\nCopy new kernel kernel7.img..."
# devicetrees
EvalExAuto "rm -f $tmpdir/*.dtb" "\nRemove old devicetrees..."
echo
for dtb in `find ${DeployFileDir} -name "bcm27*.dtb"`; do
EvalExAuto "cp -f $dtb $tmpdir/" "Copy $dtb -> $tmpdir..."
done
# devicetree overlays
EvalExAuto "rm -f $tmpdir/overlays/*.dtbo" "\nRemove old devicetree-overlays..."
echo
for dtbo in `find ${DeployFileDir} -name "*.dtbo"`; do
bname=`basename $dtbo`
if ! echo "${bname}" | grep -q 'Image-'; then
EvalExAuto "cp -f ${dtbo} $tmpdir/overlays/" "Copy $dtbo -> $tmpdir/overlays/..."
fi
done
# TODO bootfiles?
# unmount boot partition
EvalExAuto "sleep 1 && umount ${DevicePath}1" "\nUnmount boot partition..."
# mount rootfs partition
EvalExAuto "mount ${DevicePath}2 $tmpdir" "\nMount rootfs partition ${DevicePath}2 to $tmpdir..."
# Note: /boot is empty by default!!
# kernel modules
CopyKernelModules
RegisterKernelModules
# unmount rootfs
EvalExAuto "sleep 1 && umount ${DevicePath}2" "\nUnmount rootfs..."
rm -rf $tmpdir
}
CheckPrerequisite "time"
CheckPrerequisite "dd"
CheckPrerequisite "parted"
CheckPrerequisite "resize2fs"