summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/builder2.py49
-rw-r--r--morphlib/fsutils.py2
-rw-r--r--morphlib/morph2.py1
-rwxr-xr-xtests.as-root/arm-system-writes-kernel.script79
4 files changed, 116 insertions, 15 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 37abdce2..caf0d8e1 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -383,13 +383,15 @@ class SystemBuilder(BuilderBase): # pragma: no cover
def build_and_cache(self):
with self.build_watch('overall-build'):
logging.debug('SystemBuilder.do_build called')
+
+ arch = self.artifact.source.morphology['arch']
handle = self.local_artifact_cache.put(self.artifact)
image_name = handle.name
self._create_image(image_name)
self._partition_image(image_name)
- self._install_mbr(image_name)
+ self._install_mbr(arch, image_name)
partition = self._setup_device_mapping(image_name)
mount_point = None
@@ -401,12 +403,27 @@ class SystemBuilder(BuilderBase): # pragma: no cover
self._create_subvolume(factory_path)
self._unpack_strata(factory_path)
self._create_fstab(factory_path)
- self._create_extlinux_config(factory_path)
+ if arch in ('x86', 'x86_64', None):
+ self._create_extlinux_config(factory_path)
self._create_subvolume_snapshot(
mount_point, 'factory', 'factory-run')
factory_run_path = os.path.join(mount_point, 'factory-run')
- self._install_boot_files(factory_run_path, mount_point)
- self._install_extlinux(mount_point)
+ self._install_boot_files(arch, factory_run_path, mount_point)
+ if arch in ('x86', 'x86_64', None):
+ self._install_extlinux(mount_point)
+ if arch in ('arm',):
+ # write the kernel as metadata to the cache
+ # it should probably be a full artifact, but
+ # that would require altering the artifact
+ # resolver
+ lac = self.local_artifact_cache
+ a = self.artifact
+ with lac.put_artifact_metadata(a, 'kernel') as dest:
+ with open(os.path.join(factory_path,
+ 'boot',
+ 'zImage')) as kernel:
+ shutil.copyfileobj(kernel, dest)
+
self._unmount(mount_point)
except BaseException, e:
logging.error('Got error while system image building, '
@@ -418,6 +435,7 @@ class SystemBuilder(BuilderBase): # pragma: no cover
self._undo_device_mapping(image_name)
handle.close()
+
self.save_build_times()
def _create_image(self, image_name):
@@ -432,10 +450,12 @@ class SystemBuilder(BuilderBase): # pragma: no cover
with self.build_watch('partition-image'):
morphlib.fsutils.partition_image(self.app.runcmd, image_name)
- def _install_mbr(self, image_name):
+ def _install_mbr(self, arch, image_name):
logging.debug('Installing mbr on disk image %s' % image_name)
+ if arch not in ('x86', 'x86_64', None):
+ return
with self.build_watch('install-mbr'):
- morphlib.fsutils.install_mbr(self.app.runcmd, image_name)
+ morphlib.fsutils.install_syslinux_mbr(self.app.runcmd, image_name)
def _setup_device_mapping(self, image_name):
logging.debug('Device mapping partitions in %s' % image_name)
@@ -511,16 +531,17 @@ class SystemBuilder(BuilderBase): # pragma: no cover
self.app.runcmd(['btrfs', 'subvolume', 'snapshot', source, target],
cwd=path)
- def _install_boot_files(self, sourcefs, targetfs):
+ def _install_boot_files(self, arch, sourcefs, targetfs):
logging.debug('installing boot files into root volume')
with self.build_watch('install-boot-files'):
- shutil.copy2(os.path.join(sourcefs, 'extlinux.conf'),
- os.path.join(targetfs, 'extlinux.conf'))
- os.mkdir(os.path.join(targetfs, 'boot'))
- shutil.copy2(os.path.join(sourcefs, 'boot', 'vmlinuz'),
- os.path.join(targetfs, 'boot', 'vmlinuz'))
- shutil.copy2(os.path.join(sourcefs, 'boot', 'System.map'),
- os.path.join(targetfs, 'boot', 'System.map'))
+ if arch in ('x86', 'x86_64', None):
+ shutil.copy2(os.path.join(sourcefs, 'extlinux.conf'),
+ os.path.join(targetfs, 'extlinux.conf'))
+ os.mkdir(os.path.join(targetfs, 'boot'))
+ shutil.copy2(os.path.join(sourcefs, 'boot', 'vmlinuz'),
+ os.path.join(targetfs, 'boot', 'vmlinuz'))
+ shutil.copy2(os.path.join(sourcefs, 'boot', 'System.map'),
+ os.path.join(targetfs, 'boot', 'System.map'))
def _install_extlinux(self, path):
logging.debug('Installing extlinux to %s' % path)
diff --git a/morphlib/fsutils.py b/morphlib/fsutils.py
index 770cafa8..c74e97db 100644
--- a/morphlib/fsutils.py
+++ b/morphlib/fsutils.py
@@ -26,7 +26,7 @@ def partition_image(runcmd, image_name):
# FIXME make this more flexible with partitioning options
runcmd(['sfdisk', image_name], feed_stdin='1,,83,*\n')
-def install_mbr(runcmd, image_name):
+def install_syslinux_mbr(runcmd, image_name):
for path in ['/usr/lib/extlinux/mbr.bin',
'/usr/share/syslinux/mbr.bin']:
if os.path.exists(path):
diff --git a/morphlib/morph2.py b/morphlib/morph2.py
index 37e6f24f..394c27c3 100644
--- a/morphlib/morph2.py
+++ b/morphlib/morph2.py
@@ -38,6 +38,7 @@ class Morphology(object):
('description', ''),
('build-depends', None),
('build-system', 'manual'),
+ ('arch', None),
]
def __init__(self, text):
diff --git a/tests.as-root/arm-system-writes-kernel.script b/tests.as-root/arm-system-writes-kernel.script
new file mode 100755
index 00000000..06a7ba44
--- /dev/null
+++ b/tests.as-root/arm-system-writes-kernel.script
@@ -0,0 +1,79 @@
+#!/bin/sh
+#
+# If the system's arch is arm, it should write the kernel to the cache
+#
+# Copyright (C) 2011, 2012 Codethink Limited
+#
+# This program 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; version 2 of the License.
+#
+# 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.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -eu
+
+cache="$DATADIR/cache/artifacts"
+kernelrepo="$DATADIR/kernel-repo"
+morphsrepo="$DATADIR/morphs-repo"
+log="$DATADIR/morph.log"
+
+cd "$morphsrepo"
+git checkout --quiet -b arm master
+cat <<EOF >arm-system.morph
+{
+ "name": "arm-system",
+ "kind": "system",
+ "arch": "arm",
+ "disk-size": "1G",
+ "strata": [
+ "arm-stratum"
+ ]
+}
+EOF
+cat <<EOF >arm-stratum.morph
+{
+ "name": "arm-stratum",
+ "kind": "stratum",
+ "sources": [
+ {
+ "name": "hello",
+ "repo": "test:chunk-repo",
+ "ref": "farrokh"
+ },
+ {
+ "name": "linux",
+ "repo": "test:kernel-repo",
+ "ref": "arm"
+ }
+ ]
+}
+EOF
+git add arm-system.morph arm-stratum.morph
+git commit --quiet -m "add arm system"
+
+cd "$kernelrepo"
+git checkout --quiet -b arm master
+cat <<EOF >linux.morph
+{
+ "name": "linux",
+ "kind": "chunk",
+ "install-commands": [
+ "mkdir -p \"\$DESTDIR/boot\"",
+ "touch \"\$DESTDIR\"/boot/zImage"
+ ]
+}
+EOF
+git add linux.morph
+
+git commit --quiet -m 'Make the kernel create a dummy zImage'
+
+"$SRCDIR/scripts/test-morph" \
+ build test:morphs-repo arm arm-system.morph
+[ -e "$cache"/*system.arm-system.kernel ]