dev.nlited.com

>>

mkboot

<<<< prev
next >>>>

2015-12-22 22:11:06 chip Page 1482 📢 PUBLIC

Dec 22 2015

This is the script I use to create the microSD boot disks. This version always reformats the disk, which takes about 3 minutes. Updating the MLO, u-boot, or zImage on a prebuilt card can be done using a simple copy.

Updating the rootfs, beyond simply overwriting a few files, is best done by nuking the site from orbit; run the mkboot script from start.

Example:
sudo ./mkboot.sh build/tmp/deply/images/overo /dev/sdb

Updated for Ubuntu 16.04:


mkboot.sh: #!/bin/sh # fdisk portion of script based on mkcard.sh v0.4 # (c) Copyright 2009 Graeme Gregory # Additional functionality by Steve Sakoman # (c) Copyright 2010-2013 Steve Sakoman # Licensed under terms of GPLv2 # # Parts of the procudure base on the work of Denys Dmytriyenko # http://wiki.omap.com/index.php/MMC_Boot_Format VERSION=1.0 RELEASE="vekolako" IMAGE=gumstix-console-image-overo.tar.bz2 # hack to use a particular kernel variant KERNEL_VARIANT="" export LC_ALL=C MOUNT_POINT="/media/microsd" # PWD=`pwd` # WORK_DIR=$PWD if [ $# -eq 0 ]; then echo "" echo "$0 version $VERSION" echo "Usage:sudo -E $0 " echo " src: directory containing image files" echo " drive: SD device (i.e. /dev/sdc)" exit 1; fi WORK_DIR=`realpath $1` DEST_DIR=$2 # Confirm this is the correct directory: if [ ! -f $WORK_DIR/MLO ] ; then echo "No $WORK_DIR/MLO" exit 1; fi echo "Using image files from ${‌WORK_DIR}" cd ${‌WORK_DIR} if ! id | grep -q root; then echo "This utility must be run prefixed with sudo -E " exit 1; fi if [ "$DEST_DIR" = "/dev/sda" ] ; then echo "Sorry, /dev/sda probably holds your PC's rootfs." echo "Please specify an SD device." exit 1; fi DRIVE=$DEST_DIR # Make sure that the SD card isn't mounted before we start if [ -b ${‌DRIVE}1 ]; then umount ${‌DRIVE}1 umount ${‌DRIVE}2 elif [ -b ${‌DRIVE}p1 ]; then umount ${‌DRIVE}p1 umount ${‌DRIVE}p2 else umount ${‌DRIVE} fi SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{‌print $5}'` echo DISK SIZE $SIZE bytes if [ $SIZE -gt 34359738368 ]; then echo "This device is > 32GB and is probably not an SD card!" exit 1; fi #CYLINDERS=`echo $SIZE/255/63/512 | bc` # wipe current partion setup echo "Good bye $DRIVE..." dd if=/dev/zero of=$DRIVE bs=1024 count=1024 # Align partitions for SD card performance/wear optimization # FAT partition size is 131072 sectors (64MB) less: # MBR - 1 sector # padding to align to the page size of the underlying flash - 127 sectors # so we start the first partition at sector 128 and make it 131072 - 128 = 130944 sectors # second partition starts at 131072 and continues to fill the card # Updated for sfdisk version 2.27 (Ubuntu 16.04) { echo label: dos echo label-id: 0 echo 128,130944,0x0C,* echo 131072,,,- } | sfdisk --force $DRIVE sleep 1 if [ -b ${‌DRIVE}1 ]; then PART1=${‌DRIVE}1 PART2=${‌DRIVE}2 elif [ -b ${‌DRIVE}p1 ]; then PART1=${‌DRIVE}p1 PART2=${‌DRIVE}p2 else echo "Improper partitioning on $DRIVE" exit 1; fi umount ${‌PART1} mkfs.vfat -F 32 -n BOOT ${‌PART1} umount ${‌PART2} mke2fs -j -L rootfs ${‌PART2} # create a mount point if it doesn't already exist if [ ! -d $MOUNT_POINT ]; then if ! mkdir $MOUNT_POINT; then echo "Could not create mount point: $MOUNT_POINT" echo "SD card creation was not successful" exit 1; fi fi if mount -t vfat ${‌PART1} $MOUNT_POINT; then echo "Populating boot partition files" cp MLO $MOUNT_POINT cp u-boot.img $MOUNT_POINT cp zImage $MOUNT_POINT sync umount $MOUNT_POINT echo "Boot partition complete" else echo "Can't mount ${‌PART1} at $MOUNT_POINT for boot partition creation" echo "SD card creation was not successful" exit 1; fi # this shouldn't be necessary, but Ubuntu seems to remove the mount point! if [ ! -d $MOUNT_POINT ]; then if ! mkdir $MOUNT_POINT; then echo "Could not create mount point: $MOUNT_POINT" echo "SD card creation was not successful" exit 1; fi fi if mount -t ext3 ${‌PART2} $MOUNT_POINT; then if cd $MOUNT_POINT; then echo "Populating rootfs partition files" echo "This will take several minutes . . ." tar xf $WORK_DIR/$IMAGE cp $WORK_DIR/MLO boot/ cp $WORK_DIR/u-boot.img boot/ cp $WORK_DIR/$IMAGE boot/ sync cd $WORK_DIR umount $MOUNT_POINT echo "Rootfs partition complete" else echo "Error populating rootfs partition" echo "SD card creation was not successful" fi else echo "Can't mount ${‌PART2} at $MOUNT_POINT for rootfs creation" echo "SD card creation was not successful" exit 1; fi echo "SD card creation was successful" exit 0;

This is the version for Ubuntu 12.04, for historical purpose.

Old mkboot.sh: #!/bin/sh # fdisk portion of script based on mkcard.sh v0.4 # (c) Copyright 2009 Graeme Gregory # Additional functionality by Steve Sakoman # (c) Copyright 2010-2013 Steve Sakoman # Licensed under terms of GPLv2 # # Parts of the procudure base on the work of Denys Dmytriyenko # http://wiki.omap.com/index.php/MMC_Boot_Format VERSION=1.0 RELEASE="vekolako" IMAGE=gumstix-console-image-overo.tar.bz2 # hack to use a particular kernel variant KERNEL_VARIANT="" export LC_ALL=C MOUNT_POINT="/media/microsd" # PWD=`pwd` # WORK_DIR=$PWD if [ $# -eq 0 ]; then echo "" echo "$0 version $VERSION" echo "Usage:sudo -E $0 " echo " src: directory containing image files" echo " drive: SD device (i.e. /dev/sdc)" exit 1; fi WORK_DIR=$1 DEST_DIR=$2 # Confirm this is the correct directory: if [ ! -f $WORK_DIR/MLO ] ; then echo "No $WORK_DIR/MLO" exit 1; fi echo "Using image files from ${‌WORK_DIR}" cd ${‌WORK_DIR} if ! id | grep -q root; then echo "This utility must be run prefixed with sudo -E " exit 1; fi if [ "$DEST_DIR" = "/dev/sda" ] ; then echo "Sorry, /dev/sda probably holds your PC's rootfs." echo "Please specify an SD device." exit 1; fi DRIVE=$DEST_DIR # Make sure that the SD card isn't mounted before we start if [ -b ${‌DRIVE}1 ]; then umount ${‌DRIVE}1 umount ${‌DRIVE}2 elif [ -b ${‌DRIVE}p1 ]; then umount ${‌DRIVE}p1 umount ${‌DRIVE}p2 else umount ${‌DRIVE} fi SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'` echo DISK SIZE $SIZE bytes if [ $SIZE -gt 34359738368 ]; then echo "This device is > 32GB and is probably not an SD card!" exit 1; fi CYLINDERS=`echo $SIZE/255/63/512 | bc` # wipe current partion setup echo "Good bye $DRIVE..." dd if=/dev/zero of=$DRIVE bs=1024 count=1024 # Align partitions for SD card performance/wear optimization # FAT partition size is 131072 sectors (64MB) less: # MBR - 1 sector # padding to align to the page size of the underlying flash - 127 sectors # so we start the first partition at sector 128 and make it 131072 - 128 = 130944 sectors # second partition starts at 131072 and continues to fill the card { echo 128,130944,0x0C,* echo 131072,,,- } | sfdisk --force -D -uS -H 255 -S 63 -C $CYLINDERS $DRIVE sleep 1 if [ -b ${‌DRIVE}1 ]; then PART1=${‌DRIVE}1 PART2=${‌DRIVE}2 elif [ -b ${‌DRIVE}p1 ]; then PART1=${‌DRIVE}p1 PART2=${‌DRIVE}p2 else echo "Improper partitioning on $DRIVE" exit 1; fi umount ${‌PART1} mkfs.vfat -F 32 -n boot ${‌PART1} umount ${‌PART2} mke2fs -j -L rootfs ${‌PART2} # create a mount point if it doesn't already exist if [ ! -d $MOUNT_POINT ]; then if ! mkdir $MOUNT_POINT; then echo "Could not create mount point: $MOUNT_POINT" echo "SD card creation was not successful" exit 1; fi fi if mount -t vfat ${‌PART1} $MOUNT_POINT; then echo "Populating boot partition files" cp MLO $MOUNT_POINT cp u-boot.img $MOUNT_POINT cp zImage $MOUNT_POINT sync umount $MOUNT_POINT echo "Boot partition complete" else echo "Can't mount ${‌PART1} at $MOUNT_POINT for boot partition creation" echo "SD card creation was not successful" exit 1; fi # this shouldn't be necessary, but Ubuntu seems to remove the mount point! if [ ! -d $MOUNT_POINT ]; then if ! mkdir $MOUNT_POINT; then echo "Could not create mount point: $MOUNT_POINT" echo "SD card creation was not successful" exit 1; fi fi if mount -t ext3 ${‌PART2} $MOUNT_POINT; then if cd $MOUNT_POINT; then echo "Populating rootfs partition files" echo "This will take several minutes . . ." tar xf $WORK_DIR/$IMAGE cp $WORK_DIR/MLO boot/ cp $WORK_DIR/u-boot.img boot/ cp $WORK_DIR/$IMAGE boot/ sync cd $WORK_DIR umount $MOUNT_POINT echo "Rootfs partition complete" else echo "Error populating rootfs partition" echo "SD card creation was not successful" fi else echo "Can't mount ${‌PART2} at $MOUNT_POINT for rootfs creation" echo "SD card creation was not successful" exit 1; fi echo "SD card creation was successful" exit 0;


WebV7 (C)2018 nlited | Rendered by tikope in 66.817ms | 3.144.89.197