|
#!/bin/bash |
|
|
|
# build and write u-boot to the CI20's SD card. |
|
# note: this script does not touch the ext4 rootfs partition. |
|
|
|
set -e -o pipefail |
|
set -x |
|
|
|
if test -z "$1" ; then |
|
echo "Error: no SD card device node specified." >&2 |
|
echo "Usage: $0 <SD card device, e.g. /dev/sdc>" >&2 |
|
exit 1 |
|
fi |
|
device="$1" |
|
|
|
which mipsel-linux-gnu-gcc >/dev/null 2>&1 || sudo apt-get install gcc-mipsel-linux-gnu |
|
|
|
# the official CI20 u-boot fork |
|
# UBOOT_REPO=${UBOOT_REPO:="https://github.com/MIPS/CI20_u-boot"} |
|
# UBOOT_BRANCH=${UBOOT_BRANCH:="ci20-v2013.10"} |
|
|
|
# Gabriele Svelto's u-boot fork with RAM timing fixes. |
|
UBOOT_REPO=${UBOOT_REPO:="https://github.com/gabrielesvelto/CI20_u-boot"} |
|
UBOOT_BRANCH=${UBOOT_BRANCH:="fixed-timings"} |
|
|
|
# clone u-boot |
|
cd /tmp |
|
if ! test -e CI20_u-boot/Makefile ; then |
|
git clone "$UBOOT_REPO" -b "$UBOOT_BRANCH" --depth 1 |
|
fi |
|
|
|
# reset u-boot from any previous build |
|
cd /tmp/CI20_u-boot |
|
make distclean |
|
git reset --hard HEAD |
|
git checkout "$UBOOT_BRANCH" |
|
|
|
# change the cserial console baud rate to 9600 |
|
sed -i'' -e 's|console=ttyS4,115200 console=tty0 |console=ttyS4,9600 console=tty0,9600 |' /tmp/CI20_u-boot/include/configs/ci20.h |
|
|
|
# disable the second CPU core for stability |
|
# see https://groups.google.com/g/mips-creator-ci20/c/VXr7feU5XWA/m/rZjFYhjrAwAJ |
|
sed -i'' -e 's|rootwait quiet rw|rootwait quiet maxcpus=1 rw|' /tmp/CI20_u-boot/include/configs/ci20.h |
|
|
|
# build u-boot |
|
CROSS_COMPILE=mipsel-linux-gnu- make -j4 ARCH=mips ci20_mmc |
|
maxsize=14336 |
|
cursize=$(cat spl/u-boot-spl.bin | wc -c) |
|
# JZ4780 internal boot ROM reads 14KB (14336 bytes) of data from the boot device |
|
if test $cursize -ge $maxsize ; then |
|
echo "Error: spl/u-boot-spl.bin exceeds '$maxsize' bytes" >&2 |
|
exit 1 |
|
fi |
|
|
|
# note: the dd offsets below appear to come from the following buildroot config: |
|
# https://github.com/buildroot/buildroot/blob/master/board/ci20/genimage.cfg |
|
# image sdcard.img { |
|
# hdimage { |
|
# } |
|
# partition uboot-spl { |
|
# in-partition-table = "no" |
|
# image = "u-boot-spl.bin" |
|
# offset = 512 |
|
# } |
|
# partition uboot { |
|
# in-partition-table = "no" |
|
# image = "u-boot.img" |
|
# offset = 14K |
|
# } |
|
# partition uboot-env { |
|
# in-partition-table = "no" |
|
# image = "uboot-env.bin" |
|
# offset = 526K |
|
# } |
|
# partition rootfs { |
|
# partition-type = 0x83 |
|
# image = "rootfs.ext4" |
|
# offset = 2M |
|
# } |
|
# } |
|
# See also https://github.com/gabrielesvelto/CI20_u-boot/blob/ci20-v2013.10/include/configs/ci20.h |
|
|
|
# wipe any saved u-boot environment |
|
sudo dd if=/dev/zero of="$device" bs=1K seek=526 count=32 ; sync |
|
|
|
# write the new u-boot |
|
sudo dd if=spl/u-boot-spl.bin of="$device" obs=512 seek=1 ; sync |
|
sudo dd if=u-boot.img of="$device" obs=1K seek=14 ; sync |