Code dump

Support for Banana Pi M1 only for now.
This commit is contained in:
Johan Gunnarsson 2019-03-16 21:33:09 +01:00
parent 04ae0e02a7
commit 82c90dad16
13 changed files with 253 additions and 0 deletions

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM debian:latest
RUN apt-get update
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y install debootstrap \
debian-archive-keyring \
git \
crossbuild-essential-arm64 \
crossbuild-essential-armhf \
qemu-user-static \
device-tree-compiler \
bison \
flex \
python-dev \
swig \
parted \
e2fsprogs \
pwgen
ENV PATH="/debimg:${PATH}"
COPY . /debimg
WORKDIR /debimg

22
build-boot-allwinner Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
# Build SD card image
IMAGE="${1}" # For example "boot-bananapi.bin"
DEFCONFIG="${2}" # For example "Bananapi_defconfig"
TUPLE="${3}" # For example "arm-linux-gnueabihf"
set -e
# Create fresh empty directory
TMP=$(mktemp -d tmp.XXXXXX)
cd "${TMP}"
build-image tmp.img
build-u_boot u-boot "${DEFCONFIG}" "${TUPLE}"
# Copy U-Boot to 8192 bytes from start
dd if=u-boot/u-boot-sunxi-with-spl.bin of=tmp.img bs=1K seek=8
truncate -s 32M tmp.img
gzip tmp.img
cp tmp.img.gz "${IMAGE}.bin.gz"

83
build-debian Executable file
View File

@ -0,0 +1,83 @@
#!/bin/sh
# Build Debian root filesystem
IMAGE2="$1"
ARCH="$2"
DIST="$3"
set -e
case "${ARCH}" in
armhf)
KERNEL=linux-image-armmp
;;
arm64)
KERNEL=linux-image-arm64
;;
*)
echo "Can't decide kernel package for \"${ARCH}\""
exit 1
;;
esac
# Create fresh empty directory
TMP=$(mktemp -d tmp.XXXXXX)
cd "${TMP}"
# Build a Debian root filesystem (first stage)
debootstrap \
--arch="${ARCH}" \
--verbose \
--variant=minbase \
--foreign \
--include=\
netbase,\
ifupdown,\
net-tools,\
isc-dhcp-client,\
${KERNEL},\
systemd-sysv,\
u-boot-tools,\
openssh-server \
"${DIST}" \
debian \
"http://ftp.se.debian.org/debian/"
# Randomly generated root password
PASSWORD=$(pwgen -B -A 8 1)
cp -rv --preserve=mode ../pre-2nd-stage-files/* debian
# Copy ARM emulation stuff
cp /usr/bin/qemu-*-static debian/usr/bin
# Build a Debian root filesystem (second stage)
chroot debian sh -e <<- EOF
/debootstrap/debootstrap --second-stage
/usr/bin/apt-get clean
/bin/rm -rf /var/lib/apt/lists/*
/bin/rm -f /var/log/*.log
/bin/echo root:${PASSWORD} | /usr/sbin/chpasswd
/bin/sed -i "s/#*\s*PermitRootLogin .*/PermitRootLogin yes/" /etc/ssh/sshd_config
EOF
# Remove ARM emulation stuff again
rm debian/usr/bin/qemu-*-static
cp -rv --preserve=mode ../post-2nd-stage-files/* debian
# Write apt sources config
cat <<- EOF > debian/etc/apt/sources.list
deb http://deb.debian.org/debian ${DIST} main
deb-src http://deb.debian.org/debian ${DIST} main
deb http://security.debian.org/debian-security ${DIST}/updates main
deb-src http://security.debian.org/debian-security ${DIST}/updates main
EOF
# Make a ext4 filesystem of this and put it into the image
rm -f ext4.img
fallocate -l 900MiB ext4.img
mkfs.ext4 -d debian ext4.img
gzip ext4.img
cp ext4.img.gz "${IMAGE2}-${PASSWORD}.bin.gz"

14
build-image Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
# Build empty image
IMAGE="${1}"
set -e
rm -f "${IMAGE}"
fallocate -l 1GB "${IMAGE}" # 1,000,000,000 bytes
parted -s "${IMAGE}" mklabel msdos
parted -s "${IMAGE}" mkpart primary fat32 -- 1MiB 32MiB # 31 MiB (32,505,856 bytes)
parted -s "${IMAGE}" mkpart primary ext2 -- 32MiB -1
parted -s "${IMAGE}" set 2 boot on

40
build-u_boot Executable file
View File

@ -0,0 +1,40 @@
#!/bin/sh
# Download and build latest version of U-Boot
UBOOTDIR="${1}"
DEFCONFIG="${2}"
TUPLE="${3}"
set -e
# U-Boot version to build
VERSION=$(git ls-remote --tags --refs "git://git.denx.de/u-boot.git" "v????.??" | \
cut -f 2 | \
grep -o "v....\..." | \
tail -n 1)
# Download U-Boot
git clone -b "$VERSION" --depth 1 "git://git.denx.de/u-boot.git" "${UBOOTDIR}"
# Step into U-Boot directory
cd "${UBOOTDIR}"
# Setup ARCH
case "${TUPLE}" in
arm-*)
export ARCH="arm"
;;
aarch64-*)
export ARCH="aarch64"
;;
*)
echo "Can't decide \$ARCH for tuple \"${TUPLE}\""
exit 1
;;
esac
# CROSS_COMPILE must point to a valid compiler path prefix
export CROSS_COMPILE=$(dirname $(which "${TUPLE}-gcc"))/"${TUPLE}-"
# Build U-Boot
make "${DEFCONFIG}" && make

3
post-2nd-stage-files/etc/fstab Executable file
View File

@ -0,0 +1,3 @@
# <file system> <mount point> <type> <options> <dump> <pass>
tmpfs /tmp tmpfs nodev,nosuid 0 0
tmpfs /var/tmp tmpfs nodev,nosuid 0 0

View File

@ -0,0 +1 @@
debian

View File

@ -0,0 +1,2 @@
auto eth0
iface eth0 inet dhcp

View File

@ -0,0 +1,2 @@
auto lo
iface lo inet loopback

View File

@ -0,0 +1,21 @@
HOW TO CHANGE ROOT PASSWORD
---------------------------
1. It is strongly recommended that you change the root password:
# passwd root
HOW TO RESIZE ROOT FILESYSTEM PARTITION
---------------------------------------
1. Maximize size of rootfs partition in:
# parted -s /dev/mmcblk0 resizepart -- 2 -1
2. Reload partition table:
# partprobe
3. Expand ext4 filesystem:
# resize2fs /dev/mmcblk0p2

View File

@ -0,0 +1,21 @@
#!/bin/sh
# Generate initrd.uimg and update U-Boot boot.scr
# Kernel ABI string
ABI="${1}"
# Create U-Boot ramdisk image
mkimage -A arm -T ramdisk -C none -d "/boot/initrd.img-${ABI}" "/boot/initrd.uimg-${ABI}"
# Create U-Boot boot script
cat << EOF > /boot/boot.cmd
mmc dev 0
ext4load mmc 0:2 \${kernel_addr_r} /boot/vmlinuz-${ABI}
ext4load mmc 0:2 \${ramdisk_addr_r} /boot/initrd.uimg-${ABI}
ext4load mmc 0:2 \${fdt_addr_r} /usr/lib/linux-image-${ABI}/\${fdtfile}
setenv bootargs "root=/dev/mmcblk0p2 rw rootwait earlyprintk"
bootz \${kernel_addr_r} \${ramdisk_addr_r} \${fdt_addr_r}
EOF
# Create U-Boot boot script
mkimage -A arm -T script -C none -d /boot/boot.cmd /boot/boot.scr

View File

@ -0,0 +1,8 @@
#!/bin/sh
# Generate initrd.uimg and update U-Boot boot.scr
# Kernel ABI string
ABI="${1}"
# Delete U-Boot ramdisk image
rm -f "/boot/initrd.uimg-${ABI}"

16
rebuild Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
# Rebuild everything
DOCKEROPTS1="--rm -v /tmp/artifacts:/artifacts"
DOCKEROPTS2="--privileged $DOCKEROPTS1"
mkdir -p /tmp/artifacts || exit
# Build Docker image
docker build -t debimg .
# Build bootloaders
docker run $DOCKEROPTS1 debimg build-boot-allwinner "/artifacts/boot-bananapi" "Bananapi_defconfig" "arm-linux-gnueabihf"
# Build root filesystems
docker run $DOCKEROPTS2 debimg build-debian "/artifacts/debian-buster-armhf" "armhf" "buster"