3 # This scripts makes a minimal bootable SD card image for the Chromebook.
4 # The resulting file is called bootsd.img. It should be written directly
7 # SD=/dev/mmcblk1 # check your device name!
8 # dd if=output/images/bootsd.img of=$SD
10 # The partitions are created just large enough to hold the kernel and
11 # the rootfs image. Most of the card will be empty, and the secondary
12 # GPT will not be in its proper location.
14 # cgpt does not create protective MBR, and the kernel refuses to read
15 # GPT unless there's some kind of MBR in sector 0. So we need parted
16 # to write that single sector before doing anything with the GPT.
17 cgpt
=$HOST_DIR/usr
/bin
/cgpt
18 parted
=$HOST_DIR/usr
/sbin
/parted
19 kernel
=$BINARIES_DIR/uImage.kpart
20 rootfs
=$BINARIES_DIR/rootfs.ext2
22 run
() { echo "$@"; "$@"; }
23 die
() { echo "$@" >&2; exit 1; }
24 test -f $kernel || die
"No kernel image found"
25 test -f $rootfs || die
"No rootfs image found"
26 test -x $cgpt || die
"cgpt not found (host-vboot-utils have not been built?)"
28 # True file sizes in bytes
29 kernelsize
=`stat -t $kernel | cut -d\ -f2`
30 rootfssize
=`stat -t $rootfs | cut -d\ -f2`
32 # The card is partitioned in sectors of 8KB.
33 # 4 sectors are reserved for MBR+GPT. Their actual size turns out
34 # to be 33 512-blocks which is just over 2 sectors, but we align
35 # it to a nice round number.
37 kernelsec
=$
(((kernelsize
+8191)>>13))
38 rootfssec
=$
(((rootfssize
+8191)>>13))
41 # There is also a copy of MBR+GPT at the end of the image.
42 # It's going to be useless but both tools assume it's there.
43 imagesec
=$
((2*headersec
+kernelsec
+rootfssec
))
44 bootsd
="$BINARIES_DIR/bootsd.img"
45 run
dd bs
=$sec count
=$imagesec if=/dev
/zero of
=$bootsd
47 # cgpt needs offsets and sizes in 512-blocks.
49 kernelstart
=$
((headersec
<<4))
50 kernelblocks=$((kernelsec<<4))
51 rootfsblocks=$((rootfssec<<4))
52 rootfsstart=$((kernelstart+kernelblocks))
54 # This command initializes both GPT and MBR
55 run $parted -s $bootsd mklabel gpt
57 # The kernel partition must be marked as bootable, that's why -S -T -P
58 run $cgpt add -i 1 -b $kernelstart -s $kernelblocks \
60 -S 1 -T 1 -P 10 $bootsd
62 # It does not really matter where the rootfs partition is located as long
63 # as the kernel can find it.
64 # However, if anything is changed here, kernel.args must be updated as well.
65 run $cgpt add -i 2 -b $rootfsstart -s $rootfsblocks \
66 -t data -l rootfs $bootsd
68 run dd bs=$block if=$kernel of=$bootsd seek=$kernelstart
69 run dd bs=$block if=$rootfs of=$bootsd seek=$rootfsstart