]> spindle.queued.net Git - xodist/commitdiff
debxo: add initial ubifs support
authorAndres Salomon <dilinger@collabora.co.uk>
Sun, 21 Feb 2010 23:25:06 +0000 (18:25 -0500)
committerAndres Salomon <dilinger@collabora.co.uk>
Sun, 21 Feb 2010 23:25:06 +0000 (18:25 -0500)
New script 'mkubifs.sh' for creating an image w/ a jffs2 /boot and an ubifs /.
It requires a new(er) kernel, possibly a newer initramfs-tools.. so for now,
it's not enabled.  Hopefully soon..

Signed-off-by: Andres Salomon <dilinger@collabora.co.uk>
13 files changed:
configs/debxo-awesome/fstab-ubifs [new file with mode: 0644]
configs/debxo-awesome/olpc.fth-ubifs [new file with mode: 0644]
configs/debxo-gnome/fstab-ubifs [new file with mode: 0644]
configs/debxo-gnome/olpc.fth-ubifs [new file with mode: 0644]
configs/debxo-kde/fstab-ubifs [new file with mode: 0644]
configs/debxo-kde/olpc.fth-ubifs [new file with mode: 0644]
configs/debxo-lxde/fstab-ubifs [new file with mode: 0644]
configs/debxo-lxde/olpc.fth-ubifs [new file with mode: 0644]
configs/debxo-sugar/fstab-ubifs [new file with mode: 0644]
configs/debxo-sugar/olpc.fth-ubifs [new file with mode: 0644]
configs/debxo-xfce/fstab-ubifs [new file with mode: 0644]
configs/debxo-xfce/olpc.fth-ubifs [new file with mode: 0644]
mkubifs.sh [new file with mode: 0755]

diff --git a/configs/debxo-awesome/fstab-ubifs b/configs/debxo-awesome/fstab-ubifs
new file mode 100644 (file)
index 0000000..ebce571
--- /dev/null
@@ -0,0 +1,8 @@
+# /etc/fstab: static file system information 
+#
+# <file system>        <mount point>   <type>  <options>       <dump>  <pass>
+proc           /proc           proc    defaults        0       0       # <partition size in MB>
+mtd:boot       /boot           jffs2   defaults,noatime 1      1       # 50
+ubi:root       /               ubifs   defaults,noatime 1      1
+none           /ofw            promfs  defaults        0       0
+tmpfs          /var/cache/apt/cache tmpfs defaults     0       0
diff --git a/configs/debxo-awesome/olpc.fth-ubifs b/configs/debxo-awesome/olpc.fth-ubifs
new file mode 100644 (file)
index 0000000..c70c010
--- /dev/null
@@ -0,0 +1,25 @@
+\ OLPC boot script
+
+\ fetch the /chosen/bootpath property
+" /chosen" find-package  if                       ( phandle )
+  " bootpath" rot  get-package-property  0=  if   ( propval$ )
+    get-encoded-string                            ( bootpath$ )
+    [char] \ left-parse-string  2nip              ( dn$ )
+
+    \ store the first part of bootpath (up to the '\') in $DN
+    dn-buf place                                  ( )
+  then
+then
+
+" ro ubi.mtd=root root=ubi:root rootfstype=ubifs video=lxfb fbcon=font:SUN12x22" to boot-file
+game-key-mask h# 80 and if
+       \ boot from backup kernel
+       " ${DN}\vmlinuz.old" expand$ to boot-device
+       " ${DN}\initrd.img.old" expand$ to ramdisk
+else
+       \ boot from regular kernel
+       " ${DN}\vmlinuz" expand$ to boot-device
+       " ${DN}\initrd.img" expand$ to ramdisk
+then
+dcon-unfreeze
+boot
diff --git a/configs/debxo-gnome/fstab-ubifs b/configs/debxo-gnome/fstab-ubifs
new file mode 100644 (file)
index 0000000..ebce571
--- /dev/null
@@ -0,0 +1,8 @@
+# /etc/fstab: static file system information 
+#
+# <file system>        <mount point>   <type>  <options>       <dump>  <pass>
+proc           /proc           proc    defaults        0       0       # <partition size in MB>
+mtd:boot       /boot           jffs2   defaults,noatime 1      1       # 50
+ubi:root       /               ubifs   defaults,noatime 1      1
+none           /ofw            promfs  defaults        0       0
+tmpfs          /var/cache/apt/cache tmpfs defaults     0       0
diff --git a/configs/debxo-gnome/olpc.fth-ubifs b/configs/debxo-gnome/olpc.fth-ubifs
new file mode 100644 (file)
index 0000000..c70c010
--- /dev/null
@@ -0,0 +1,25 @@
+\ OLPC boot script
+
+\ fetch the /chosen/bootpath property
+" /chosen" find-package  if                       ( phandle )
+  " bootpath" rot  get-package-property  0=  if   ( propval$ )
+    get-encoded-string                            ( bootpath$ )
+    [char] \ left-parse-string  2nip              ( dn$ )
+
+    \ store the first part of bootpath (up to the '\') in $DN
+    dn-buf place                                  ( )
+  then
+then
+
+" ro ubi.mtd=root root=ubi:root rootfstype=ubifs video=lxfb fbcon=font:SUN12x22" to boot-file
+game-key-mask h# 80 and if
+       \ boot from backup kernel
+       " ${DN}\vmlinuz.old" expand$ to boot-device
+       " ${DN}\initrd.img.old" expand$ to ramdisk
+else
+       \ boot from regular kernel
+       " ${DN}\vmlinuz" expand$ to boot-device
+       " ${DN}\initrd.img" expand$ to ramdisk
+then
+dcon-unfreeze
+boot
diff --git a/configs/debxo-kde/fstab-ubifs b/configs/debxo-kde/fstab-ubifs
new file mode 100644 (file)
index 0000000..ebce571
--- /dev/null
@@ -0,0 +1,8 @@
+# /etc/fstab: static file system information 
+#
+# <file system>        <mount point>   <type>  <options>       <dump>  <pass>
+proc           /proc           proc    defaults        0       0       # <partition size in MB>
+mtd:boot       /boot           jffs2   defaults,noatime 1      1       # 50
+ubi:root       /               ubifs   defaults,noatime 1      1
+none           /ofw            promfs  defaults        0       0
+tmpfs          /var/cache/apt/cache tmpfs defaults     0       0
diff --git a/configs/debxo-kde/olpc.fth-ubifs b/configs/debxo-kde/olpc.fth-ubifs
new file mode 100644 (file)
index 0000000..c70c010
--- /dev/null
@@ -0,0 +1,25 @@
+\ OLPC boot script
+
+\ fetch the /chosen/bootpath property
+" /chosen" find-package  if                       ( phandle )
+  " bootpath" rot  get-package-property  0=  if   ( propval$ )
+    get-encoded-string                            ( bootpath$ )
+    [char] \ left-parse-string  2nip              ( dn$ )
+
+    \ store the first part of bootpath (up to the '\') in $DN
+    dn-buf place                                  ( )
+  then
+then
+
+" ro ubi.mtd=root root=ubi:root rootfstype=ubifs video=lxfb fbcon=font:SUN12x22" to boot-file
+game-key-mask h# 80 and if
+       \ boot from backup kernel
+       " ${DN}\vmlinuz.old" expand$ to boot-device
+       " ${DN}\initrd.img.old" expand$ to ramdisk
+else
+       \ boot from regular kernel
+       " ${DN}\vmlinuz" expand$ to boot-device
+       " ${DN}\initrd.img" expand$ to ramdisk
+then
+dcon-unfreeze
+boot
diff --git a/configs/debxo-lxde/fstab-ubifs b/configs/debxo-lxde/fstab-ubifs
new file mode 100644 (file)
index 0000000..ebce571
--- /dev/null
@@ -0,0 +1,8 @@
+# /etc/fstab: static file system information 
+#
+# <file system>        <mount point>   <type>  <options>       <dump>  <pass>
+proc           /proc           proc    defaults        0       0       # <partition size in MB>
+mtd:boot       /boot           jffs2   defaults,noatime 1      1       # 50
+ubi:root       /               ubifs   defaults,noatime 1      1
+none           /ofw            promfs  defaults        0       0
+tmpfs          /var/cache/apt/cache tmpfs defaults     0       0
diff --git a/configs/debxo-lxde/olpc.fth-ubifs b/configs/debxo-lxde/olpc.fth-ubifs
new file mode 100644 (file)
index 0000000..c70c010
--- /dev/null
@@ -0,0 +1,25 @@
+\ OLPC boot script
+
+\ fetch the /chosen/bootpath property
+" /chosen" find-package  if                       ( phandle )
+  " bootpath" rot  get-package-property  0=  if   ( propval$ )
+    get-encoded-string                            ( bootpath$ )
+    [char] \ left-parse-string  2nip              ( dn$ )
+
+    \ store the first part of bootpath (up to the '\') in $DN
+    dn-buf place                                  ( )
+  then
+then
+
+" ro ubi.mtd=root root=ubi:root rootfstype=ubifs video=lxfb fbcon=font:SUN12x22" to boot-file
+game-key-mask h# 80 and if
+       \ boot from backup kernel
+       " ${DN}\vmlinuz.old" expand$ to boot-device
+       " ${DN}\initrd.img.old" expand$ to ramdisk
+else
+       \ boot from regular kernel
+       " ${DN}\vmlinuz" expand$ to boot-device
+       " ${DN}\initrd.img" expand$ to ramdisk
+then
+dcon-unfreeze
+boot
diff --git a/configs/debxo-sugar/fstab-ubifs b/configs/debxo-sugar/fstab-ubifs
new file mode 100644 (file)
index 0000000..ebce571
--- /dev/null
@@ -0,0 +1,8 @@
+# /etc/fstab: static file system information 
+#
+# <file system>        <mount point>   <type>  <options>       <dump>  <pass>
+proc           /proc           proc    defaults        0       0       # <partition size in MB>
+mtd:boot       /boot           jffs2   defaults,noatime 1      1       # 50
+ubi:root       /               ubifs   defaults,noatime 1      1
+none           /ofw            promfs  defaults        0       0
+tmpfs          /var/cache/apt/cache tmpfs defaults     0       0
diff --git a/configs/debxo-sugar/olpc.fth-ubifs b/configs/debxo-sugar/olpc.fth-ubifs
new file mode 100644 (file)
index 0000000..c70c010
--- /dev/null
@@ -0,0 +1,25 @@
+\ OLPC boot script
+
+\ fetch the /chosen/bootpath property
+" /chosen" find-package  if                       ( phandle )
+  " bootpath" rot  get-package-property  0=  if   ( propval$ )
+    get-encoded-string                            ( bootpath$ )
+    [char] \ left-parse-string  2nip              ( dn$ )
+
+    \ store the first part of bootpath (up to the '\') in $DN
+    dn-buf place                                  ( )
+  then
+then
+
+" ro ubi.mtd=root root=ubi:root rootfstype=ubifs video=lxfb fbcon=font:SUN12x22" to boot-file
+game-key-mask h# 80 and if
+       \ boot from backup kernel
+       " ${DN}\vmlinuz.old" expand$ to boot-device
+       " ${DN}\initrd.img.old" expand$ to ramdisk
+else
+       \ boot from regular kernel
+       " ${DN}\vmlinuz" expand$ to boot-device
+       " ${DN}\initrd.img" expand$ to ramdisk
+then
+dcon-unfreeze
+boot
diff --git a/configs/debxo-xfce/fstab-ubifs b/configs/debxo-xfce/fstab-ubifs
new file mode 100644 (file)
index 0000000..ebce571
--- /dev/null
@@ -0,0 +1,8 @@
+# /etc/fstab: static file system information 
+#
+# <file system>        <mount point>   <type>  <options>       <dump>  <pass>
+proc           /proc           proc    defaults        0       0       # <partition size in MB>
+mtd:boot       /boot           jffs2   defaults,noatime 1      1       # 50
+ubi:root       /               ubifs   defaults,noatime 1      1
+none           /ofw            promfs  defaults        0       0
+tmpfs          /var/cache/apt/cache tmpfs defaults     0       0
diff --git a/configs/debxo-xfce/olpc.fth-ubifs b/configs/debxo-xfce/olpc.fth-ubifs
new file mode 100644 (file)
index 0000000..c70c010
--- /dev/null
@@ -0,0 +1,25 @@
+\ OLPC boot script
+
+\ fetch the /chosen/bootpath property
+" /chosen" find-package  if                       ( phandle )
+  " bootpath" rot  get-package-property  0=  if   ( propval$ )
+    get-encoded-string                            ( bootpath$ )
+    [char] \ left-parse-string  2nip              ( dn$ )
+
+    \ store the first part of bootpath (up to the '\') in $DN
+    dn-buf place                                  ( )
+  then
+then
+
+" ro ubi.mtd=root root=ubi:root rootfstype=ubifs video=lxfb fbcon=font:SUN12x22" to boot-file
+game-key-mask h# 80 and if
+       \ boot from backup kernel
+       " ${DN}\vmlinuz.old" expand$ to boot-device
+       " ${DN}\initrd.img.old" expand$ to ramdisk
+else
+       \ boot from regular kernel
+       " ${DN}\vmlinuz" expand$ to boot-device
+       " ${DN}\initrd.img" expand$ to ramdisk
+then
+dcon-unfreeze
+boot
diff --git a/mkubifs.sh b/mkubifs.sh
new file mode 100755 (executable)
index 0000000..1dbbbba
--- /dev/null
@@ -0,0 +1,218 @@
+#!/bin/bash -e
+#
+# Copyright © 2008-2010  Andres Salomon <dilinger@debian.org>
+#
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+. ./functions.sh
+
+CONFIG_TYPE=generic
+
+usage()
+{
+       echo "" 1>&2
+       echo "Usage: $0 [<options>] <root directory> <img>" 1>&2
+       echo "" 1>&2
+       echo "Options:" 1>&2
+       echo "  --config-type <config>    directory name in configs/ to use" 1>&2
+       echo "  --help                    display this help screen" 1>&2
+       echo "" 1>&2
+       exit 1
+}
+
+while test $# != 0
+do
+       case $1 in
+       --config-type)
+               CONFIG_TYPE=$2
+               [ -d ./configs/${CONFIG_TYPE} ] || {
+                       echo "Error: can't find directory './configs/${CONFIG_TYPE}/'!" 1>&2
+                       exit 2
+               }
+               shift
+               ;;
+       --help|-h)
+               usage
+               ;;
+       *)
+               if [ "$#" != "2" ]; then
+                       echo "Unknown option $1" 1>&2
+                       usage
+               else
+                       ROOT_DIR=$1
+                       IMG_NAME=$2
+                       shift
+               fi
+               ;;
+       esac
+       shift
+done
+
+if [ "${IMG_NAME}" == "${IMG_NAME/.img/.dat}" ]; then
+       DAT_NAME=${IMG_NAME}.dat
+else
+       DAT_NAME=${IMG_NAME/.img/.dat}
+fi
+
+if [ ! -d "${ROOT_DIR}" ]; then
+       echo "" 1>&2
+       echo "*** Unable to find root directory!" 1>&2
+       usage
+fi
+
+check_for_cmds mkfs.jffs2 sumtool mkfs.ubifs ubinize || exit 1
+
+# create image's /etc/fstab
+if [ ! -f ./configs/${CONFIG_TYPE}/fstab-ubifs ]; then
+       echo "*** Unable to find fstab-ubifs!" 1>&2
+       exit 1
+fi
+sed 's/[[:space:]]#.*//' ./configs/${CONFIG_TYPE}/fstab-ubifs > ${ROOT_DIR}/etc/fstab
+
+# TODO: this needs to go into an OFW package; here it's a hack
+# create image's /boot/olpc.fth
+if [ -f ./configs/${CONFIG_TYPE}/olpc.fth-ubifs ]; then
+       cp ./configs/${CONFIG_TYPE}/olpc.fth-ubifs ${ROOT_DIR}/boot/olpc.fth
+fi
+
+create_ubifs()
+{
+       root_dir="$1"
+       out="$2"
+
+       cat >ubinize.cfg<<EOF
+# Section header
+[ubifs]
+# Volume mode (other option is static)
+mode=ubi
+# Source image
+image=${out}.pre
+# Volume ID in UBI image
+vol_id=0
+# Volume size
+vol_size=650000KiB
+# Allow for dynamic resize
+vol_type=dynamic
+# Volume name
+vol_name=root
+# Autoresize volume at first mount
+vol_flags=autoresize
+EOF
+
+       mkfs.ubifs -m 2048 -e 124KiB -c 8000 -r ${root_dir} -o ${out}.pre
+       ubinize -o ${out} -m 2048 -p 128KiB -s 2048 ubinize.cfg
+       rm -f ${out}.pre ubinize.cfg
+}
+
+create_jffs2()
+{
+       root_dir="$1"
+       out="$2"
+
+       mkfs.jffs2 -n -e128KiB -r ${root_dir} -o ${out}.pre
+       sumtool -n -p -e 128KiB -i ${out}.pre -o ${out}
+       rm -f ${out}.pre
+}
+
+partition_map()
+{
+       cat >${IMG_NAME}<<EOF
+data:  ${DAT_NAME}
+erase-all
+EOF
+
+       # partition size map
+       printf "partitions:" >> ${IMG_NAME}
+       sed -n -e 's/^mtd://p' -e 's/^ubi://p' configs/${CONFIG_TYPE}/fstab-ubifs | \
+                       while read name mntpt fstype extra; do
+               size=$(echo $extra | sed -ne 's/.*[[:space:]]\+#[[:space:]]\+//p')
+               if [ "${size}" = "" ]; then
+                       size="-1"
+               else
+                       # size in fstab is in MB; convert to 128KiB chunks (in hex)
+                       # MB * (1024/128)
+                       size=$((size * 8))
+                       size=`printf "%x\n" $size`
+               fi
+               printf "  $name $size" >> ${IMG_NAME}
+       done
+       printf "\n" >> ${IMG_NAME}
+
+       # individual partitions
+       sed -n -e 's/^mtd://p' -e 's/^ubi://p' configs/${CONFIG_TYPE}/fstab-ubifs | \
+                       while read name mntpt fstype extra; do
+               cat >>${IMG_NAME}<<EOF
+set-partition: ${name}
+mark-pending: 0
+EOF
+               # sha256 summing for data
+               eblocks=$((`stat --printf "%s\n" _${name}.img` / (128*1024)))
+               for b in $(seq 0 $(($eblocks - 1))); do
+                       sha=$(dd status=noxfer bs=128KiB skip=$b count=1 if=_${name}.img 2>/dev/null \
+                                       | sha256sum | cut -d\  -f1)
+                       echo "eblock: `printf '%x' $b` sha256 $sha" >> ${IMG_NAME}
+               done
+               cat >>${IMG_NAME}<<EOF
+cleanmarkers
+mark-complete: 0
+EOF
+       done
+}
+
+# move separate partitions out of the way
+sed -n -e 's/^mtd://p' -e 's/^ubi://p' configs/${CONFIG_TYPE}/fstab-ubifs | \
+               while read name mntpt fstype extra; do
+       if [ "$mntpt" = "/" ]; then
+               continue
+       fi
+
+       mv ${ROOT_DIR}/${mntpt} "_${name}"
+       mkdir ${ROOT_DIR}/${mntpt}
+done
+
+# create partitions
+sed -n -e 's/^mtd://p' -e 's/^ubi://p' configs/${CONFIG_TYPE}/fstab-ubifs | \
+               while read name mntpt fstype extra; do
+       if [ "$mntpt" = "/" ]; then
+               create_${fstype} ${ROOT_DIR} "_${name}.img"
+
+       else
+               create_${fstype} "_${name}" "_${name}.img"
+       fi
+done
+
+# move separate partitions back into the chroot
+sed -n -e 's/^mtd://p' -e 's/^ubi://p' configs/${CONFIG_TYPE}/fstab-ubifs | \
+               while read name mntpt fstype extra; do
+       if [ "$mntpt" = "/" ]; then
+               continue
+       fi
+
+       rmdir ${ROOT_DIR}/${mntpt}
+       mv "_${name}" ${ROOT_DIR}/${mntpt}
+done
+
+# partition map is used by OFW for partition layout and sha256 checksums
+partition_map
+
+# concat partitions, finish up
+rm -f ${DAT_NAME}
+sed -n -e 's/^mtd://p' -e 's/^ubi://p' configs/${CONFIG_TYPE}/fstab-ubifs | \
+               while read name mntpt fstype extra; do
+       cat "_${name}.img" >> ${DAT_NAME}
+       rm -f "_${name}.img"
+done
+
+exit 0