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
30 echo " --help display this help screen" 1>&2
40 [ -d ./configs/${CONFIG_TYPE} ] || {
41 echo "Error: can't find directory './configs/${CONFIG_TYPE}/'!" 1>&2
50 if [ "$#" != "2" ]; then
51 echo "Unknown option $1" 1>&2
63 if [ "${IMG_NAME}" == "${IMG_NAME/.img/.dat}" ]; then
64 DAT_NAME=${IMG_NAME}.dat
66 DAT_NAME=${IMG_NAME/.img/.dat}
69 if [ ! -d "${ROOT_DIR}" ]; then
71 echo "*** Unable to find root directory!" 1>&2
75 check_for_cmds mkfs.jffs2 sumtool || exit 1
77 # create image's /etc/fstab
78 if [ ! -f ./configs/${CONFIG_TYPE}/fstab-jffs2 ]; then
79 echo "*** Unable to find fstab-jffs2!" 1>&2
82 sed 's/[[:space:]]#.*//' ./configs/${CONFIG_TYPE}/fstab-jffs2 > ${ROOT_DIR}/etc/fstab
84 # TODO: this needs to go into an OFW package; here it's a hack
85 # create image's /boot/olpc.fth
86 if [ -f ./configs/${CONFIG_TYPE}/olpc.fth-jffs2 ]; then
87 cp ./configs/${CONFIG_TYPE}/olpc.fth-jffs2 ${ROOT_DIR}/boot/olpc.fth
95 mkfs.jffs2 -n -e128KiB -r ${root_dir} -o ${out}.pre
96 sumtool -n -p -e 128KiB -i ${out}.pre -o ${out}
102 cat >${IMG_NAME}<<EOF
108 printf "partitions:" >> ${IMG_NAME}
109 sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \
110 while read name mntpt fstype extra; do
111 size=$(echo $extra | sed -ne 's/.*[[:space:]]\+#[[:space:]]\+//p')
112 if [ "${size}" = "" ]; then
115 # size in fstab is in MB; convert to 128KiB chunks (in hex)
118 size=`printf "%x\n" $size`
120 printf " $name $size" >> ${IMG_NAME}
122 printf "\n" >> ${IMG_NAME}
124 # individual partitions
125 sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \
126 while read name mntpt fstype extra; do
127 cat >>${IMG_NAME}<<EOF
128 set-partition: ${name}
131 # sha256 summing for data
132 eblocks=$((`stat --printf "%s\n" _${name}.img` / (128*1024)))
133 for b in $(seq 0 $(($eblocks - 1))); do
134 sha=$(dd status=noxfer bs=128KiB skip=$b count=1 if=_${name}.img 2>/dev/null \
135 | sha256sum | cut -d\ -f1)
136 echo "eblock: `printf '%x' $b` sha256 $sha" >> ${IMG_NAME}
138 cat >>${IMG_NAME}<<EOF
145 # move separate partitions out of the way
146 sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \
147 while read name mntpt fstype extra; do
148 if [ "$mntpt" = "/" ]; then
152 mv ${ROOT_DIR}/${mntpt} "_${name}"
153 mkdir ${ROOT_DIR}/${mntpt}
157 sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \
158 while read name mntpt fstype extra; do
159 if [ "$mntpt" = "/" ]; then
160 create_jffs2 ${ROOT_DIR} "_${name}.img"
163 create_jffs2 "_${name}" "_${name}.img"
167 # move separate partitions back into the chroot
168 sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \
169 while read name mntpt fstype extra; do
170 if [ "$mntpt" = "/" ]; then
174 rmdir ${ROOT_DIR}/${mntpt}
175 mv "_${name}" ${ROOT_DIR}/${mntpt}
178 # partition map is used by OFW for partition layout and sha256 checksums
181 # concat partitions, finish up
183 sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \
184 while read name mntpt fstype extra; do
185 cat "_${name}.img" >> ${DAT_NAME}