Explorar el Código

Make a debian image

Based on freedom-maker with proprietary
stuff removed
Bob Mottram hace 9 años
padre
commit
0f91280e28

+ 7
- 0
Makefile Ver fichero

@@ -10,6 +10,8 @@ source:
10 10
 	gzip -f9n ../${APP}_${VERSION}.orig.tar
11 11
 install:
12 12
 	mkdir -p ${DESTDIR}${PREFIX}/bin
13
+	mkdir -p ${DESTDIR}/etc/freedombone
14
+	cp -r image_build/* ${DESTDIR}/etc/freedombone
13 15
 	install -m 755 src/${APP} ${DESTDIR}${PREFIX}/bin
14 16
 	install -m 755 src/zeronetavahi ${DESTDIR}${PREFIX}/bin
15 17
 	install -m 755 src/${APP}-keydrive ${DESTDIR}${PREFIX}/bin
@@ -45,6 +47,7 @@ install:
45 47
 	install -m 755 src/${APP}-rmsipuser ${DESTDIR}${PREFIX}/bin
46 48
 	install -m 755 src/${APP}-sipfreeext ${DESTDIR}${PREFIX}/bin
47 49
 	install -m 755 src/${APP}-format ${DESTDIR}${PREFIX}/bin
50
+	install -m 755 src/${APP}-image* ${DESTDIR}${PREFIX}/bin
48 51
 	mkdir -m 755 -p ${DESTDIR}${PREFIX}/share/man/man1
49 52
 	install -m 644 man/${APP}.1.gz ${DESTDIR}${PREFIX}/share/man/man1
50 53
 	install -m 644 man/${APP}-keydrive.1.gz ${DESTDIR}${PREFIX}/share/man/man1
@@ -75,6 +78,7 @@ install:
75 78
 	install -m 644 man/${APP}-addsipuser.1.gz ${DESTDIR}${PREFIX}/share/man/man1
76 79
 	install -m 644 man/${APP}-rmsipuser.1.gz ${DESTDIR}${PREFIX}/share/man/man1
77 80
 	install -m 644 man/${APP}-format.1.gz ${DESTDIR}${PREFIX}/share/man/man1
81
+	install -m 644 man/${APP}-image.1.gz ${DESTDIR}${PREFIX}/share/man/man1
78 82
 uninstall:
79 83
 	rm -f ${PREFIX}/share/man/man1/${APP}.1.gz
80 84
 	rm -f ${PREFIX}/share/man/man1/${APP}-keydrive.1.gz
@@ -105,6 +109,7 @@ uninstall:
105 109
 	rm -f ${PREFIX}/share/man/man1/${APP}-addsipuser.1.gz
106 110
 	rm -f ${PREFIX}/share/man/man1/${APP}-rmsipuser.1.gz
107 111
 	rm -f ${PREFIX}/share/man/man1/${APP}-format.1.gz
112
+	rm -f ${PREFIX}/share/man/man1/${APP}-image.1.gz
108 113
 	rm -rf ${PREFIX}/share/${APP}
109 114
 	rm -f ${PREFIX}/bin/${APP}
110 115
 	rm -f ${PREFIX}/bin/zeronetavahi
@@ -139,7 +144,9 @@ uninstall:
139 144
 	rm -f ${PREFIX}/bin/${APP}-rmsipuser
140 145
 	rm -f ${PREFIX}/bin/${APP}-sipfreeext
141 146
 	rm -f ${PREFIX}/bin/${APP}-format
147
+	rm -f ${PREFIX}/bin/${APP}-image*
142 148
 clean:
143 149
 	rm -f \#* \.#* debian/*.substvars debian/*.log
144 150
 	rm -fr deb.* debian/${APP}
145 151
 	rm -f ../${APP}*.deb ../${APP}*.changes ../${APP}*.asc ../${APP}*.dsc
152
+	rm -rf /etc/freedombone

+ 147
- 0
image_build/vendor-patches/vmdebootstrap/03-roottype-btrfs-bts-741223.patch Ver fichero

@@ -0,0 +1,147 @@
1
+diff --git a/vmdebootstrap b/vmdebootstrap
2
+index 4895147..c46be43 100755
3
+--- a/vmdebootstrap
4
++++ b/vmdebootstrap
5
+@@ -218,6 +218,25 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
6
+                     self.runcmd(['mkswap', swapdev])
7
+                 self.mkfs(rootdev, fstype=roottype)
8
+                 rootdir = self.mount(rootdev)
9
++                rootfsdir = rootdir
10
++                if 'btrfs' == roottype:
11
++                    # Put root in a subvolume, to ease snapshots and volume management
12
++                    self.message("Creating root file system as btrfs subvolume @")
13
++                    self.runcmd(['btrfs', 'subvolume', 'create', "%s/@" % rootdir])
14
++
15
++                    # Make sure the subvolume mount point show in in
16
++                    # /proc/mounts for grub-update to figure out the
17
++                    # device for the root file system.
18
++                    newrootdir = "%s/build" % rootdir
19
++                    os.mkdir(newrootdir)
20
++                    self.mount(rootdev, newrootdir, ['-o','subvol=@'])
21
++#                    self.runcmd(['btrfs', 'subvolume', 'set-default', '@', rootdir])
22
++
23
++                    # Make the btrfs root file system available in the chroot.
24
++                    os.mkdir("%s/btrfs" % newrootdir)
25
++                    self.mount(rootdev, "%s/btrfs" % newrootdir)
26
++
27
++                    rootdir = newrootdir
28
+                 if bootdev:
29
+                     if self.settings['boottype']:
30
+                         boottype = self.settings['boottype']
31
+@@ -245,9 +264,9 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
32
+ 
33
+             if self.settings['image']:
34
+                 if self.settings['grub']:
35
+-                    self.install_grub2(rootdev, rootdir)
36
++                    self.install_grub2(rootdev, rootdir, rootfsdir)
37
+                 elif self.settings['extlinux']:
38
+-                    self.install_extlinux(rootdev, rootdir)
39
++                    self.install_extlinux(rootdev, rootdir, rootfsdir)
40
+                 self.append_serial_console(rootdir)
41
+                 self.optimize_image(rootdir)
42
+                 if self.settings['squash']:
43
+@@ -300,13 +319,19 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
44
+         logging.debug('mkdir %s', dirname)
45
+         return dirname
46
+ 
47
+-    def mount(self, device, path=None):
48
++    def mount(self, device, path=None, opts=None):
49
+         if not path:
50
+             mount_point = self.mkdtemp()
51
+         else:
52
+             mount_point = path
53
+         self.message('Mounting %s on %s' % (device, mount_point))
54
+-        self.runcmd(['mount', device, mount_point])
55
++        cmd = ['mount']
56
++        if opts is not None:
57
++            for opt in opts:
58
++                cmd.append(opt)
59
++        cmd.append(device)
60
++        cmd.append(mount_point)
61
++        self.runcmd(cmd)
62
+         self.mount_points.append(mount_point)
63
+         logging.debug('mounted %s on %s', device, mount_point)
64
+         return mount_point
65
+@@ -458,6 +483,9 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
66
+         if self.settings['grub']:
67
+             include.append('grub-pc')
68
+ 
69
++        if 'btrfs' == self.settings['roottype']:
70
++            include.append('btrfs-tools')
71
++
72
+         if not self.settings['no-kernel']:
73
+             if self.settings['kernel-package']:
74
+                 kernel_image = self.settings['kernel-package']
75
+@@ -546,7 +574,12 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
76
+         fstab = os.path.join(rootdir, 'etc', 'fstab')
77
+         with open(fstab, 'w') as f:
78
+             f.write('proc /proc proc defaults 0 0\n')
79
+-            f.write('%s / %s errors=remount-ro 0 1\n' % (rootdevstr, roottype))
80
++            if 'btrfs' == roottype:
81
++#                f.write('%s / %s defaults 0 1\n' % (rootdevstr, roottype))
82
++                f.write('%s / %s subvol=@ 0 1\n' % (rootdevstr, roottype))
83
++                f.write('%s /btrfs %s defaults 1\n' % (rootdevstr, roottype))
84
++            else:
85
++                f.write('%s / %s errors=remount-ro 0 1\n' % (rootdevstr, roottype))
86
+             if bootdevstr:
87
+                 f.write('%s /boot %s errors=remount-ro 0 2\n' % (bootdevstr, boottype))
88
+                 if self.settings['swap'] > 0:
89
+@@ -661,7 +694,8 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
90
+             cfg.write("%s\n" % terminal)
91
+             cfg.write("%s\n" % command)
92
+ 
93
+-    def install_grub2(self, rootdev, rootdir):
94
++    def install_grub2(self, rootdev, rootdir, rootfsdir):
95
++        # FIXME use rootfsdir
96
+         self.message("Configuring grub2")
97
+         # rely on kpartx using consistent naming to map loop0p1 to loop0
98
+         install_dev = os.path.join('/dev', os.path.basename(rootdev)[:-2])
99
+@@ -679,12 +713,12 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
100
+             self.runcmd(['chroot', rootdir, 'grub-install', install_dev])
101
+         except cliapp.AppException:
102
+             self.message("Failed. Is grub2-common installed? Using extlinux.")
103
+-            self.install_extlinux(rootdev, rootdir)
104
++            self.install_extlinux(rootdev, rootdir, rootfsdir)
105
+         self.runcmd(['umount', os.path.join(rootdir, 'sys')])
106
+         self.runcmd(['umount', os.path.join(rootdir, 'proc')])
107
+         self.runcmd(['umount', os.path.join(rootdir, 'dev')])
108
+ 
109
+-    def install_extlinux(self, rootdev, rootdir):
110
++    def install_extlinux(self, rootdev, rootdir, rootfsdir):
111
+         if not os.path.exists("/usr/bin/extlinux"):
112
+             self.message("extlinux not installed, skipping.")
113
+             return
114
+@@ -711,7 +745,7 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
115
+                            '-s', 'UUID', rootdev])
116
+         uuid = out.splitlines()[0].strip()
117
+ 
118
+-        conf = os.path.join(rootdir, 'extlinux.conf')
119
++        conf = os.path.join(rootfsdir, 'extlinux.conf')
120
+         logging.debug('configure extlinux %s', conf)
121
+         kserial = 'console=ttyS0,115200' if self.settings['serial-console'] else ''
122
+         extserial = 'serial 0 115200' if self.settings['serial-console'] else ''
123
+@@ -721,13 +755,14 @@ timeout 1
124
+ 
125
+ label linux
126
+ kernel %(kernel)s
127
+-append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
128
++append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s %(rootflags)s
129
+ %(extserial)s
130
+ ''' % {
131
+             'kernel': kernel_image,  # pylint: disable=bad-continuation
132
+             'initrd': initrd_image,  # pylint: disable=bad-continuation
133
+             'uuid': uuid,  # pylint: disable=bad-continuation
134
+             'kserial': kserial,  # pylint: disable=bad-continuation
135
++            'rootflags': 'rootfsflags=subvol=@' if 'btrfs' == self.settings['roottype'] else '',  # pylint: disable=bad-continuation
136
+             'extserial': extserial,  # pylint: disable=bad-continuation
137
+         }  # pylint: disable=bad-continuation
138
+         logging.debug("extlinux config:\n%s", msg)
139
+@@ -738,7 +773,7 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
140
+         f = open(conf, 'w')
141
+         f.write(msg)
142
+ 
143
+-        self.runcmd(['extlinux', '--install', rootdir])
144
++        self.runcmd(['extlinux', '--install', rootfsdir])
145
+         self.runcmd(['sync'])
146
+         time.sleep(2)
147
+ 

+ 1
- 0
image_build/vendor/vmdebootstrap

@@ -0,0 +1 @@
1
+Subproject commit 390e883698f85e34433ef79aeabfde77c06b1c22

BIN
man/freedombone-image.1.gz Ver fichero


+ 72
- 0
src/freedombone-image Ver fichero

@@ -0,0 +1,72 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Creates a debian image using vmdebootstrap
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+# GNU General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU General Public License
29
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+
31
+IMAGE_TYPE=$1
32
+CURR_DIR=$(pwd)
33
+BUILD_DIR=~/.tmp_freedombone_build
34
+
35
+rm $CURR_DIR/*.img
36
+
37
+if [ -d $BUILD_DIR ]; then
38
+	rm -rf $BUILD_DIR
39
+fi
40
+mkdir -p $BUILD_DIR
41
+if [ -f /usr/local/bin/freedombone-image-makefile ]; then
42
+	cp /usr/local/bin/freedombone-image-makefile $BUILD_DIR/Makefile
43
+else
44
+	cp /usr/bin/freedombone-image-makefile $BUILD_DIR/Makefile
45
+fi
46
+
47
+cp -r /etc/freedombone/* $BUILD_DIR
48
+cd $BUILD_DIR
49
+
50
+rm -rf vendor
51
+mkdir vendor
52
+if [ -d vendor/vmdebootstrap ] ; then
53
+    (cd vendor/vmdebootstrap; git checkout .; git pull)
54
+else
55
+    git clone git://git.liw.fi/vmdebootstrap vendor/vmdebootstrap
56
+fi
57
+cd vendor/vmdebootstrap
58
+git checkout tags/vmdebootstrap-0.8
59
+git checkout -b tags/vmdebootstrap-0.8
60
+for f in ../../vendor-patches/vmdebootstrap/* ; do
61
+    echo applying $(basename $f)
62
+    patch -p1 < $f
63
+done
64
+
65
+cd $BUILD_DIR
66
+make $IMAGE_TYPE
67
+mv build/*.bz2 $CURR_DIR
68
+mv build/*.img $CURR_DIR
69
+mv build/*.sig $CURR_DIR
70
+rm -rf $BUILD_DIR
71
+
72
+exit 0

+ 158
- 0
src/freedombone-image-customise Ver fichero

@@ -0,0 +1,158 @@
1
+#!/bin/sh
2
+#
3
+# Based on bin/freedombox-customize from freedom-maker
4
+#
5
+# This program is free software: you can redistribute it and/or modify
6
+# it under the terms of the GNU General Public License as published by
7
+# the Free Software Foundation, either version 3 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,
11
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+# GNU 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, see <http://www.gnu.org/licenses/>.
17
+
18
+set -e
19
+set -x
20
+
21
+enable_eatmydata_override() {
22
+    chroot $rootdir apt-get install --no-install-recommends -y eatmydata
23
+    if [ -x $rootdir/usr/bin/eatmydata ] && \
24
+        [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
25
+        echo "info: Adding apt config to call dpkg via eatmydata"
26
+        printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
27
+            > $rootdir/var/tmp/dpkg-eatmydata
28
+        chmod 755 $rootdir/var/tmp/dpkg-eatmydata
29
+        cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
30
+Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
31
+EOF
32
+    else
33
+        echo "error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
34
+    fi
35
+}
36
+
37
+disable_eatmydata_override() {
38
+    for override in \
39
+        /etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
40
+        /var/tmp/dpkg-eatmydata ; do
41
+        echo "info: Removing apt config to call dpkg via eatmydata"
42
+        if [ -f $rootdir$override ] ; then
43
+            rm -f $rootdir$override
44
+        else
45
+            echo "warning: missing $rootdir$override"
46
+        fi
47
+    done
48
+    sync # Flush file buffers before continuing
49
+}
50
+
51
+set_apt_sources() {
52
+    NEW_MIRROR="$1"
53
+    COMPONENTS="main"
54
+
55
+    cat <<EOF > etc/apt/sources.list
56
+deb $NEW_MIRROR $SUITE $COMPONENTS
57
+deb-src $NEW_MIRROR $SUITE $COMPONENTS
58
+
59
+#deb http://security.debian.org/ $SUITE/updates main
60
+#deb-src http://security.debian.org/ $SUITE/updates main
61
+EOF
62
+}
63
+
64
+# Set to true/false to control if eatmydata is used during build
65
+use_eatmydata=true
66
+
67
+rootdir="$1"
68
+fmdir="$(pwd)"
69
+image="$fmdir"/"$2"
70
+cd "$rootdir"
71
+
72
+echo info: building $MACHINE for $ARCHITECTURE
73
+
74
+export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
75
+export LC_ALL=C LANGUAGE=C LANG=C
76
+
77
+# Override libpam-tmpdir setting during build, as the directories
78
+# are not created yet.
79
+export TMP=/tmp/ TMPDIR=/tmp/
80
+
81
+username=freedom
82
+echo "warning: creating initial user $username with well known password!"
83
+password=bone
84
+chroot $rootdir adduser --gecos $username --disabled-password $username
85
+echo $username:$password | chroot $rootdir /usr/sbin/chpasswd
86
+chroot $rootdir adduser $username sudo
87
+
88
+case "$MACHINE" in
89
+    virtualbox)
90
+        # hide irrelevant console keyboard messages.
91
+        echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
92
+            >> /etc/init.d/rc.local
93
+        ;;
94
+esac
95
+
96
+set_apt_sources $BUILD_MIRROR
97
+chroot $rootdir apt-get update
98
+
99
+cat > $rootdir/usr/sbin/policy-rc.d <<EOF
100
+#!/bin/sh
101
+exit 101
102
+EOF
103
+chmod a+rx $rootdir/usr/sbin/policy-rc.d
104
+
105
+if $use_eatmydata ; then
106
+    enable_eatmydata_override
107
+fi
108
+
109
+if [ -n "$CUSTOM_SETUP" ]; then
110
+    cp "$CUSTOM_SETUP" "$rootdir"/tmp
111
+    chroot "$rootdir" apt-get install -y gdebi-core
112
+    chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
113
+fi
114
+
115
+chroot "$rootdir" apt-get install -y git dialog
116
+chroot "$rootdir" git clone https://github.com/bashrc/freedombone /root/freedombone
117
+chroot "$rootdir" cd /root/freedombone && make install
118
+
119
+chroot $rootdir freedombone-image-hardware-setup 2>&1 | \
120
+    tee $rootdir/var/log/freedombone-image-hardware-setup.log
121
+
122
+rm $rootdir/usr/sbin/policy-rc.d
123
+
124
+chroot $rootdir /usr/lib/freedombone/setup 2>&1 | \
125
+    tee $rootdir/var/log/freedombone-setup.log
126
+
127
+# Remove SSH keys from the image
128
+rm $rootdir/etc/ssh/ssh_host_* || true
129
+
130
+# copy u-boot to beginning of image
131
+case "$MACHINE" in
132
+    beaglebone)
133
+    chroot $rootdir apt-get -y install rng-tools
134
+    sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
135
+
136
+	dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
137
+	   count=1 seek=1 conv=notrunc bs=128k
138
+	dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
139
+	   count=2 seek=1 conv=notrunc bs=384k
140
+	;;
141
+    cubieboard2)
142
+        dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
143
+           seek=8 conv=notrunc bs=1k
144
+        ;;
145
+esac
146
+
147
+if $use_eatmydata ; then
148
+    disable_eatmydata_override
149
+fi
150
+
151
+set_apt_sources $MIRROR
152
+chroot $rootdir apt-get update
153
+
154
+cd /
155
+echo "info: killing leftover processes in chroot"
156
+# 2014-11-04 this killed /usr/lib/erlang/erts-6.2/bin/epmd, see
157
+# <URL: https://www.ejabberd.im/epmd?q=epmd > to learn more.
158
+fuser -mvk $rootdir/. || true

+ 170
- 0
src/freedombone-image-hardware-setup Ver fichero

@@ -0,0 +1,170 @@
1
+#!/bin/sh
2
+
3
+enable_serial_console() {
4
+    # By default, spawn a console on the serial port
5
+    device="$1"
6
+    echo "Adding a getty on the serial port"
7
+    echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
8
+}
9
+
10
+beaglebone_setup_boot() {
11
+    # Setup uEnv.txt
12
+    if grep -q btrfs /etc/fstab ; then
13
+        fstype=btrfs
14
+    else
15
+        fstype=ext4
16
+    fi
17
+    kernelVersion=$(ls /usr/lib/*/am335x-boneblack.dtb | head -1 | cut -d/ -f4)
18
+    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
19
+    initRd=initrd.img-$version
20
+    vmlinuz=vmlinuz-$version
21
+
22
+    # uEnv.txt for Beaglebone
23
+    # based on https://github.com/beagleboard/image-builder/blob/master/target/boot/beagleboard.org.txt
24
+    cat >> /boot/uEnv.txt <<EOF
25
+mmcroot=/dev/mmcblk0p2 ro
26
+mmcrootfstype=$fstype rootwait fixrtc
27
+mmcrootflags=subvol=@
28
+
29
+console=ttyO0,115200n8
30
+
31
+kernel_file=$vmlinuz
32
+initrd_file=$initRd
33
+
34
+loadaddr=0x80200000
35
+initrd_addr=0x81000000
36
+fdtaddr=0x80F80000
37
+
38
+initrd_high=0xffffffff
39
+fdt_high=0xffffffff
40
+
41
+loadkernel=load mmc \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
42
+loadinitrd=load mmc \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}; setenv initrd_size \${filesize}
43
+loadfdt=load mmc \${mmcdev}:\${mmcpart} \${fdtaddr} /dtbs/\${fdtfile}
44
+
45
+loadfiles=run loadkernel; run loadinitrd; run loadfdt
46
+mmcargs=setenv bootargs console=tty0 console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype} rootflags=\${mmcrootflags}
47
+
48
+uenvcmd=run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
49
+EOF
50
+
51
+    mkdir -p /boot/dtbs
52
+    cp /usr/lib/linux-image-*-armmp/* /boot/dtbs
53
+}
54
+
55
+beaglebone_flash() {
56
+    # allow flash-kernel to work without valid /proc contents
57
+    # ** this doesn't *really* work, since there are too many checks
58
+    #    that fail in an emulated environment!  We'll have to do it by
59
+    #    hand below anyway...
60
+    export FK_MACHINE="TI AM335x BeagleBone"
61
+    apt-get install -y flash-kernel
62
+}
63
+
64
+beaglebone_repack_kernel() {
65
+# process installed kernel to create uImage, uInitrd, dtb
66
+# using flash-kernel would be a good approach, except it fails in the
67
+# cross build environment due to too many environment checks...
68
+#FK_MACHINE="TI AM335x BeagleBone" flash-kernel
69
+#  so, let's do it manually...
70
+
71
+# flash-kernel's hook-functions provided to mkinitramfs have the
72
+# unfortunate side-effect of creating /conf/param.conf in the initrd
73
+# when run from our emulated chroot environment, which means our root=
74
+# on the kernel command line is completely ignored!  repack the initrd
75
+# to remove this evil...
76
+
77
+    echo "info: repacking beaglebone kernel and initrd"
78
+
79
+    kernelVersion=$(ls /usr/lib/*/am335x-boneblack.dtb | head -1 | cut -d/ -f4)
80
+    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
81
+    initRd=initrd.img-$version
82
+    vmlinuz=vmlinuz-$version
83
+
84
+    mkdir /tmp/initrd-repack
85
+
86
+    (cd /tmp/initrd-repack ; \
87
+    zcat /boot/$initRd | cpio -i ; \
88
+    rm -f conf/param.conf ; \
89
+    find . | cpio --quiet -o -H newc | \
90
+    gzip -9 > /boot/$initRd )
91
+
92
+    rm -rf /tmp/initrd-repack
93
+
94
+    (cd /boot ; \
95
+    cp /usr/lib/$kernelVersion/am335x-boneblack.dtb dtb ; \
96
+    cat $vmlinuz dtb >> temp-kernel ; \
97
+    mkimage -A arm -O linux -T kernel -n "Debian kernel ${version}" \
98
+    -C none -a 0x80200000 -e 0x80200000 -d temp-kernel uImage ; \
99
+    rm -f temp-kernel ; \
100
+    mkimage -A arm -O linux -T ramdisk -C gzip -a 0x81000000 -e 0x81000000 \
101
+    -n "Debian ramdisk ${version}" \
102
+    -d $initRd uInitrd )
103
+}
104
+
105
+cubieboard2_setup_boot() {
106
+    # Setup boot.cmd
107
+    if grep -q btrfs /etc/fstab ; then
108
+        fstype=btrfs
109
+    else
110
+        fstype=ext4
111
+    fi
112
+    kernelVersion=$(ls /usr/lib/*/sun7i-a20-cubieboard2.dtb | head -1 | cut -d/ -f4)
113
+    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
114
+    initRd=initrd.img-$version
115
+    vmlinuz=vmlinuz-$version
116
+
117
+    # boot.cmd for CubieTruck
118
+    cat >> /boot/boot.cmd <<EOF
119
+setenv mmcdev 0
120
+setenv mmcpart 1
121
+
122
+setenv mmcroot /dev/mmcblk0p2 ro
123
+setenv mmcrootfstype $fstype rootwait fixrtc
124
+setenv mmcrootflags subvol=@
125
+
126
+setenv console ttyS0,115200n8
127
+
128
+setenv kernel_file $vmlinuz
129
+setenv initrd_file $initRd
130
+
131
+setenv loadaddr 0x46000000
132
+setenv initrd_addr 0x48000000
133
+setenv fdtaddr 0x47000000
134
+
135
+setenv initrd_high 0xffffffff
136
+setenv fdt_high 0xffffffff
137
+
138
+setenv loadkernel load mmc \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
139
+setenv loadinitrd load mmc \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}\\; setenv initrd_size \\\${filesize}
140
+setenv loadfdt load mmc \${mmcdev}:\${mmcpart} \${fdtaddr} /dtbs/\${fdtfile}
141
+
142
+setenv loadfiles run loadkernel\\; run loadinitrd\\; run loadfdt
143
+setenv mmcargs setenv bootargs console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype} rootflags=\${mmcrootflags}
144
+
145
+run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
146
+EOF
147
+
148
+    # boot.scr for CubieTruck
149
+    mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
150
+
151
+    # DTBs for CubieTruck
152
+    mkdir -p /boot/dtbs
153
+    cp /usr/lib/$kernelVersion/* /boot/dtbs
154
+
155
+    # extra boot modules
156
+    echo "rtc_sunxi" >> /etc/initramfs-tools/modules
157
+}
158
+
159
+case "$MACHINE" in
160
+    beaglebone)
161
+    beaglebone_setup_boot
162
+    beaglebone_flash
163
+    beaglebone_repack_kernel
164
+    enable_serial_console ttyO0
165
+    ;;
166
+    cubieboard2)
167
+    cubieboard2_setup_boot
168
+    enable_serial_console ttyS0
169
+    ;;
170
+esac

+ 129
- 0
src/freedombone-image-make Ver fichero

@@ -0,0 +1,129 @@
1
+#!/bin/sh
2
+#
3
+# Based upon bin/mk-freedombox-image from freedom-maker
4
+# With non-free stuff removed
5
+#
6
+# This program is free software: you can redistribute it and/or modify
7
+# it under the terms of the GNU General Public License as published by
8
+# the Free Software Foundation, either version 3 of the License, or
9
+# (at your option) any later version.
10
+#
11
+# This program is distributed in the hope that it will be useful,
12
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+# GNU General Public License for more details.
15
+#
16
+# You should have received a copy of the GNU General Public License
17
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
+
19
+set -e # Exit on first error
20
+
21
+#set -x # Enable debugging
22
+
23
+IMAGE=$1
24
+export ARCHITECTURE
25
+export MACHINE
26
+export SOURCE
27
+export SUITE
28
+
29
+# Locate vmdebootstrap program fetched in Makefile
30
+basedir=`pwd`
31
+vendor_dir="${basedir}/vendor"
32
+vmdebootstrap_dir="${vendor_dir}/vmdebootstrap"
33
+
34
+if [ -z "$MIRROR" ] || [ -z "$SUITE" ] ; then
35
+    echo error: Missing MIRROR and SUITE settings inherited from Makefile.
36
+    exit 1
37
+fi
38
+
39
+# Packages to install in all Freedombone environments
40
+base_pkgs="apt base-files ifupdown initramfs-tools \
41
+logrotate module-init-tools netbase rsyslog udev debian-archive-keyring"
42
+
43
+# Packages needed on the beaglebone
44
+beaglebone_pkgs="linux-image-armmp u-boot-tools u-boot"
45
+
46
+# Packages needed for self-hosted development
47
+dev_pkgs="build-essential devscripts make man-db emacs org-mode git mercurial"
48
+
49
+# Packages needed for XFCE desktop environment
50
+xfce_pkgs="task-xfce-desktop iceweasel ca-certificates"
51
+
52
+echo Building $MACHINE Freedombone for $ARCHITECTURE.
53
+
54
+case "$MACHINE" in
55
+    beaglebone)
56
+	extra_pkgs="$beaglebone_pkgs"
57
+	extra_opts="\
58
+ --variant minbase \
59
+ --bootoffset=2mib \
60
+ --bootsize 128M \
61
+ --boottype ext2 \
62
+ --no-kernel \
63
+ --no-extlinux \
64
+ --foreign /usr/bin/qemu-arm-static \
65
+ --roottype btrfs \
66
+"
67
+	;;
68
+    virtualbox)
69
+	extra_opts="\
70
+ --grub \
71
+ --roottype btrfs \
72
+"	;;
73
+    all)
74
+	extra_opts="\
75
+ --grub \
76
+ --roottype btrfs \
77
+"	;;
78
+esac
79
+
80
+# allow for lots of extra fun customization options.
81
+for customization in $CUSTOMIZATIONS
82
+do
83
+    case "$customization" in
84
+        development)
85
+            extra_pkgs="$extra_pkgs $dev_pkgs"
86
+            ;;
87
+	xfce)
88
+	    extra_pkgs="$extra_pkgs $xfce_pkgs"
89
+	    ;;
90
+    esac
91
+done
92
+
93
+for p in $base_pkgs $extra_pkgs; do
94
+    pkgopts="$pkgopts --package $p"
95
+done
96
+
97
+# Make sure file is owned by current user, not root
98
+touch $(dirname $IMAGE)/freedombone.log
99
+
100
+if [ -x vendor/vmdebootstrap/vmdebootstrap ] ; then
101
+    VMDEBOOTSTRAP=vendor/vmdebootstrap/vmdebootstrap
102
+else
103
+    VMDEBOOTSTRAP=vmdebootstrap
104
+fi
105
+
106
+echo "starting $VMDEBOOTSTRAP"
107
+# Run vmdebootstrap script to create image
108
+sudo -H \
109
+    SUITE="$SUITE" \
110
+    MIRROR="$MIRROR" \
111
+    BUILD_MIRROR="$BUILD_MIRROR"\
112
+    MACHINE="$MACHINE" \
113
+    ARCHITECTURE="$ARCHITECTURE" \
114
+    SOURCE="$SOURCE" \
115
+    CUSTOM_SETUP="$CUSTOM_SETUP" \
116
+    $VMDEBOOTSTRAP \
117
+    --log $(dirname $IMAGE)/freedombone.log \
118
+    --log-level debug \
119
+    --size $IMAGE_SIZE \
120
+    --image $IMAGE.img \
121
+    --hostname freedombone \
122
+    --verbose \
123
+    --mirror $BUILD_MIRROR \
124
+    --customize "freedombone-image-customise" \
125
+    --lock-root-password \
126
+    --arch $ARCHITECTURE \
127
+    --distribution $SUITE \
128
+    $extra_opts \
129
+    $pkgopts

+ 147
- 0
src/freedombone-image-makefile Ver fichero

@@ -0,0 +1,147 @@
1
+#!/usr/bin/make
2
+#
3
+# A debian image builder, based upon freedom-maker
4
+#
5
+# This program is free software: you can redistribute it and/or modify
6
+# it under the terms of the GNU General Public License as published by
7
+# the Free Software Foundation, either version 3 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,
11
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+# GNU 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, see <http://www.gnu.org/licenses/>.
17
+
18
+# Where to fetch packages
19
+MIRROR ?= http://httpredir.debian.org/debian
20
+BUILD_MIRROR ?= http://httpredir.debian.org/debian
21
+IMAGE_SIZE ?= 8G
22
+SUITE ?= jessie
23
+# include source packages in image?
24
+SOURCE ?= false
25
+
26
+# yes no
27
+BUILD = $(MACHINE)-$(ARCHITECTURE)
28
+TODAY := $(shell date +%Y-%m-%d)
29
+NAME = build/freedombone-$(TODAY)_$(BUILD)
30
+IMAGE = $(NAME).img
31
+ARCHIVE = $(NAME).tar.bz2
32
+SIGNATURE = $(ARCHIVE).sig
33
+OWNER = 1000
34
+TAR = tar --checkpoint=1000 --checkpoint-action=dot -cjvf
35
+SIGN = -gpg --output $(SIGNATURE) --detach-sig $(ARCHIVE)
36
+
37
+# settings for `make test`
38
+TEST_SSH_PORT = 2222
39
+TEST_FIRSTRUN_WAIT_TIME = 120 # seconds
40
+
41
+# Using taskset to pin build process to single core. This is a
42
+# workaround for a qemu-user-static issue that causes builds to
43
+# hang. (See Debian bug #769983 for details.)
44
+MAKE_IMAGE = ARCHITECTURE=$(ARCHITECTURE) MACHINE=$(MACHINE) SOURCE=$(SOURCE) \
45
+    MIRROR=$(MIRROR) SUITE=$(SUITE) OWNER=$(OWNER) \
46
+    BUILD_MIRROR=$(BUILD_MIRROR) \
47
+    CUSTOM_PLINTH=$(CUSTOM_PLINTH) CUSTOM_SETUP=$(CUSTOM_SETUP) \
48
+    IMAGE_SIZE=$(IMAGE_SIZE) taskset 0x01 freedombone-image-make $(NAME)
49
+
50
+# build Beaglebone SD card image
51
+beaglebone: prep
52
+	$(eval ARCHITECTURE = armhf)
53
+	$(eval MACHINE = beaglebone)
54
+	$(MAKE_IMAGE)
55
+	$(TAR) $(ARCHIVE) $(IMAGE)
56
+	@echo ""
57
+	$(SIGN)
58
+	@echo "Build complete."
59
+
60
+# build Cubieboard2 SD card image
61
+cubieboard2: prep
62
+	$(eval ARCHITECTURE = armhf)
63
+	$(eval MACHINE = cubieboard2)
64
+	$(MAKE_IMAGE)
65
+	$(TAR) $(ARCHIVE) $(IMAGE)
66
+	@echo ""
67
+	$(SIGN)
68
+	@echo "Build complete."
69
+
70
+# build an i386 image
71
+i386: prep
72
+	$(eval ARCHITECTURE = i386)
73
+	$(eval MACHINE = all)
74
+	$(MAKE_IMAGE)
75
+	$(TAR) $(ARCHIVE) $(IMAGE)
76
+	@echo ""
77
+	$(SIGN)
78
+	@echo "Build complete."
79
+
80
+# build an amd64 image
81
+amd64: prep
82
+	$(eval ARCHITECTURE = amd64)
83
+	$(eval MACHINE = all)
84
+	$(MAKE_IMAGE)
85
+	$(TAR) $(ARCHIVE) $(IMAGE)
86
+	@echo ""
87
+	$(SIGN)
88
+	@echo "Build complete."
89
+
90
+# build a virtualbox image
91
+virtualbox: virtualbox-i386
92
+
93
+virtualbox-i386: prep
94
+	$(eval ARCHITECTURE = i386)
95
+	$(eval MACHINE = virtualbox)
96
+	$(MAKE_IMAGE)
97
+	# Convert image to vdi hard drive
98
+	VBoxManage convertdd $(NAME).img $(NAME).vdi
99
+	$(TAR) $(ARCHIVE) $(NAME).vdi
100
+	@echo ""
101
+	$(SIGN)
102
+	@echo "Build complete."
103
+
104
+virtualbox-amd64: prep
105
+	$(eval ARCHITECTURE = amd64)
106
+	$(eval MACHINE = virtualbox)
107
+	$(MAKE_IMAGE)
108
+	# Convert image to vdi hard drive
109
+	VBoxManage convertdd $(NAME).img $(NAME).vdi
110
+	$(TAR) $(ARCHIVE) $(NAME).vdi
111
+	@echo ""
112
+	$(SIGN)
113
+	@echo "Build complete."
114
+
115
+test: test-virtualbox
116
+
117
+test-virtualbox: virtualbox
118
+	$(eval VM_NAME = freedom-maker-test)
119
+	VBoxManage createvm --name $(VM_NAME) --ostype "Debian" --register
120
+	VBoxManage storagectl $(VM_NAME) --name "SATA Controller" --add sata \
121
+		 --controller IntelAHCI
122
+	VBoxManage storageattach $(VM_NAME) --storagectl "SATA Controller" \
123
+		--port 0 --device 0 --type hdd --medium $(NAME).vdi
124
+	VBoxManage modifyvm $(VM_NAME) --pae on --memory 1024 --vram 128 \
125
+		--nic1 nat --natpf1 ,tcp,,$(TEST_SSH_PORT),,22
126
+	VBoxManage startvm $(VM_NAME) --type headless
127
+	sleep $(TEST_FIRSTRUN_WAIT_TIME) # wait for first-run to complete
128
+	echo frdm |sshpass -p frdm ssh -o UserKnownHostsFile=/dev/null \
129
+		-o StrictHostKeyChecking=no -t -t \
130
+		-p $(TEST_SSH_PORT) fbx@127.0.0.1 \
131
+		"sudo plinth --diagnose" \
132
+		|tee build/$(VM_NAME)-results_$(TODAY).log
133
+	VBoxManage controlvm $(VM_NAME) poweroff
134
+	VBoxManage modifyvm $(VM_NAME) --hda none
135
+	VBoxManage unregistervm $(VM_NAME) --delete
136
+
137
+vendor/vmdebootstrap/vmdebootstrap: vendor-patches/vmdebootstrap/*.patch
138
+	bin/fetch-new-vmdebootstrap
139
+
140
+prep: vendor/vmdebootstrap/vmdebootstrap
141
+	mkdir -p build
142
+
143
+clean:
144
+	-rm -f build/freedombone.log
145
+
146
+distclean: clean
147
+	sudo rm -rf build