]> spindle.queued.net Git - xodist/blob - functions.sh
olpc.fth: auto-detect boot device during boot
[xodist] / functions.sh
1 #!/bin/sh -e
2 #
3 # Copyright © 2008  Andres Salomon <dilinger@queued.net>
4 #
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.
9 #
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.
14 #
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.
18
19 check_for_cmds()
20 {
21         for cmd in $@; do
22                 which $cmd >/dev/null || {
23                         echo "Missing required command '$cmd'!" 1>&2
24                         return 1
25                 }
26         done
27
28         return 0
29 }
30
31 # @mntpt - path to mounted root directory
32 # @fstype - the root filesystem type (in a form that 'mount' understands)
33 create_fstab()
34 {
35         mntpt="$1"
36         fstype="$2"
37
38         if [ "${fstype}" = "jffs2" ]; then
39                 r=mtd0
40         else
41                 r="LABEL=${IMG_LABEL}"
42         fi
43
44         cat >${mntpt}/etc/fstab<<EOF
45 ${r} / ${fstype} defaults,noatime 1 1
46 devpts /dev/pts devpts gid=5,mode=620 0 0
47 tmpfs /dev/shm tmpfs defaults,size=15% 0 0
48 proc /proc proc defaults 0 0
49 sysfs /sys sysfs defaults 0 0
50 none /ofw promfs defaults 0 0
51 tmpfs /var/cache/apt/cache tmpfs defaults 0 0
52 EOF
53 }
54
55 # @mntpt - path to mounted root directory
56 # @fstype - the root filesystem type (in a form that 'mount' understands)
57 create_ofwboot()
58 {
59         mntpt="$1"
60         fstype="$2"
61
62         if [ "${fstype}" = "jffs2" ]; then
63                 r=mtd0
64                 rfs="rootfstype=jffs2"
65         else
66                 r="LABEL=${IMG_LABEL}"
67                 rfs=""
68         fi
69
70         cat >${mntpt}/boot/olpc.fth<<EOF
71 \\ OLPC boot script
72
73 \\ fetch the /chosen/bootpath property
74 " /chosen" find-package  if                       ( phandle )
75   " bootpath" rot  get-package-property  0=  if   ( propval\$ )
76     get-encoded-string                            ( bootpath\$ )
77     [char] \ left-parse-string  2nip              ( dn\$ )
78
79     \ store the first part of bootpath (up to the '\\') in \$DN
80     dn-buf place                                  ( )
81   then
82 then
83
84 " ro root=${r} ${rfs} video=lxfb fbcon=font:SUN12x22" to boot-file
85 game-key-mask h# 80 and if
86         \\ boot from backup kernel
87         " \${DN}\\vmlinuz.old" expand\$ to boot-device
88         " \${DN}\\initrd.img.old" expand\$ to ramdisk
89 else
90         \\ boot from regular kernel
91         " \${DN}\\vmlinuz" expand\$ to boot-device
92         " \${DN}\\initrd.img" expand\$ to ramdisk
93 then
94 boot
95 EOF
96 }
97
98 chroot_internal_mounts()
99 {
100     root_dir="$1"
101     mount -t proc proc ${root_dir}/proc
102     mount -t devpts devpts ${root_dir}/dev/pts
103     mount -t tmpfs tmpfs ${root_dir}/var/cache/apt/cache
104 }
105
106 chroot_internal_umounts()
107 {
108     root_dir="$1"
109     umount ${root_dir}/proc
110     umount ${root_dir}/dev/pts
111     umount ${root_dir}/var/cache/apt/cache
112 }