]> spindle.queued.net Git - xodist/blob - mkbootable.sh
bootable attempt
[xodist] / mkbootable.sh
1 #!/bin/sh
2 set -e
3
4 IMAGE_DEFAULT=
5 INTERACTIVE=yes
6 OUTPUT=${IMAGE_DEFAULT}.bootable
7
8 . functions.sh
9
10 images()
11 {
12         echo "Available images:" 1>&2
13         echo -n "  " 1>&2
14         ls *.img | cut -f1 -d. | tr '\n' ' ' 1>&2
15 }
16
17 usage()
18 {
19         echo "" 1>&2
20         echo "Usage: $0 [<options>] <image-name>" 1>&2
21         echo "" 1>&2
22         echo "Options:" 1>&2
23         echo "  --no-interactive    in the generated media, during boot, do not prompt" 1>&2
24         echo "  --output dir        directory in which to create the structure" 1>&2
25         echo "" 1>&2
26         echo "Argument:" 1>&2
27         echo "  <image-name>       an image name, default $IMAGE_DEFAULT" 1>&2
28         echo "" 1>&2
29         images
30         echo "" 1>&2
31         exit 1
32 }
33
34 if test $# == 0; then
35         usage
36 fi
37
38 IMAGE="$IMAGE_DEFAULT"
39 while test $# != 0
40 do
41         case $1 in
42         --no-interactive)
43                 INTERACTIVE=no
44                 ;;
45         --interactive)
46                 INTERACTIVE=yes
47                 ;;
48         --output)
49                 OUTPUT=$2
50                 shift
51                 ;;
52         *)
53                 if [ "$#" != "1" ]; then
54                         echo "Unknown option $1" 1>&2
55                         usage
56                 else
57                         IMAGE="$1"
58                         if [ "${OUTPUT}" == "" ]; then
59                                 OUTPUT=${IMAGE}.bootable
60                         fi
61                 fi
62                 ;;
63         esac
64         shift
65 done
66
67 if ! test -f ${IMAGE}.img; then
68         echo "*** No such image ${IMAGE}"
69         exit 1
70 fi
71
72 if ! test -d ${OUTPUT}; then
73         mkdir ${OUTPUT}
74 fi
75
76 cp ${IMAGE}.{dat,crc,img} ${OUTPUT}
77
78 mkdir -p ${OUTPUT}/boot
79
80 # create essential header required by OpenFirmware
81 cat <<EOF >${OUTPUT}/boot/olpc.fth
82 \ OLPC boot script
83
84 cr
85 ." This is a debxo bootable install script." cr
86 cr
87 ." `md5sum ${IMAGE}.img`" cr
88 ." `md5sum ${IMAGE}.dat`" cr
89 ." `md5sum ${IMAGE}.crc`" cr
90 cr
91 EOF
92
93 # create either an interactive or non-interactive section
94 case $INTERACTIVE in
95         no)
96                 cat <<EOF >>${OUTPUT}/boot/olpc.fth
97
98 \ --no-interactive was used, so we do not prompt
99 ." Erasing everything here and installing debxo ${IMAGE}" cr
100 EOF
101                 ;;
102         yes|*)
103                 cat <<EOF >>${OUTPUT}/boot/olpc.fth
104
105 \ --interactive was used, so we prompt before erasing
106 ." Power off to abort, or" cr
107 ." press Enter to erase everything here and install debxo ${IMAGE} ?"
108 begin
109     key 13 =
110 until
111 EOF
112                 ;;
113 esac
114
115 cat <<EOF >>${OUTPUT}/boot/olpc.fth
116
117 cr
118 ." Starting"
119
120 \ erase the NAND flash and fill it with the image
121 update-nand u:\\${IMAGE}.img
122
123 \ boot from the NAND flash
124 boot n:\boot\olpc.fth
125 EOF
126
127 # TODO: avoid reflashing if already flashed