Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active April 10, 2025 00:49
Show Gist options
  • Save cellularmitosis/d41c2805a0cae004000067c587d93826 to your computer and use it in GitHub Desktop.
Save cellularmitosis/d41c2805a0cae004000067c587d93826 to your computer and use it in GitHub Desktop.
Modifying the MIPS Creator CI20 default u-boot environment

Blog 2025/4/9

<- previous | index | next ->

Modifying the MIPS Creator CI20 default u-boot environment

Follow-up to https://gist.github.com/cellularmitosis/a79c663f2e8430bc58bab61d459c9c1b

This script is an example of building u-boot while modifying its default environment and flashing u-boot to an SD card.

In particular:

  • the serial console baud rate is reduced to 9600 (to allow for flaky cabling)
  • a maxcpus=1 kernel parameter is added (for stability)

Note: this script does not modify the ext4 rootfs partition created by the script in my previous post.

#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment