]> spindle.queued.net Git - xodist/blob - mkbootable.sh
debxo: expand ext3 root partition size
[xodist] / mkbootable.sh
1 #!/bin/bash
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 visible
113 clear-screen
114 cr
115 ." This is a xodist bootable install script for the OLPC XO-1." cr
116 cr
117 ." Checksums:" cr
118 ."     `md5sum ${IMAGE}.img`" cr
119 ."     `md5sum ${IMAGE}.dat`" cr
120 cr
121 EOF
122
123 # create either an interactive or non-interactive section
124 case $INTERACTIVE in
125         no)
126                 cat <<EOF >>${OUTPUT}/boot/olpc.fth
127
128 \ --no-interactive was used, so we do not prompt
129 ." Erasing everything here and installing ${IMAGE}" cr
130 EOF
131                 ;;
132         yes|*)
133                 cat <<EOF >>${OUTPUT}/boot/olpc.fth
134
135 \ --interactive was used, so we prompt before erasing
136 ." Type yes then enter to erase everything here and install ${IMAGE} ? "
137 cursor-on
138 key  lcc  dup emit  ascii y = not  [if] cr abort [then]
139 key  lcc  dup emit  ascii e = not  [if] cr abort [then]
140 key  lcc  dup emit  ascii s = not  [if] cr abort [then]
141 key       dup emit  d       = not  [if] cr abort [then]
142
143 EOF
144                 ;;
145 esac
146
147 cat <<EOF >>${OUTPUT}/boot/olpc.fth
148
149 cr
150 ." Starting"
151
152 \ erase the NAND flash and fill it with the image
153 \ boot from the NAND flash
154 : update-and-boot
155   " update-nand u:\\${IMAGE}.img" evaluate
156   " boot n:\boot\olpc.fth" evaluate
157 ;
158
159 update-and-boot
160 EOF
161
162 # TODO: avoid reflashing if already flashed