]> spindle.queued.net Git - xodist/blob - mkbootable.sh
add xterm for erikg
[xodist] / mkbootable.sh
1 #!/bin/sh
2 #
3 # mkbootable.sh, make a bootable file set from a jffs2 image
4 # Copyright © 2008  James Cameron <quozl@laptop.org>
5 #
6 # This file is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #
20
21 # Using an image produced by mkjffs2.sh,
22 # produces a tree of files suitable for erasing and loading an XO,
23 # typical usage is to mount USB storage and then populate the storage,
24 # for example:
25 #
26 # mount /dev/sdz1 /mnt
27 # ./mkbootable --output /mnt gnome
28 # umount /mnt
29
30 set -e
31
32 IMAGE_DEFAULT=
33 INTERACTIVE=yes
34 OUTPUT=${IMAGE_DEFAULT}.bootable
35
36 . functions.sh
37
38 images()
39 {
40         echo "Available images:" 1>&2
41         echo -n "  " 1>&2
42         ls *.img | cut -f1 -d. | tr '\n' ' ' 1>&2
43 }
44
45 usage()
46 {
47         echo "" 1>&2
48         echo "Usage: $0 [<options>] <image-name>" 1>&2
49         echo "" 1>&2
50         echo "Options:" 1>&2
51         echo "  --no-interactive    in the generated media, during boot, do not prompt" 1>&2
52         echo "  --output dir        directory in which to create the structure" 1>&2
53         echo "" 1>&2
54         echo "Argument:" 1>&2
55         echo "  <image-name>       an image name, default $IMAGE_DEFAULT" 1>&2
56         echo "" 1>&2
57         images
58         echo "" 1>&2
59         exit 1
60 }
61
62 if test $# == 0; then
63         usage
64 fi
65
66 IMAGE="$IMAGE_DEFAULT"
67 while test $# != 0
68 do
69         case $1 in
70         --no-interactive)
71                 INTERACTIVE=no
72                 ;;
73         --interactive)
74                 INTERACTIVE=yes
75                 ;;
76         --output)
77                 OUTPUT=$2
78                 shift
79                 ;;
80         *)
81                 if [ "$#" != "1" ]; then
82                         echo "Unknown option $1" 1>&2
83                         usage
84                 else
85                         IMAGE="$1"
86                         if [ "${OUTPUT}" == "" ]; then
87                                 OUTPUT=${IMAGE}.bootable
88                         fi
89                 fi
90                 ;;
91         esac
92         shift
93 done
94
95 if ! test -f ${IMAGE}.img; then
96         echo "*** No such image ${IMAGE}"
97         exit 1
98 fi
99
100 if ! test -d ${OUTPUT}; then
101         mkdir ${OUTPUT}
102 fi
103
104 cp ${IMAGE}.{dat,img} ${OUTPUT}
105
106 mkdir -p ${OUTPUT}/boot
107
108 # create essential header required by OpenFirmware
109 cat <<EOF >${OUTPUT}/boot/olpc.fth
110 \ OLPC boot script
111
112 cr
113 ." This is a debxo bootable install script." cr
114 cr
115 ." `md5sum ${IMAGE}.img`" cr
116 ." `md5sum ${IMAGE}.dat`" cr
117 cr
118 EOF
119
120 # create either an interactive or non-interactive section
121 case $INTERACTIVE in
122         no)
123                 cat <<EOF >>${OUTPUT}/boot/olpc.fth
124
125 \ --no-interactive was used, so we do not prompt
126 ." Erasing everything here and installing debxo ${IMAGE}" cr
127 EOF
128                 ;;
129         yes|*)
130                 cat <<EOF >>${OUTPUT}/boot/olpc.fth
131
132 \ --interactive was used, so we prompt before erasing
133 ." Power off to abort, or" cr
134 ." press Enter to erase everything here and install debxo ${IMAGE} ?"
135 begin
136     key d =
137 until
138 EOF
139                 ;;
140 esac
141
142 cat <<EOF >>${OUTPUT}/boot/olpc.fth
143
144 cr
145 ." Starting"
146
147 \ erase the NAND flash and fill it with the image
148 \ boot from the NAND flash
149 : update-and-boot
150   " update-nand u:\\${IMAGE}.img" evaluate
151   " boot n:\boot\olpc.fth" evaluate
152 ;
153
154 update-and-boot
155 EOF
156
157 # TODO: avoid reflashing if already flashed