Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from docbobo/master
Browse files Browse the repository at this point in the history
Bring image-builder-odroid-c2 in line with image-builder-rpi
  • Loading branch information
DieterReuter authored Mar 5, 2017
2 parents f6946b8 + 56d59b6 commit d80c3d7
Show file tree
Hide file tree
Showing 36 changed files with 740 additions and 466 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.img
*.img.zip
*.img.zip.sha256
*.tar.gz
*.xz
.vagrant/
85 changes: 0 additions & 85 deletions builder/boot.ini

This file was deleted.

142 changes: 73 additions & 69 deletions builder/build.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
#!/bin/bash
set -ex

# This script should be run only inside of a Docker container
if [ ! -f /.dockerenv ]; then
echo "ERROR: script works only in a Docker container!"
exit 1
fi

# get versions for software that needs to be installed
source /workspace/versions.config

### setting up some important variables to control the build process

# where to store our created sd-image file
BUILD_RESULT_PATH="/workspace"

# place to build our sd-image
BUILD_PATH="/build"

# where to store our base file system
HYPRIOT_OS_VERSION="v0.7.2"
ROOTFS_TAR="rootfs-arm64-${HYPRIOT_OS_VERSION}.tar.gz"
ROOTFS_TAR="rootfs-arm64-debian-${HYPRIOT_OS_VERSION}.tar.gz"
ROOTFS_TAR_PATH="$BUILD_RESULT_PATH/$ROOTFS_TAR"

# size of root and boot partion
ROOT_PARTITION_SIZE="800M"
# Show TRAVSI_TAG in travis builds
echo TRAVIS_TAG="${TRAVIS_TAG}"

# device specific settings
# name of the sd-image we gonna create
HYPRIOT_IMAGE_VERSION=${VERSION:="dirty"}
HYPRIOT_IMAGE_NAME="hypriotos-odroid-c2-${HYPRIOT_IMAGE_VERSION}.img"
IMAGE_ROOTFS_PATH="/image-rootfs.tar.gz"
QEMU_ARCH="aarch64"
export HYPRIOT_IMAGE_VERSION

# specific versions of kernel/firmware and docker tools
export DOCKER_ENGINE_VERSION="1.9.1-1"
export DOCKER_COMPOSE_VERSION="1.5.2-80"
export DOCKER_MACHINE_VERSION="0.4.1-72"

# create build directory for assembling our image filesystem
rm -rf $BUILD_PATH
mkdir -p $BUILD_PATH

# download our base root file system
if [ ! -f $ROOTFS_TAR_PATH ]; then
wget -q -O $ROOTFS_TAR_PATH https://github.com/hypriot/os-rootfs/releases/download/$HYPRIOT_OS_VERSION/$ROOTFS_TAR
if [ ! -f "$ROOTFS_TAR_PATH" ]; then
wget -q -O "$ROOTFS_TAR_PATH" "https://github.com/hypriot/os-rootfs/releases/download/$HYPRIOT_OS_VERSION/$ROOTFS_TAR"
fi

# verify checksum of our root filesystem
echo "${ROOTFS_TAR_CHECKSUM} ${ROOTFS_TAR_PATH}" | sha256sum -c -

# extract root file system
tar -xzf $ROOTFS_TAR_PATH -C $BUILD_PATH
tar -xzf "$ROOTFS_TAR_PATH" -C $BUILD_PATH

# register qemu-arm with binfmt
# to ensure that binaries we use in the chroot
# are executed via qemu-arm
update-binfmts --enable qemu-$QEMU_ARCH

# set up mount points for pseudo filesystems
Expand All @@ -55,72 +58,73 @@ mount -o bind /dev/pts $BUILD_PATH/dev/pts
mount -t proc none $BUILD_PATH/proc
mount -t sysfs none $BUILD_PATH/sys

#---modify image---
# modify/add image files directly
# e.g. root partition resize script
cp -R /builder/files/* $BUILD_PATH/

# modify image in chroot environment
chroot $BUILD_PATH /bin/bash </builder/chroot-script.sh
#---modify image---

umount -l $BUILD_PATH/sys || true
umount -l $BUILD_PATH/proc || true
umount -l $BUILD_PATH/dev/pts || true
umount -l $BUILD_PATH/dev || true
# make our build directory the current root
# and install the kernel packages, docker tools
# and some customizations for Odroid C2.
chroot $BUILD_PATH /bin/bash < /builder/chroot-script.sh

# unmount pseudo filesystems
umount -l $BUILD_PATH/sys
umount -l $BUILD_PATH/proc
umount -l $BUILD_PATH/dev/pts
umount -l $BUILD_PATH/dev

# package image filesytem into two tarballs - one for bootfs and one for rootfs
# ensure that there are no leftover artifacts in the pseudo filesystems
rm -rf ${BUILD_PATH}/{dev,sys,proc}/*

tar -czf /image_with_kernel_boot.tar.gz -C ${BUILD_PATH}/boot .
du -sh ${BUILD_PATH}/boot
rm -Rf ${BUILD_PATH}/boot
tar -czf /image_with_kernel_root.tar.gz -C ${BUILD_PATH} .
du -sh ${BUILD_PATH}
ls -alh /image_with_kernel_*.tar.gz

# download the ready-made raw image for the Odroid
if [ ! -f "${BUILD_RESULT_PATH}/${RAW_IMAGE}.zip" ]; then
wget -q -O "${BUILD_RESULT_PATH}/${RAW_IMAGE}.zip" "https://github.com/hypriot/image-builder-raw/releases/download/${RAW_IMAGE_VERSION}/${RAW_IMAGE}.zip"
fi

# package image rootfs
tar -czf $IMAGE_ROOTFS_PATH -C $BUILD_PATH .
# verify checksum of the ready-made raw image
echo "${RAW_IMAGE_CHECKSUM} ${BUILD_RESULT_PATH}/${RAW_IMAGE}.zip" | sha256sum -c -

# create the image and add a single ext4 filesystem
# --- important settings for ODROID SD card
# - initialise the partion with MBR
# - use start sector 3072, this reserves 1.5MByte of disk space
# - don't set the partition to "bootable"
# - format the disk with ext4
# for debugging use 'set-verbose true'
#set-verbose true
unzip -p "${BUILD_RESULT_PATH}/${RAW_IMAGE}" > "/${HYPRIOT_IMAGE_NAME}"

#FIXME: use latest upstream u-boot files from hardkernel
# download current bootloader/u-boot images from hardkernel
wget -q -O - http://dn.odroid.com/S905/BootLoader/ODROID-C2/c2_bootloader.tar.gz | tar -C /tmp -xzvf -
cp /tmp/c2_bootloader/bl1.bin.hardkernel .
cp /tmp/c2_bootloader/u-boot.bin .
cp /tmp/c2_bootloader/sd_fusing.sh .
rm -rf /tmp/c2_bootloader/

guestfish <<EOF
# create new image disk
sparse /$HYPRIOT_IMAGE_NAME $ROOT_PARTITION_SIZE
run
part-init /dev/sda mbr
part-add /dev/sda primary 3072 -1
part-set-bootable /dev/sda 1 false
mkfs ext4 /dev/sda1
# import base rootfs
mount /dev/sda1 /
tar-in $IMAGE_ROOTFS_PATH / compress:gzip
#FIXME: use dd to directly writing u-boot to image file
#FIXME2: later on, create a dedicated .deb package to install/update u-boot
# write bootloader and u-boot into image start sectors 0-3071
upload sd_fusing.sh /boot/sd_fusing.sh
upload bl1.bin.hardkernel /boot/bl1.bin.hardkernel
upload u-boot.bin /boot/u-boot.bin
upload /builder/boot.ini /boot/boot.ini
copy-file-to-device /boot/bl1.bin.hardkernel /dev/sda size:442 sparse:true
copy-file-to-device /boot/bl1.bin.hardkernel /dev/sda srcoffset:512 destoffset:512 sparse:true
copy-file-to-device /boot/u-boot.bin /dev/sda destoffset:49664 sparse:true
EOF

# log image partioning
fdisk -l "/$HYPRIOT_IMAGE_NAME"
wget -q -O - http://dn.odroid.com/S905/BootLoader/ODROID-C2/c2_boot_release.tar.gz | tar -C /tmp -xzvf -
cp /tmp/sd_fuse/bl1.bin.hardkernel .
cp /tmp/sd_fuse/u-boot.bin .
cp /tmp/sd_fuse/sd_fusing.sh .
rm -rf /tmp/sd_fuse/

guestfish -a "/${HYPRIOT_IMAGE_NAME}" << _EOF_
run
# import filesystem content
mount /dev/sda2 /
tar-in /image_with_kernel_root.tar.gz / compress:gzip
mkdir /boot
mount /dev/sda1 /boot
tar-in /image_with_kernel_boot.tar.gz /boot compress:gzip
# write bootloader and u-boot into image start sectors 0-3071
upload bl1.bin.hardkernel /boot/bl1.bin.hardkernel
upload u-boot.bin /boot/u-boot.bin
copy-file-to-device /boot/bl1.bin.hardkernel /dev/sda size:442 sparse:true
copy-file-to-device /boot/bl1.bin.hardkernel /dev/sda srcoffset:512 destoffset:512 sparse:true
copy-file-to-device /boot/u-boot.bin /dev/sda destoffset:49664 sparse:true
_EOF_

# ensure that the travis-ci user can access the SD card image file
umask 0000

# compress image
pigz --zip -c "$HYPRIOT_IMAGE_NAME" > "$BUILD_RESULT_PATH/$HYPRIOT_IMAGE_NAME.zip"
zip "${BUILD_RESULT_PATH}/${HYPRIOT_IMAGE_NAME}.zip" "${HYPRIOT_IMAGE_NAME}"
cd ${BUILD_RESULT_PATH} && sha256sum "${HYPRIOT_IMAGE_NAME}.zip" > "${HYPRIOT_IMAGE_NAME}.zip.sha256" && cd -

# test sd-image that we have built
VERSION=${HYPRIOT_IMAGE_VERSION} rspec --format documentation --color /builder/test
Loading

0 comments on commit d80c3d7

Please sign in to comment.