Skip to content

Instantly share code, notes, and snippets.

@user890104
Created January 25, 2026 22:35
Show Gist options
  • Select an option

  • Save user890104/930fa5f6c009997dc88b5304f3e4c437 to your computer and use it in GitHub Desktop.

Select an option

Save user890104/930fa5f6c009997dc88b5304f3e4c437 to your computer and use it in GitHub Desktop.
Linux on iPod nano (7th generation)
#!/bin/bash
set -eEx
ARCH=armv7
VER=3.23.2
MAJOR=v${VER%.*}
TAR=alpine-minirootfs-${VER}-${ARCH}.tar.gz
URL=https://dl-cdn.alpinelinux.org/alpine/${MAJOR}/releases/${ARCH}/${TAR}
wget -c $URL
WORK_DIR=$(mktemp -d)
tar xf ${TAR} -C $WORK_DIR
# create minimal /init for initramfs
cat >"$WORK_DIR/init" <<'EOF'
#!/bin/sh
echo "initramfs: starting init"
exec /sbin/init
EOF
chmod +x "$WORK_DIR/init"
# add ssh keys
mkdir "$WORK_DIR/root/.ssh"
chmod 700 "$WORK_DIR/root/.ssh"
echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAlSmJO7UgzjbBTTOvh1re3uFOwwQmkofNH7/d/kD0Qz [email protected]' > "$WORK_DIR/root/.ssh/authorized_keys"
echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMnegmtmFuchzqYvECz3HMfyjz/UQvA7LOqA+tm8UiNp venci@Venci-X270' >> "$WORK_DIR/root/.ssh/authorized_keys"
chmod 600 "$WORK_DIR/root/.ssh/authorized_keys"
# add devmem
cp ~/Git/devmem/devmem "$WORK_DIR/sbin/"
chmod +x "$WORK_DIR/sbin/devmem"
# add physmem
cp physmem "$WORK_DIR/sbin/"
chmod +x "$WORK_DIR/sbin/physmem"
# setup networking
echo 'nameserver 8.8.8.8' > "$WORK_DIR/etc/resolv.conf"
echo nano7g > "$WORK_DIR/etc/hostname"
cat >"$WORK_DIR/etc/network/interfaces" <<'EOF'
auto lo
iface lo inet
auto usb0
iface usb0 inet static
address 10.0.0.2
netmask 255.255.255.0
gateway 10.0.0.1
EOF
# setup the rootfs
cp $(which qemu-arm-static) $WORK_DIR
# install packages
sudo systemd-nspawn -D $WORK_DIR /qemu-arm-static /sbin/apk add dropbear openrc haveged chrony zlib fbvnc evtest i2c-tools
# setup services
sudo systemd-nspawn -D $WORK_DIR /qemu-arm-static /bin/sh -c "export PATH=; source /etc/profile; for s in devfs dmesg root; do rc-update add \$s sysinit; done; for s in chronyd bootmisc hostname sysctl haveged; do rc-update add \$s boot; done; rc-update add networking; rc-update add dropbear"
# pre-generate dropbear host keys
sudo systemd-nspawn -D $WORK_DIR /qemu-arm-static /bin/sh -c "export PATH=; source /etc/profile; for algo in rsa ecdsa ed25519; do dropbearkey -t \$algo -f /etc/dropbear/dropbear_\${algo}_host_key; done"
# set root password
sudo systemd-nspawn -D $WORK_DIR /qemu-arm-static /bin/sh -c "export PATH=; source /etc/profile; echo -ne 'alpine\nalpine\n' | passwd root"
#sudo systemd-nspawn -D $WORK_DIR /qemu-arm-static /sbin/apk add weston --update-cache
rm -rf "$WORK_DIR/qemu-arm-static"
# make the initramfs
(
find $WORK_DIR -printf "%P\0" |
sudo cpio --directory=$WORK_DIR --null --create --verbose --owner root:root --format=newc |
gzip -9
) >initramfs.cpio.gz
sudo rm -rf "$WORK_DIR"
/dts-v1/;
/ {
description = "Simple image with single Linux kernel and FDT blob";
#address-cells = <1>;
images {
kernel {
description = "Linux kernel";
data = /incbin/("../../../Git/linux/arch/arm/boot/zImage");
type = "kernel";
arch = "arm";
os = "linux";
compression = "none";
load = <0x08000000>;
entry = <0x08000000>;
hash-1 {
algo = "crc32";
};
};
fdt {
description = "Flattened Device Tree blob";
data = /incbin/("../../../Git/u-boot/arch/arm/dts/s5l8740.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash-1 {
algo = "crc32";
};
};
ramdisk {
description = "Gzipped Initramfs";
data = /incbin/("initramfs.cpio.gz");
type = "ramdisk";
arch = "arm";
os = "linux";
hash {
algo = "crc32";
};
};
};
configurations {
default = "conf-1";
conf-1 {
description = "Boot Linux kernel with FDT blob";
kernel = "kernel";
fdt = "fdt";
ramdisk = "ramdisk";
};
};
};
#!/bin/bash
set -e
set -x
echo 'This is not a copy/paste script! You need to adjust it to your system/paths!'
exit 1
# u-boot
cd ~/Git/u-boot
git clean -x -d -f
git checkout s5l87xx
make apple_n31_defconfig
make CROSS_COMPILE=arm-none-eabi- -j $(nproc) u-boot.bin
# Linux
cd ~/Git/linux
git clean -x -d -f
git checkout s5l87xx
make ARCH=arm apple_n31_defconfig
make ARCH=arm CROSS_COMPILE=arm-elf-eabi- -j $(nproc) zImage
# Combine them
cd ~/Development/freemyipod/linux
ls -lha ../../../Git/linux/arch/arm/boot/zImage ../../../Git/u-boot/arch/arm/dts/s5l8740.dtb initramfs.cpio.gz
PATH=../../../Git/u-boot/tools:../../../Git/u-boot/scripts/dtc:$PATH mkimage -f kernel_fdt.its kernel_fdt.itb
ls -lha kernel_fdt.itb
# Run it
~/Git/wInd3x/wInd3x cfw run ~/Git/u-boot/u-boot.bin
sleep 10
dfu-util -d 05ac:8007 -D kernel_fdt.itb
dfu-util -d 05ac:8007 -e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment