summaryrefslogtreecommitdiffstats
path: root/mkrootfs-rasp-pi
blob: 460431e1e3fcd5d16a7375f308eab2793c219cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/sh

ARCH=armv5tel
SYSROOT=/opt/qtonpi/${ARCH}-qtonpi-linux-gnueabi/sys-root
ZYPP_CONF_NAME=etc-zypp-armv5fedora14-upstream.tgz
# set -x
function usage {
    echo "usage: sudo $0 ROOTFS_DIR RPM_LIST"
    exit
}

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root"
   usage
fi

if [ $# -ne 2 ] ; then
    usage
fi

if [ "$1" == "" ]; then
    echo "need a rootfs dir"
    usage
fi

# where we stage it
if [ -e $1 ] ; then
    echo "$1 already exists, try again"
    usage
fi

if [ ! -s "$2" ]; then
    echo "need a list of rpms to populate"
    usage
fi

F_RPMLIST=$2

function die {
    echo $1
    exit
}

mkdir -p $1/etc/
# force absolute path, could use readlink -m but not on mac :(
fsdir=`cd $1; pwd`

# set up our zypper
# just package it here
tar xf $ZYPP_CONF_NAME -C $fsdir/etc
export ZYPP_CONF=$fsdir/etc/zypp/zypp.conf

echo "using the following repos:"
ZYPP_CONF=$ZYPP_CONF zypper -R $fsdir lr
echo "refreshing the repos, this will take awhile (~ 5min)"
ZYPP_CONF=$ZYPP_CONF zypper -R $fsdir refresh

# prepare root fs
mkdir -p $fsdir/dev
mkdir -p $fsdir/dev/pts
mkdir -p $fsdir/dev/shm

mknod -m 0600 $fsdir/dev/console c 5 1
mknod $fsdir/dev/fb0 c 29 0
mknod $fsdir/dev/full c 1 7
mknod -m 0666 $fsdir/dev/null c 1 3
mknod $fsdir/dev/ptmx c 5 2
mknod $fsdir/dev/random c 1 8
mknod $fsdir/dev/urandom c 1 9
mknod -m 0666 $fsdir/dev/zero c 1 5

mknod $fsdir/dev/tty c 4 0
mknod $fsdir/dev/tty1 c 4 1
mknod $fsdir/dev/tty2 c 4 2

# vchiq dev
mknod $fsdir/dev/vchiq c 253 0


# and autofs for systemd
mknod $fsdir/dev/autofs c 10 235

mkdir -p $fsdir/var/lib
mkdir -p $fsdir/var/log

# we at least need a shell
# install packages
ZYPP_CONF=$ZYPP_CONF zypper -R $fsdir -n install upstart-sysvinit   || die "can't install what I can't find: upstart-sysvinit"
for i in `cat $F_RPMLIST| sed '/^ *#/d;s/#.*//' `; do
    echo "Working on $i"
    echo "calling     ZYPP_CONF=$ZYPP_CONF zypper -R $fsdir -n install   $i "
    ZYPP_CONF=$ZYPP_CONF zypper -R $fsdir -n install   $i || die "can't install what I can't find: $i"
done


# the Berkelydb datase is VERY sensitive to what tools were last used to access it.
# for the doodad to use rpm, we need to have rpm regenerate the __db.00* files
rm -f $fsdir/var/lib/rpm/__db.00*

# the standard yum repos don't work for us
# the good ones were insered via etc-raspi-various.tar.bz2
for i in fedora.repo  fedora-updates.repo  fedora-updates-testing.repo; do
    rm -f $fsdir/etc/yum.repos.d/$i
done
echo "arch=${ARCH}" >> $fsdir/etc/yum.conf

###
# finally we need a section of rc.local to check and make sure our
# desired services are enabled.  This is because the postinstall
# scriplets can't run when we do an x86 install of the
# armpackages. If you want more pkgs, add their rpm to the list and then
# add the chkconfig name to the list that goes into rc.local

# Currently enabling:
# network, ntpd, sshd
cat >>  $fsdir/etc/rc.d/rc.local  <<DELIM
# the fs is made on an x86 box so  the
# post install scriptlets to add these services
# didnt run
NEED_REBOOT=""
for i in network ntpd sshd messagebus; do
    Q=\`/sbin/chkconfig --list \$i\`
    if [ "\$Q" == "" ]; then
        echo "enabling \$i service"
        /sbin/chkconfig --add \$i
        /sbin/chkconfig \$i on
        NEED_REBOOT="yes"
    fi
done
if [ "\$NEED_REBOOT" != "" ]; then
    echo "reboot system to finish enabling the new services" > /etc/motd
    depmod -a
else
    rm /etc/motd
    touch /etc/motd
fi
# to install the binary only gles kernel module
/sbin/depmod -a
ldconfig
DELIM

# make sure we find the qt5 libs
cat >>  $fsdir/etc/ld.so.conf.d/qt5.conf  <<DELIM2
/opt/qt5/lib
DELIM2

# make sure we find the gles libs
cat >>  $fsdir/etc/ld.so.conf.d/gles.conf  <<DELIM3
/opt/vc/lib
DELIM3

# the current kernel brings up the usb device at random addresses.
# we'll remap them all to eth0
cat >>  $fsdir/etc/udev/rules.d/70-persistent-net.rules  <<DELIM4
# the current kernel brings up the usb device at random addresses.
# we'll remap them all to eth0
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# USB device 0x0424:0xec00 (usb)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:27:eb:*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

DELIM4

# lastly force in the extra stuff
# the etc files:
#  passwd for root is rootme
#  also the init.d scripts
echo "unpacking the etc files"
tar xf binaries/etc-raspi-various.tar.bz2 -C $fsdir || die "sad etcfiles"

# the kernel modules for the 2.6.35.7 kernel
echo "unpacking the kernel modules"
tar xf binaries/rasp-pi-kernel-3.1-modules.tar.bz2 -C $fsdir/lib/modules || die "sad kernel modules"

# and the binary only gles libraries
echo "unpacking the gles libs"
tar xf binaries/opt-vc-bcom-gles.tar.bz2  -C $fsdir || die "sad gles libs"

# and qt5
echo "unpacking qt5"
tar xf ../../app-sdk/opt-qt5-current.tar.bz2  -C $fsdir || die "sad qt5"

# clean up leftovers
rm -f $fsdir/etc/resolv.conf
touch $fsdir/etc/resolv.conf