Hi guys,
I have a BPI-M3, and wanted to roll my own build, given the current dissatisfaction with the builds provided by Sinovoip themselves.
In any case, I have tested this locally, and it builds a bootable sd card, which works on UART only.
It doesn't have working ethernet or WiFi, but at least you can interact with it over UART.
Please feel free to review and comment on the script, and let me know if there are any issues running in your environment (ie, prerequisites that I have already, and make an invalid assumption that it is present).
As per the comment inside the script, it will wipe the sdcard specified, and repartition with one partition which takes all but the first 2Mb (reserved for u-boot).
Cheers,
Damien
#!/bin/bash
# buildBananaPiM3OnSdCard.sh <sdcard> <mount directory>
# This will attempt to build a jessie chroot
# WARNING, this will wipe your SD Card
# Damien Mascord <tusker@tusker.org>
# LINUX_SRC_DIR is a git clone https://github.com/wens/linux.git
LINUX_SRC_DIR=./linux
#UBOOT_SRC_DIR is a git clone https://github.com/wens/u-boot-sunxi.git
UBOOT_SRC_DIR=./u-boot-sunxi
HOSTNAME=BPiM3
ROOTPASS=`date | md5sum | cut -c1-16`
if [ $# -lt 2 ]; then
echo "Usage: $0 <sdcard (ie /dev/sdc)> <mount directory (ie /mnt)>"
echo " *** WARNING - this will repartition and wipe your sd card ***"
exit 1
fi
SDCARD=$1
MNT_DIR=$2
# Ask for sudo permissions up front
sudo -v
if [ $? != 0 ]; then
echo "Unable to sudo, please ensure that global sudo is setup correctly for this user"
fi
# Keep-alive: update existing sudo time stamp if set, otherwise do nothing.
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# make sure the sd card is unmounted
sudo umount -f ${SDCARD}1
sudo umount -f ${SDCARD}
sudo umount -f $MNT_DIR/dev/pts
sudo umount -f $MNT_DIR/dev
sudo umount -f $MNT_DIR/proc
sudo umount -f $MNT_DIR/sys
sudo umount -f $MNT_DIR
# partition the SD Card, leaving 2M at the beginning of the card for u-boot
sudo sfdisk $SDCARD << EOF
2048,
EOF
# run partprobe to make sure the kernel is using the latest partition table
sudo partprobe
# make the ext4 filesystem
sudo mkfs.ext4 ${SDCARD}1
# mount the first partition of the SD Card
sudo mount ${SDCARD}1 $MNT_DIR
# build the jessie chroot
sudo qemu-debootstrap --verbose --include=linux-image-armmp-lpae,locales,sunxi-tools,firmware-linux,ssh,debconf --arch=armhf --components=main,non-free jessie $MNT_DIR http://ftp.au.debian.org/debian/
cat <<EOF > /tmp/boot.cmd
setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rootwait panic=10
load mmc 0:1 0x43000000 sun8i-a83t-sinovoip-bpi-m3.dtb || load mmc 0:1 0x43000000 boot/sun8i-a83t-sinovoip-bpi-m3.dtb
load mmc 0:1 0x42000000 zImage || load mmc 0:1 0x42000000 boot/zImage
bootz 0x42000000 - 0x43000000
EOF
sudo mv /tmp/boot.cmd $MNT_DIR/boot.cmd
sudo mkimage -C none -A arm -T script -d $MNT_DIR/boot.cmd $MNT_DIR/boot.scr
if [ ! -e $LINUX_SRC_DIR ]; then
git clone https://github.com/wens/linux.git
fi
# build the debian kernel package
pushd $LINUX_SRC_DIR
git fetch
git checkout -b a83-emac remotes/origin/a83-emac
# add the extra kernel compile options into the defconfig
cp -rp arch/arm/configs/sunxi_defconfig arch/arm/configs/sinovoip_bpi_m3_defconfig
cat <<EOF >> arch/arm/configs/sinovoip_bpi_m3_defconfig
CONFIG_WLAN=y
# CONFIG_WLAN_VENDOR_ADMTEK is not set
# CONFIG_WLAN_VENDOR_ATH is not set
# CONFIG_WLAN_VENDOR_ATMEL is not set
CONFIG_WLAN_VENDOR_BROADCOM=y
# CONFIG_B43 is not set
# CONFIG_B43LEGACY is not set
CONFIG_BRCMUTIL=y
# CONFIG_BRCMSMAC is not set
CONFIG_BRCMFMAC=y
CONFIG_BRCMFMAC_PROTO_BCDC=y
CONFIG_BRCMFMAC_SDIO=y
CONFIG_ETHERNET=y
CONFIG_NET_VENDOR_ALLWINNER=y
CONFIG_SUN4I_EMAC=y
CONFIG_SUN8I_EMAC=y
CONFIG_REALTEK_PHY=y
EOF
ARCH=arm make sinovoip_bpi_m3_defconfig
# grab the latest from the repo
git pull
export ARCH=arm
export DEB_HOST_ARCH=armhf
export CROSS_COMPILE=arm-linux-gnueabihf-
export CONCURRENCY_LEVEL=`grep -m1 cpu\ cores /proc/cpuinfo | cut -d : -f 2`
fakeroot make-kpkg --arch arm --cross-compile arm-linux-gnueabihf- --initrd --append-to-version=-custom1 kernel_image kernel_headers
popd
# copy the latest linux-headers and linux-image in the current directory to $MNT_DIR/tmp
LATEST_LINUX_IMAGE=`ls -rt | grep linux-image | tail -1`
LATEST_LINUX_HEADERS=`ls -rt | grep linux-headers | tail -1`
sudo cp -rp $LATEST_LINUX_IMAGE $MNT_DIR/tmp
sudo cp -rp $LATEST_LINUX_HEADERS $MNT_DIR/tmp
# install the linux-headers and linux-image into the mounted chroot
sudo chroot $MNT_DIR dpkg -i /tmp/$LATEST_LINUX_IMAGE
sudo chroot $MNT_DIR dpkg -i /tmp/$LATEST_LINUX_HEADERS
# find out the latest vmlinuz (just installed)
LATEST_IN_CHROOT_VMLINUZ=`sudo ls -rt $MNT_DIR/boot/vmlinuz-* | tail -n1`
LATEST_IN_CHROOT_VMLINUZ=`basename $LATEST_IN_CHROOT_VMLINUZ`
sudo chroot $MNT_DIR ln -s /boot/$LATEST_IN_CHROOT_VMLINUZ /boot/zImage
sudo chroot $MNT_DIR ln -s /boot/zImage /zImage
# copy in the dtb file into the chroot
sudo cp -rp $LINUX_SRC_DIR/arch/arm/boot/dts/sun8i-a83t-sinovoip-bpi-m3.dtb $MNT_DIR/boot
sudo chroot $MNT_DIR ln -s /boot/sun8i-a83t-sinovoip-bpi-m3.dtb .
if [ ! -e $UBOOT_SRC_DIR ]; then
git clone https://github.com/wens/u-boot-sunxi.git
fi
pushd $UBOOT_SRC_DIR
git fetch
git checkout -b a80-pmic remotes/origin/a80-pmic
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
make Sinovoip_BPI_M3_defconfig
make
sudo dd if=u-boot-sunxi-with-spl.bin of=$SDCARD bs=1024 seek=8
popd
# once we have our jessie base system, latest built kernel, and u-boot installed, modify our root filesystem to be bootable
echo "/dev/mmcblk0p1 / ext4 relatime,errors=remount-ro 0 1" > /tmp/fstab
sudo mv /tmp/fstab $MNT_DIR/etc/
echo $HOSTNAME > /tmp/hostname
sudo mv /tmp/hostname $MNT_DIR/etc/
# make sure our hosts resolve our local domain
sudo chroot $MNT_DIR perl -i -p -e "s/localhost/localhost $HOSTNAME/g" /etc/hosts
# setup debian apt repos
cat <<EOF > /tmp/sources.list
#
deb http://ftp.au.debian.org/debian/ jessie main non-free contrib
deb-src http://ftp.au.debian.org/debian/ jessie main non-free contrib
deb http://security.debian.org/ jessie/updates main contrib non-free
deb-src http://security.debian.org/ jessie/updates main contrib non-free
# jessie-updates, previously known as 'volatile'
deb http://ftp.au.debian.org/debian/ jessie-updates main contrib non-free
deb-src http://ftp.au.debian.org/debian/ jessie-updates main contrib non-free
EOF
sudo mv /tmp/sources.list $MNT_DIR/etc/apt/
# setup network interfaces
cat <<EOF > /tmp/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
EOF
sudo mv /tmp/interfaces $MNT_DIR/etc/network/
# setup getty
echo "T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100" >> /tmp/inittab
sudo mv /tmp/inittab $MNT_DIR/etc/
# allow root login via SSH
sudo sed -i "s/^PermitRootLogin without-password/PermitRootLogin yes/" $MNT_DIR/etc/ssh/sshd_config
sudo mount -t proc chproc $MNT_DIR/proc
sudo mount chsys $MNT_DIR/sys -t sysfs
sudo mount -t devtmpfs chdev $MNT_DIR/dev || mount --bind /dev $MNT_DIR/dev
sudo mount -t devpts chpts $MNT_DIR/dev/pts
echo -e '#!/bin/sh\nexit 101' > /tmp/policy-rc.d
sudo mv /tmp/policy-rc.d $MNT_DIR/usr/sbin/
sudo chmod 755 $MNT_DIR/usr/sbin/policy-rc.d
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C sudo -E chroot $MNT_DIR dpkg --configure -a
LC_ALL=C LANGUAGE=C LANG=C sudo -E chroot $MNT_DIR dpkg-reconfigure locales
LC_ALL=C LANGUAGE=C LANG=C sudo -E chroot $MNT_DIR dpkg-reconfigure tzdata
LC_ALL=C LANGUAGE=C LANG=C sudo -E chroot $MNT_DIR apt-get update
LC_ALL=C LANGUAGE=C LANG=C sudo -E chroot $MNT_DIR apt-get -q -y install u-boot u-boot-tools
# get the wifi sdio
LC_ALL=C LANGUAGE=C LANG=C sudo -E chroot $MNT_DIR apt-get -q -y install firmware-brcm80211
sudo wget -O $MNT_DIR/lib/firmware/brcm/brcmfmac43430-sdio.bin https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.bin
sudo wget -O $MNT_DIR/lib/firmware/brcm/brcmfmac43430-sdio.txt https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm/brcmfmac43430-sdio.txt
# install some other things
LC_ALL=C LANGUAGE=C LANG=C sudo -E chroot $MNT_DIR apt-get -q -y install console-setup keyboard-configuration openssh-server ntp
# set the root password
echo "root:$ROOTPASS"| LC_ALL=C LANGUAGE=C LANG=C sudo -E chroot $MNT_DIR chpasswd
echo "Setting your root password to be $ROOTPASS"
# setup tx delay for EMAC ethernet, as per http://linux-sunxi.org/Sun8i_emac
wget -O /tmp/devmem2.c http://www.lartmaker.nl/lartware/port/devmem2.c
arm-linux-gnueabihf-gcc /tmp/devmem2.c -o devmem2
sudo mkdir -p $MNT_DIR/usr/local/bin
sudo cp -rp devmem2 $MNT_DIR/usr/local/bin
sudo sed -i 's/exit 0/#exit 0/' $MNT_DIR/etc/rc.local
echo "/usr/local/bin/devmem2 0x1c00030 w 0x1806" | sudo tee -a $MNT_DIR/etc/rc.local
echo "exit 0" | sudo tee -a $MNT_DIR/etc/rc.local
sudo rm $MNT_DIR/usr/sbin/policy-rc.d
sudo rm $MNT_DIR/usr/bin/qemu-arm-static
sudo umount $MNT_DIR/dev/pts
sudo umount $MNT_DIR/dev
sudo umount $MNT_DIR/sys
sudo umount $MNT_DIR/proc
sudo umount $MNT_DIR
sudo sync
# kill the sudo session
sudo -K