How to build Trisquel 11 "from scratch" for the TPE-R1500 mail server

# Directions on how to build Trisquel 11 "from scratch" for the TPE-R1500 mail server
#
# This is NOT how to build Trisquel 11 from sources, but how to build an ARM64 image from official packages in the Trisquel repositories
# and the only part that is built from sources is the ARM trusted firmware and uboot
#
# Vetted on a Trisquel 11 tp edition live image/USB, the instructions below use docker, and will include how to create the Trisquel 11 docker image
# such that no proprietary software need to be utilized during the Trisquel 11 SD card image build process

# Create Trisquel 11 base docker container image

sudo su
mkdir -p /opt/docker_base_images
cd /opt/docker_base_images
apt update
apt install debootstrap docker-compose qemu-user-static
debootstrap aramo aramo > /dev/null

# Verify

cat aramo/etc/lsb-release

# Start docker

systemctl start docker

# Import docker image

tar -C aramo -c . | docker import - aramo

# Show docker images

docker images

# Example output

root@trisquel:/opt/docker_base_images# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
aramo latest 1b413da044a5 5 seconds ago 440MB

# Verify new docker image release version

docker run aramo cat /etc/lsb-release

exit

# Install and start docker if you haven't done so

sudo apt update
sudo apt install docker-compose
sudo systemctl start docker

# Make sure the user is part of the docker group

sudo usermod -a -G docker trisquel

# Download the source code for the scripts/docker needed to build the Trisquel 11 image for the TPE-R1500 mail server

git clone https://github.com/johang/sd-card-images.git

# We're adding support to a quality set of scripts that were written by another party originally intended to build pure images of Debian

# For RYF compliance replace the Debian example with Trisquel, arm64, and aramo

nano sd-card-images/scripts/build-debian

OS="$1" # For example "trisquel"
ARCH="$2" # For example "arm64"
DIST="$3" # For example "aramo"

# In the sd-card-images/scripts directory add the following under the "case '${OS}-${ARCH}' in" section:

trisquel-arm64)
KERNEL=linux-image-generic
URL=http://ports.trisquel.info/trisquel
KERNEL_URL=http://packages.trisquel.info/"${DIST}"/"${KERNEL}"
SCRIPT=/usr/share/debootstrap/scripts/aramo
;;

# Note: For RYF compliance in the case "${OS}-${ARCH}-${DIST}" in debian-*-rc-buggy|debian-*-experimental) section everything but what comes after the *) and before the ;; leaving ONLY the following two lines like so (even the esac goes since there is no case statement any more):

TARGET="${DIST}"
KERNELSUITE=""

# For RYF compliance delete the whole section for:

case "${OS}-${ARCH}-${DIST}" in
debian-*-rc-buggy|debian-*-experimental)

# Note: For RYF compliance remove non-free distributions from script within the "case "${OS}-${ARCH}" in" section

# Note: For RYF compliance remove non-free distributions from the "# Write apt sources config" section

# In the "# Write apt sources config" section add:

trisquel-*)
tee debian/tmp/sources.list <<- EOF
deb http://ports.trisquel.info/trisquel ${DIST} main
deb-src http://ports.trisquel.info/trisquel ${DIST} main
deb http://ports.trisquel.info/trisquel ${DIST}-updates main
deb-src http://ports.trisquel.info/trisquel ${DIST}-updates main
deb http://ports.trisquel.info/trisquel ${DIST}-security main
deb-src http://ports.trisquel.info/trisquel ${DIST}-security main
EOF
;;

# Modify the Dockerfile to use our Trisquel 11 base docker image instead of Ubuntu 24.04

nano sd-card-images/Dockerfile

# Change the first line "FROM public.ecr.aws/ubuntu/ubuntu:24.04" to "FROM aramo" like so:

FROM aramo

# Also remove the following from the bottom of the Dockerfile

RUN wget -q "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -O "awscliv2.zip" && \
unzip -q awscliv2.zip && \
./aws/install && \
rm -rf aws

# Replace the uboot official source with a copy that we're using for the TPE-R1500

nano sd-card-images/scripts/build-u_boot

U_BOOT_GIT_URL_DEFAULT="https://github.com/chris00001/u-boot-for-r1500.git/"

# Replace the official arm-trusted-firmware with the deblobbed arm-trusted-firmware on the ATF_GIT_URL_DEFAULT= line like so:

nano sd-card-images/scripts/build-atf

ATF_GIT_URL_DEFAULT="https://github.com/chris00001/no-blobs-arm-trusted-firmware.git"

# For RYF compliance you should change the top of build-boot-rk to:

nano sd-card-images/scripts/build-boot-rk

BOARD_ID="${1}" # For example "r1500"
CHIP_ID="${2}" # For example "rk3399"
DEFCONFIG="${3}" # For example "nanopi-r4s-rk3399_defconfig"
TUPLE="${4}" # For example "arm-linux-gnueabihf"

# Replace the RKBIN_GIT_URL_DEFAULT line with:

RKBIN_GIT_URL_DEFAULT="https://github.com/chris00001/rockchip-linux-tpe-r1500.git"

# Also under case "{$CHIP_ID}" in delete everything that isn't for the 3399 TPE-R1500 board

# Remove the scripts we're not using:

mv sd-card-images/scripts/build-boot-meson /tmp
mv sd-card-images/scripts/build-boot-qemu /tmp
mv sd-card-images/scripts/build-boot-qemu-x86 /tmp
mv sd-card-images/scripts/build-boot-rpi /tmp
mv sd-card-images/scripts/build-boot-sunxi /tmp
mv sd-card-images/scripts/build-boot-with-aws-batch /tmp
mv sd-card-images/scripts/build-debian-with-aws-batch /tmp

# Build the docker image

sudo docker build -t sd-images sd-card-images

# Build the boot image for the TPE-R1500

mkdir -p /tmp/sd-images
sudo docker run --rm -v /tmp/sd-images:/artifacts sd-images build-boot r1500 rk3399 nanopi-r4s-rk3399_defconfig aarch64-linux-gnu

# Check the boot image was built

ls /tmp/sd-images

# Example output:

boot-r1500.bin.gz boot-r1500.bin.gz.versions.csv

# Build the Trisquel root image

sudo docker run --rm -v /tmp/sd-images:/artifacts sd-images build-debian trisquel arm64 aramo

# Combine the boot image with the Trisquel root image to create an SD card image

zcat /tmp/sd-images/boot-r1500.bin.gz /tmp/sd-images/trisquel-aramo-arm64-yeish3.bin.gz > /tmp/sd-images/r1500-trisquel-11-sd-card.img

# Lastly run gnome-disks and write the r1500-trisquel-11-sd-card.img file to a SD card

gnome-disks

# You may need to look at your router's DHCP list to figure out the IP to ssh into as the live media will name the system trisquel as is the sd card image
# The password is in the name of the Trisquel image, ie trisquel-aramo-arm64-yeish3.bin.gz, so in this example the password is yeish3
# Replace the word trisquel below with the IP of the booted TPE-R1500 mail server (make sure to insert the SD card and power it on)

ssh root@trisquel