Commit 3911b005 authored by Nick Elsmore's avatar Nick Elsmore

Create individual boot and rootfs images instead of single partitioned image

parent 70c19106
......@@ -31,7 +31,7 @@ print_usage() {
echo " kernel Build kernel zImage and Debian package"
echo " uboot [2gb|4gb] Build U-Boot for 2gb or 4gb RAM"
echo " rootfs Build rootfs using package repository"
echo " image Build bootable image"
echo " image Build PyraOS images"
}
get_kernel_info() {
......@@ -111,62 +111,49 @@ build_rootfs() {
cp $MULTISTRAP_DIR/export/pyra-debian-stretch-mate-rootfs.tgz $OUT_DIR
}
build_image() {
echo "Building PyraOS image"
build_images() {
echo "Building PyraOS images"
local imagefn="pyraos-stretch-mate.img"
local rootfs_tar_fn="pyra-debian-stretch-mate-rootfs.tgz"
local bootimage_fn="boot.img"
local rootfsimage_fn="rootfs.img"
local rootfs_tar="$OUT_DIR/$rootfs_tar_fn"
local bootimage="$OUT_DIR/$bootimage_fn"
local rootfsimage="$OUT_DIR/$rootfsimage_fn"
if [[ ! -e $OUT_DIR/MLO || ! -e $OUT_DIR/u-boot.bin ]]; then
echo "ERROR: Unable to find U-Boot binaries. Please build U-Boot and try again."
exit 1
fi
if [ ! -e $OUT_DIR/pyra-debian-stretch-mate-rootfs.tgz ]; then
if [ ! -e $rootfs_tar ]; then
echo "ERROR: Unable to find rootfs. Please build rootfs and try again."
exit 1
fi
mkdir -p $IMAGE_WORKDIR
cd $IMAGE_WORKDIR
echo "Creating image"
dd if=/dev/zero of=$imagefn bs=1M count=4096 2>/dev/null
echo "Writing U-Boot"
dd if=$OUT_DIR/MLO of=$imagefn count=1 seek=1 bs=128k conv=notrunc
dd if=$OUT_DIR/u-boot.bin of=$imagefn count=2 seek=1 bs=384k conv=notrunc
echo "Partitioning image"
sfdisk $imagefn <<- __EOF__
1M,256M,0x83,*
,,0x83,
__EOF__
echo "Mounting image"
local loopback=$(sudo losetup --partscan --show --find $IMAGE_WORKDIR/$imagefn)
printf "Creating images..."
dd if=/dev/zero of=$bootimage count=0 seek=256 bs=1M 2>/dev/null
dd if=/dev/zero of=$rootfsimage count=0 seek=3072 bs=1M 2>/dev/null
echo "done"
echo "Creating filesystems"
sudo mkfs.ext4 -O ^64bit ${loopback}p1 -L boot
sudo mkfs.f2fs ${loopback}p2 -l rootfs
printf "Generating filesystems..."
mkfs.ext4 -F -O ^64bit $bootimage -L boot 2>/dev/null >/dev/null
mkfs.f2fs -q $rootfsimage -l rootfs
echo "done"
echo "Populating filesystems"
sudo mkdir -p rootfs
sudo mount ${loopback}p2 rootfs
sudo mkdir -p rootfs/boot
sudo mount ${loopback}p1 rootfs/boot
bar $OUT_DIR/pyra-debian-stretch-mate-rootfs.tgz | sudo tar --numeric-owner -xzf - -C rootfs
echo "Cleaning up"
sync
echo "Populating filesystems..."
(
mkdir -p work
cd work
mkdir -p rootfs
sudo mount $rootfsimage rootfs
mkdir -p rootfs/boot
sudo mount $bootimage rootfs/boot
bar $rootfs_tar | sudo tar --numeric-owner -xzf - -C rootfs
printf "Cleaning up..."
sudo umount rootfs/boot
sudo umount rootfs
cd ../
sudo losetup -d $loopback
cp --sparse=always $IMAGE_WORKDIR/$imagefn $OUT_DIR
sudo rm -rf $IMAGE_WORKDIR
sync
cd ..
rm -rf work
)
echo "done"
}
main() {
......@@ -197,7 +184,7 @@ main() {
;;
image)
build_image
build_images
;;
clean)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment