Open main menu

DAVE Developer's Wiki β

Changes

Template:How to create a bootable SD card

2,071 bytes added, 12:52, 1 July 2021
no edit summary
The resulting card is partitioned as depicted [[Axel_Embedded_Linux_Kit_(XELK)#XELK_microSD_Layout|here]].
The script - named <code>mksd.sh</code> - looks like thiscan be realized with the following code:
<pre>
TBD #!/bin/bash if [[ -z $1 || -z $2 || -z $3 || -z $4 || -z $5 ]]then echo "$0 Usage: cat " echo " $0 <device> <u-boot.img> <SPL> <binaries directory> <rootfs tar.bz2>" echo " Example: $0 /dev/sdc u-boot.img SPL binaries/ rootfs.tar.bz2" exitfi if [ "$(whoami)" != "root" ]then echo "you must be root to run this script!" exitfi if ! [[ -b $1 ]]then echo "$1 is not a valid block device!" exitfi if ! [[ -e $2 ]]then echo "Incorrect u-boot.img location!" exitfi if ! [[ -e $3 ]]then echo "Incorrect SPL location!" exitfi if ! [[ -d $4 ]]then echo "Incorrect Binaries location!" exitfi if ! [[ -f $5 ]]then echo "Incorrect rootfs location!" exitfi DRIVE=$1if [[ "$DRIVE" == *"mmcblk"* ]]then echo "You're using a mmc device, I need to fix partition names" PART="p"else PART=""fiUBOOT=$2SPL=$3BINARIES=$4RFS=$5 echo "All data on "$DRIVE" now will be destroyed! Continue? [y/n]"read ansif ! [ $ans == 'y' ]then exitfi echo "[Partitioning $1...]" dd if=/dev/zero of mksd=$DRIVE bs=1024 count=1024 SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'` echo DISK SIZE - $SIZE bytes CYLINDERS=`echo $SIZE/255/63/512 | bc` # check if we're running an old (e.g. 2.20.x) or new (e.g.sh script2.24.x) sfdisksfdisk --help | grep -- -H if [ "$?" -eq "0" ]then { echo 40,1380,0x0c,* echo 1420,,83,- } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVEelse{ echo 16M,8176M,0x0c,* echo 8192M,,83,-} | sfdisk $DRIVEfi partprobe  echo "[Making filesystems...]"mkfs.vfat -F 32 -n BOOT "$DRIVE$PART"1 #> /dev/nullmkfs.ext3 -F -L ROOTFS "$DRIVE$PART"2 #> /dev/null echo "[Copying files...]" binaries_dir=${BINARIES%/}mount "$DRIVE$PART"1 /mntcp -av --no-preserve=ownership $binaries_dir/* /mnt/umount "$DRIVE$PART"1 echo "[Extracting rfs (this may take a while...)]"mount "$DRIVE$PART"2 /mnttar jxf $RFS -C /mnt > /dev/nullchmod 755 /mntumount "$DRIVE$PART"2 echo "[Programming SPL]"dd if=$SPL of=$DRIVE bs=512 seek=2 conv=fsync echo "[Programming u-boot.img]"dd if=$UBOOT of=$DRIVE bs=1k seek=69 conv=fsync echo "[Done]"
</pre>
 
Here is an example that shows how to use this script. Let's assume that the binary files were downloaded in the <code>desk</code> subdirectory of the working directory. Before invoking the script, the following files has to be renamed in order to make them compatible with the default U-Boot environment variables:
8,226
edits