Skip to content

Instantly share code, notes, and snippets.

@cdave1
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdave1/eb7f50b768ed336c7251 to your computer and use it in GitHub Desktop.
Save cdave1/eb7f50b768ed336c7251 to your computer and use it in GitHub Desktop.
Experimental shell for creating an image with 3.12.28 of the kernel (image did not boot for me). REQUIRES kernel 3.12.28 from kernel.org
#!/bin/bash
rm -rf build
mkdir -p build/boot
echo "[INFO] Creating u-boot-bananapi"
if [ ! -d u-boot-bananapi ]; then
git clone https://github.com/LeMaker/u-boot-bananapi.git
elif [ -d u-boot-bananapi ]; then
( cd u-boot-bananapi && git pull )
fi
(cd u-boot-bananapi &&
make CROSS_COMPILE=arm-linux-gnueabihf- Bananapi_config &&
make CROSS_COMPILE=arm-linux-gnueabihf-
cp u-boot-sunxi-with-spl.bin ../build/boot/u-boot-sunxi-with-spl.bin)
echo "[INFO] Creating sunxi-tools"
if [ ! -d sunxi-tools ]; then
git clone https://github.com/LeMaker/sunxi-tools.git
elif [ -d sunxi-tools ]; then
( cd sunxi-tools && git pull )
fi
(cd sunxi-tools &&
make clean &&
make)
echo "[INFO] Creating script.bin"
if [ ! -d sunxi-boards ]; then
git clone https://github.com/LeMaker/sunxi-boards.git
elif [ -d sunxi-boards ]; then
( cd sunxi-boards && git pull )
fi
cp sunxi-boards/sys_config/a20/Bananapi.fex Bananapi.fex
# TODO : patch Bananapi.fex here
sunxi-tools/fex2bin Bananapi.fex build/script.bin
echo "[INFO] Creating Boot uImage"
( cd linux-3.12.28 &&
make ARCH=arm LOADADDR=0x40008000 CROSS_COMPILE=arm-linux-gnueabihf- sunxi_defconfig &&
make ARCH=arm LOADADDR=0x40008000 CROSS_COMPILE=arm-linux-gnueabihf- menuconfig &&
make ARCH=arm LOADADDR=0x40008000 CROSS_COMPILE=arm-linux-gnueabihf- uImage modules dtbs &&
cp arch/arm/boot/uImage ../build/boot/uImage &&
cp .config ../build/boot/.config &&
make ARCH=arm LOADADDR=0x40008000 CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../build/modules modules_install &&
cp arch/arm/boot/dts/sun7i-a20-bananapi.dtb ../build/boot/sun7i-a20-bananapi.dtb)
echo "[INFO] Creating boot image"
( mkimage -C none -A arm -T script -d boot.cmd ./build/boot/boot.scr )
IMG_FILE="bananapi.img"
echo "[INFO] Allocating image space"
dd if=/dev/zero of=${IMG_FILE} bs=1M count=5000
LOOP_DEV=`sudo losetup -f --show ${IMG_FILE}`
LOOP_PART_BOOT="${LOOP_DEV}p1"
LOOP_PART_SYS="${LOOP_DEV}p2"
sudo parted -s "${LOOP_DEV}" mklabel msdos
sudo parted -s "${LOOP_DEV}" unit cyl mkpart primary fat32 -- 0 2cyl
sudo parted -s "${LOOP_DEV}" unit cyl mkpart primary ext2 -- 2cyl -0
sudo parted -s "${LOOP_DEV}" set 1 boot on
sudo parted -s "${LOOP_DEV}" print
sudo partprobe "${LOOP_DEV}"
echo "[INFO] Creating filesystems"
sudo mkfs.vfat "${LOOP_PART_BOOT}" -I -n boot
sudo mkfs.ext4 -O ^has_journal -E stride=2,stripe-width=1024 -b 4096 "${LOOP_PART_SYS}" -L system
sync
echo "[INFO] Burning the bootloader"
sudo dd if=/dev/zero of=${LOOP_DEV} bs=1k count=1023 seek=1
sudo dd if=build/boot/u-boot-sunxi-with-spl.bin of=${LOOP_DEV} bs=1024 seek=8
sync
echo "[INFO] Copying boot files"
sudo mount -t vfat "${LOOP_PART_BOOT}" /mnt
sudo cp build/boot/uImage /mnt
sudo cp build/boot/boot.scr /mnt
sudo cp build/boot/sun7i-a20-bananapi.dtb /mnt
sync
ls -al /mnt
sudo umount /mnt
# NOTE: This file system "debian-fs" is just taken from a standard bananian image.
echo "[INFO] Copying rootfs"
sudo mount -t ext4 "${LOOP_PART_SYS}" /mnt
sudo rm -rf /mnt/*
sudo cp -r ./debian-fs/* /mnt
if [ -f /mnt/README.md ]; then
sudo rm -rf /mnt/README.md
fi
sync
echo "[INFO] Copying modules"
sudo mkdir -p /mnt/lib/modules
sudo rm -rf /mnt/lib/modules/
sudo cp -r build/modules/lib /mnt/
sync
echo "[INFO] Creating /proc, /sys, /mnt, /tmp & /boot"
sudo mkdir -p /mnt/proc
sudo mkdir -p /mnt/sys
sudo mkdir -p /mnt/mnt
sudo mkdir -p /mnt/tmp
sudo mkdir -p /mnt/boot
sync
ls -al /mnt
sudo umount /mnt
echo
echo Umount
echo
sudo losetup -d ${LOOP_DEV}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment