The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / board / freescale / imx28evk / create-boot-sd.sh
1 #!/bin/sh
2
3 set -u
4 set -e
5
6 PROGNAME=$(basename $0)
7
8 usage()
9 {
10     echo "Create an SD card that boots on an i.MX28 EVK board."
11     echo
12     echo "Note: all data on the the card will be completely deleted!"
13     echo "Use with care!"
14     echo "Superuser permissions may be required to write to the device."
15     echo
16     echo "Usage: ${PROGNAME} <sd_block_device>"
17     echo "Arguments:"
18     echo "  <sd_block_device>     The device to be written to"
19     echo
20     echo "Example: ${PROGNAME} /dev/mmcblk0"
21     echo
22 }
23
24 if [ $# -ne 1 ]; then
25     usage
26     exit 1
27 fi
28
29 if [ $(id -u) -ne 0 ]; then
30     echo "${PROGNAME} must be run as root"
31     exit 1
32 fi
33
34 DEV=${1}
35
36 # The partition name prefix depends on the device name:
37 # - /dev/sde -> /dev/sde1
38 # - /dev/mmcblk0 -> /dev/mmcblk0p1
39 if echo ${DEV}|grep -q mmcblk ; then
40     PART="p"
41 else
42     PART=""
43 fi
44
45 PART1=${DEV}${PART}1
46 PART2=${DEV}${PART}2
47 PART3=${DEV}${PART}3
48
49 # Unmount the partitions if mounted
50 umount ${PART1} || true
51 umount ${PART2} || true
52 umount ${PART3} || true
53
54 # First, clear the card
55 dd if=/dev/zero of=${DEV} bs=1M count=20
56
57 sync
58
59 # Partition the card.
60 # SD layout for i.MX28 boot:
61 # - Special partition type 53 at sector 2048, containing an SD-SB-encapsulated u-boot
62 # - FAT partition containing zImage
63 # - ext2/3 partition formatted as ext2 or ext3, containing the root filesystem.
64 sfdisk --force -u S ${DEV} <<EOF
65 2048,2000,53
66 4048,16000,b
67 20048,,L
68 EOF
69
70 sync
71
72 # Copy the bootloader at offset 2048
73 # (We need to skip the partition table in the .sd, too.)
74 dd if=output/images/u-boot.sd of=${DEV}1 bs=1M
75
76 # Prepare a temp dir for mounting partitions
77 TMPDIR=$(mktemp -d)
78  
79 # FAT partition: kernel
80 mkfs.vfat ${PART2}
81 mount ${PART2} ${TMPDIR}
82 cp output/images/*Image ${TMPDIR}/
83 cp output/images/*.dtb  ${TMPDIR}/ || true
84 sync
85 umount ${TMPDIR}
86
87 # ext2 partition: root filesystem
88 mkfs.ext2 ${PART3}
89 mount ${PART3} ${TMPDIR}
90 tar -C ${TMPDIR}/ -xf output/images/rootfs.tar
91 sync
92 umount ${TMPDIR}
93
94 # Cleanup
95 rmdir ${TMPDIR}
96 sync
97 echo Done