path: root/board/chromebook/mksd.sh
diff options
Diffstat (limited to 'board/chromebook/mksd.sh')
1 files changed, 69 insertions, 0 deletions
diff --git a/board/chromebook/mksd.sh b/board/chromebook/mksd.sh
new file mode 100755
index 0000000000..cba1578ec8
--- /dev/null
+++ b/board/chromebook/mksd.sh
@@ -0,0 +1,69 @@
+# This scripts makes a minimal bootable SD card image for the Chromebook.
+# The resulting file is called bootsd.img. It should be written directly
+# to the card:
+# SD=/dev/mmcblk1 # check your device name!
+# dd if=output/images/bootsd.img of=$SD
+# The partitions are created just large enough to hold the kernel and
+# the rootfs image. Most of the card will be empty, and the secondary
+# GPT will not be in its proper location.
+# cgpt does not create protective MBR, and the kernel refuses to read
+# GPT unless there's some kind of MBR in sector 0. So we need parted
+# to write that single sector before doing anything with the GPT.
+run() { echo "$@"; "$@"; }
+die() { echo "$@" >&2; exit 1; }
+test -f $kernel || die "No kernel image found"
+test -f $rootfs || die "No rootfs image found"
+test -x $cgpt || die "cgpt not found (host-vboot-utils have not been built?)"
+# True file sizes in bytes
+kernelsize=`stat -t $kernel | cut -d\ -f2`
+rootfssize=`stat -t $rootfs | cut -d\ -f2`
+# The card is partitioned in sectors of 8KB.
+# 4 sectors are reserved for MBR+GPT. Their actual size turns out
+# to be 33 512-blocks which is just over 2 sectors, but we align
+# it to a nice round number.
+# There is also a copy of MBR+GPT at the end of the image.
+# It's going to be useless but both tools assume it's there.
+run dd bs=$sec count=$imagesec if=/dev/zero of=$bootsd
+# cgpt needs offsets and sizes in 512-blocks.
+# This command initializes both GPT and MBR
+run $parted -s $bootsd mklabel gpt
+# The kernel partition must be marked as bootable, that's why -S -T -P
+run $cgpt add -i 1 -b $kernelstart -s $kernelblocks \
+ -t kernel -l kernel \
+ -S 1 -T 1 -P 10 $bootsd
+# It does not really matter where the rootfs partition is located as long
+# as the kernel can find it.
+# However, if anything is changed here, kernel.args must be updated as well.
+run $cgpt add -i 2 -b $rootfsstart -s $rootfsblocks \
+ -t data -l rootfs $bootsd
+run dd bs=$block if=$kernel of=$bootsd seek=$kernelstart
+run dd bs=$block if=$rootfs of=$bootsd seek=$rootfsstart