3 # Copyright © 2008-2009 Andres Salomon <dilinger@collabora.co.uk>
5 # This file is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 echo "Usage: $0 [<options>] <root directory> <img>" 1>&2
29 echo " --config-type <config> directory name in configs/ to use" 1>&2
39 [ -d ./configs/${CONFIG_TYPE} ] || {
40 echo "Error: can't find directory './configs/${CONFIG_TYPE}/'!" 1>&2
46 if [ "$#" != "2" ]; then
47 echo "Unknown option $1" 1>&2
59 if [ "${IMG_NAME}" == "${IMG_NAME/.img/.dat}" ]; then
60 DAT_NAME=${IMG_NAME}.dat
62 DAT_NAME=${IMG_NAME/.img/.dat}
65 if [ ! -d "${ROOT_DIR}" ]; then
67 echo "*** Unable to find root directory!" 1>&2
71 check_for_cmds mkfs.jffs2 sumtool || exit 1
73 # create image's /etc/fstab
74 if [ ! -f ./configs/${CONFIG_TYPE}/fstab-jffs2 ]; then
75 echo "*** Unable to find fstab-jffs2!" 1>&2
78 sed 's/[[:space:]]#.*//' ./configs/${CONFIG_TYPE}/fstab-jffs2 > ${ROOT_DIR}/etc/fstab
80 # TODO: this needs to go into an OFW package; here it's a hack
81 # create image's /boot/olpc.fth
82 if [ -f ./configs/${CONFIG_TYPE}/olpc.fth-jffs2 ]; then
83 cp ./configs/${CONFIG_TYPE}/olpc.fth-jffs2 ${ROOT_DIR}/boot/olpc.fth
91 # XXX: do we want to switch to lzo? (mkfs.jffs2 -X lzo)
92 mkfs.jffs2 -n -e128KiB -r ${root_dir} -o ${out}.pre
93 sumtool -n -p -e 128KiB -i ${out}.pre -o ${out}
100 eblocks=$((`stat --printf "%s\n" $f` / (128*1024)))
101 for b in $(seq 0 $(($eblocks - 1))); do
102 sha=$(dd status=noxfer bs=128KiB skip=$b count=1 if=$f 2>/dev/null | sha256sum | cut -d\ -f1)
103 echo "eblock: `printf '%x' $b` sha256 $sha" >> ${IMG_NAME}
109 # 0x190 * 128KiB = 50MiB boot, and the rest for root
110 cat >${IMG_NAME}<<EOF
113 partitions: boot 190 root -1
117 do_sha256 "_boot.img"
118 cat >>${IMG_NAME}<<EOF
124 do_sha256 "_root.img"
125 cat >>${IMG_NAME}<<EOF
131 # create the boot partition
132 ln -s . ${ROOT_DIR}/boot/boot
133 create_jffs2 ${ROOT_DIR}/boot _boot.img
134 rm -f ${ROOT_DIR}/boot/boot
136 # create the root partition
137 mv ${ROOT_DIR}/boot _boot
138 mkdir ${ROOT_DIR}/boot
139 create_jffs2 ${ROOT_DIR} _root.img
140 rmdir ${ROOT_DIR}/boot
141 mv _boot ${ROOT_DIR}/boot
143 # concat partitions, finish up
145 cat _boot.img _root.img > ${DAT_NAME}
146 rm -f _boot.img _root.img