3 # mkbootable.sh, make a bootable file set from a jffs2 image
4 # Copyright © 2008 James Cameron <quozl@laptop.org>
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.
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.
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.
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,
26 # mount /dev/sdz1 /mnt
27 # ./mkbootable --output /mnt gnome
34 OUTPUT=${IMAGE_DEFAULT}.bootable
40 echo "Available images:" 1>&2
42 ls *.img | cut -f1 -d. | tr '\n' ' ' 1>&2
48 echo "Usage: $0 [<options>] <image-name>" 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
55 echo " <image-name> an image name, default $IMAGE_DEFAULT" 1>&2
66 IMAGE="$IMAGE_DEFAULT"
81 if [ "$#" != "1" ]; then
82 echo "Unknown option $1" 1>&2
86 if [ "${OUTPUT}" == "" ]; then
87 OUTPUT=${IMAGE}.bootable
95 if ! test -f ${IMAGE}.img; then
96 echo "*** No such image ${IMAGE}"
100 if ! test -d ${OUTPUT}; then
104 cp ${IMAGE}.{dat,img} ${OUTPUT}
106 mkdir -p ${OUTPUT}/boot
108 # create essential header required by OpenFirmware
109 cat <<EOF >${OUTPUT}/boot/olpc.fth
115 ." This is a xodist bootable install script for the OLPC XO-1." cr
118 ." `md5sum ${IMAGE}.img`" cr
119 ." `md5sum ${IMAGE}.dat`" cr
123 # create either an interactive or non-interactive section
126 cat <<EOF >>${OUTPUT}/boot/olpc.fth
128 \ --no-interactive was used, so we do not prompt
129 ." Erasing everything here and installing ${IMAGE}" cr
133 cat <<EOF >>${OUTPUT}/boot/olpc.fth
135 \ --interactive was used, so we prompt before erasing
136 ." Type yes then enter to erase everything here and install ${IMAGE} ? "
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]
147 cat <<EOF >>${OUTPUT}/boot/olpc.fth
152 \ erase the NAND flash and fill it with the image
153 \ boot from the NAND flash
155 " update-nand u:\\${IMAGE}.img" evaluate
156 " boot n:\boot\olpc.fth" evaluate
162 # TODO: avoid reflashing if already flashed