Skip to content

Instantly share code, notes, and snippets.

@MikPisula
Created February 9, 2024 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikPisula/e05788acec72efa899945e77ce03a656 to your computer and use it in GitHub Desktop.
Save MikPisula/e05788acec72efa899945e77ce03a656 to your computer and use it in GitHub Desktop.
Install Linux MVEBU for Dell Wyse 3020/Tx0D on a block device (USB, eMMC).
#!/bin/bash
# https://forum.doozan.com/read.php?2,32146
# Debian 5.3.18
#rootfs_dl="https://bitly.com/3F40YnQ"
#rootfs="Debian-5.13.8-mvebu-tld-1-rootfs-bodhi.tar.bz2"
#rootfs_sig="ed620916e376a3b3fa58594e8efccaa1"
# Debian 6.6.2
rootfs_dl="https://bit.ly/3Tq9pTO"
rootfs="Debian-6.6.2-mvebu-tld-1-rootfs-bodhi.tar.bz2"
rootfs_sig="009d315ebc813868344ce9221bcc3c70"
# 6.2.8-tld-2.x
#kernel_dl="https://www.dropbox.com/s/u36k1dahw83fcxp/linux-6.2.8-mvebu-tld-2.x-bodhi.tar.bz2"
#kernel="linux-6.2.8-mvebu-tld-2.x-bodhi.tar.bz2"
#kernel_sig="44a33b221369f65537dd9e30b98f8ee4"
# 6.4.11
# kernel_dl="https://bit.ly/3OMPrPr"
# kernel="linux-6.4.11-mvebu-tld-1-bodhi.tar.bz2"
# kernel_sig="821cb995d0f6e02c11c807a93ab38bd9"
# 6.5.7
kernel_dl="https://bit.ly/3Qrb6i7"
kernel="linux-6.5.7-mvebu-tld-1-bodhi.tar.bz2"
kernel_sig="f972f4bf0e99859c9281bf67c361185d"
# 6.6.2 - currently broken for me
#kernel_dl="https://bit.ly/47Kt3hu"
#kernel="linux-6.6.2-mvebu-tld-1-bodhi.tar.bz2"
#kernel_sig="da257c4ecbc3eb5e39c11728dc85bacd"
if [ $# -eq 0 ]; then
cat <<EOF
Usage: $(basename "$0") <device>
Install Linux MVEBU for Dell Wyse 3020 on a block device.
Arguments:
<device> Target device.
Example:
$(basename "$0") /dev/sdX
Current configuration:
kernel: $kernel ($kernel_dl)
rootfs: $rootfs ($rootfs_dl)
EOF
exit 1
fi
if [ ! -e $rootfs ]; then
echo "Error: $rootfs not found in current working directory. Please download it from $rootfs_dl"
exit 1
fi
if [ ! -e $kernel ]; then
echo "Error: $kernel not found in current working directory. Please download it from $kernel_dl"
exit 1
fi
if [ ! $(md5sum $rootfs | awk '{print $1}') == $rootfs_sig ]; then
echo "Error: MD5 hash verification for $rootfs failed."
exit 1
fi
if [ ! $(md5sum $kernel | awk '{print $1}') == $kernel_sig ]; then
echo "Error: MD5 hash verification for $kernel failed."
exit 1
fi
if [ "$(id -u)" != "0" ]; then
echo "This script requires root privileges."
exit 1
fi
device=$1
if [ ! -e "$device" ]; then
echo "Error: Device $device not found."
exit 1
fi
read -p "Warning: This will overwrite all data on $device. Are you sure you want to continue? [y/N]: " confirm
if [ "$confirm" != "y" ]; then
echo "Operation cancelled."
exit 1
fi
set -e
set -x
sfdisk "$device" <<EOF
label: dos
device: $device
unit: sectors
sector-size: 512
${device}1 : start= 2048, size= 131072, type=c
${device}2 : start= 133120, size= , type=83
EOF
mkfs -t fat ${device}*1
mkfs -t ext3 ${device}*2
e2label ${device}*2 rootfs
device_dir="/run/media/$(basename "$device")"
bootfs_dir="$device_dir/bootfs"
rootfs_dir="$device_dir/rootfs"
mkdir -p $bootfs_dir $rootfs_dir
mount ${device}*1 $bootfs_dir
mount ${device}*2 $rootfs_dir
# https://forum.doozan.com/read.php?2,134563,135415#msg-135415
tar -C $bootfs_dir -xf $kernel
tar -C $bootfs_dir -xf $bootfs_dir/linux-dtb-*
tar -C $rootfs_dir -xf $rootfs
cat $bootfs_dir/zImage-* $bootfs_dir/dts/mmp3-dell-ariel.dtb > $bootfs_dir/zImage.fdt
mkimage -A arm -O linux -T kernel -C none -a 0x8000 -e 0x8000 -d $bootfs_dir/zImage.fdt $bootfs_dir/uImage
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x3000000 -e 0x3000000 -d $rootfs_dir/boot/initrd.img-* $bootfs_dir/uInitrd
rm $rootfs_dir/root/set_persistent_mac_address
sed -i 's/ttyS0 115200/ttyS2 115200/' $rootfs_dir/etc/inittab
sed -i '2a rename \/enx*=eth0' $rootfs_dir/etc/network/interfaces
cat >$bootfs_dir/wloader.cfg <<EOF
<TX0D_START>
kernel=uImage
initrd=uInitrd
param="rootdelay=5 root=LABEL=rootfs raid=noautodetect console=ttyS2,115200 mtdparts=spi0.0:4m(boot)"
<TX0D_END>
EOF
# Copies files to /bootfs for kernel installation
cp -r $bootfs_dir $rootfs_dir/bootfs
cat >$rootfs_dir/root/kernel-install.sh <<EOF
#!/bin/bash
if [ \$# -eq 0 ]; then
echo "Usage: \$(basename "\$0") <boot partition>"
exit 1
fi
part=\$1
if [ ! -e "\$part" ]; then
echo "Error: Partition \$part not found."
exit 1
fi
set -e
set -x
cd /boot
contents=(*)
mkdir backup
mv \${contents[*]} backup/
mv /bootfs/* ./
rmdir /bootfs
apt remove flash-kernel -y
dpkg -i linux-image-*
cat zImage-* dts/mmp3-dell-ariel.dtb > zImage.fdt
mkimage -A arm -O linux -T kernel -C none -a 0x8000 -e 0x8000 -d zImage.fdt uImage
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x3000000 -e 0x3000000 -d initrd.img-* uInitrd
mount \$part /mnt
cp uImage /mnt
cp uInitrd /mnt
umount /mnt
EOF
chmod +x $rootfs_dir/root/kernel-install.sh
umount $bootfs_dir $rootfs_dir
rmdir $bootfs_dir $rootfs_dir
set +x
echo "Run "./kernel-install.sh" on the device after booting to install the kernel package."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment