=== modified file 'linaro-hwpack-install'
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# linaro-hwpack-install - Install a Linaro Hardware Pack.
# This script is meant to run inside a chroot containing nothing other than
# ubuntu-minimal, so it must not depend on anything that's not in
@@ -62,6 +62,7 @@
HWPACK_VERSION=""
HWPACK_ARCH=""
HWPACK_NAME=""
+EXTRACT_KERNEL_ONLY="no"
while [ $# -gt 0 ]; do
case "$1" in
@@ -83,6 +84,9 @@
HWPACK_NAME=$2
shift;
shift;;
+ --extract-kernel-only)
+ EXTRACT_KERNEL_ONLY="yes"
+ shift;;
--*)
die $usage_msg "\nUnrecognized option: \"$1\"";;
*)
@@ -98,165 +102,207 @@
[ "$HWPACK_ARCH" = "" ] && die $usage_msg
[ "$HWPACK_NAME" = "" ] && die $usage_msg
-# Try to acquire fd #9 (i.e. /var/lock/hwpack) for 2 seconds.
-# Using 9 as the file descriptor because of https://launchpad.net/bugs/249620
-exec 9>$LOCKFILE
-flock -w2 9 || die "Could not acquire lock: $LOCKFILE"
+setup_hwpack() {
+ # This creates all the directories we need.
+ mkdir -p "$HWPACK_DIR"
+
+ # Unpack the hwpack tarball. We don't download it here because the chroot may
+ # not contain any tools that would allow us to do that.
+ echo -n "Unpacking hardware pack ..."
+ tar zxf "$HWPACK_TARBALL" -C "$HWPACK_DIR"
+ echo "Done"
+
+ # Check the format of the hwpack is supported.
+ hwpack_format=$(cat ${HWPACK_DIR}/FORMAT)
+ supported="false"
+ for format in $SUPPORTED_FORMATS; do
+ if [ "x$hwpack_format" = "x$format" ]; then
+ supported="true"
+ break
+ fi
+ done
+
+ [ $supported = "true" ] || \
+ die "Unsupported hwpack format: $hwpack_format. "\
+ "Try using a newer version of $(basename $0)."
+
+ # Check the architecture of the hwpack matches that of the host system.
+ if [ "x$EXTRACT_KERNEL_ONLY" = "xno" ]; then
+ # TODO: create a generic way to identify the architecture, without depending on dpkg
+ [ "$HWPACK_ARCH" = `dpkg --print-architecture` ] || \
+ die "Hardware pack architecture ($HWPACK_ARCH) does not match the host's architecture"
+ fi
+}
+
+setup_apt_sources() {
+ # Install the apt sources that contain the packages we need.
+ for filename in $(ls "${HWPACK_DIR}"/sources.list.d/); do
+ file="${HWPACK_DIR}"/sources.list.d/$filename
+ should_install=0
+ stripped_file=${TEMP_DIR}/$filename
+ grep -v "\(^#\|^\s*$\)" $file > $stripped_file
+ while read line; do
+ # Only install files that have at least one line not present in the
+ # existing sources lists.
+ grep -qF "$line" $(find /etc/apt/sources.list.d/ -name '*.list') /etc/apt/sources.list \
+ || should_install=1
+ done < $stripped_file
+
+ if [ $should_install -eq 1 ]; then
+ $sudo cp $file /etc/apt/sources.list.d/hwpack.$filename
+ fi
+ done
+
+ # Import the OpenPGP keys for the files installed above.
+ for filename in $(ls "${HWPACK_DIR}"/sources.list.d.gpg/); do
+ file="${HWPACK_DIR}"/sources.list.d.gpg/$filename
+ $sudo apt-key add $file
+ done
+
+ # Add one extra apt source for the packages included in the hwpack and make
+ # sure it's the first on the list of sources so that it gets precedence over
+ # the others.
+ echo "deb file:${HWPACK_DIR}/pkgs ./" > "$SOURCES_LIST_FILE"
+ cat /etc/apt/sources.list >> "$SOURCES_LIST_FILE"
+
+ if [ "$FORCE_YES" = "yes" ]; then
+ FORCE_OPTIONS="--yes --force-yes"
+ else
+ FORCE_OPTIONS=""
+ fi
+
+ echo "Updating apt package lists ..."
+ $sudo apt-get $FORCE_OPTIONS -o "$APT_GET_OPTIONS" update -q
+}
+
+setup_ubuntu_rootfs() {
+ # Prevent daemons to start in the chroot
+ echo "exit 101" > /usr/sbin/policy-rc.d
+ chmod a+x /usr/sbin/policy-rc.d
+
+ mv -f /sbin/start-stop-daemon /sbin/start-stop-daemon.REAL
+ cat > /sbin/start-stop-daemon << EOF
+#!/bin/sh
+
+echo "Warning: Fake start-stop-daemon called, doing nothing"
+EOF
+chmod 755 /sbin/start-stop-daemon
+
+if [ -x /sbin/initctl ]; then
+ mv -f /sbin/initctl /sbin/initctl.REAL
+ cat > /sbin/initctl << EOF
+#!/bin/sh
+
+echo "Warning: Fake initctl called, doing nothing"
+EOF
+ chmod 755 /sbin/initctl
+ fi
+}
+
+install_deb_packages() {
+ echo -n "Installing packages ..."
+
+ # "newer" hwpacks contain a dependency package whose Depends is the
+ # same as the packages config setting from the file the hwpack was
+ # build from. But if we just installed that, a newer version of a
+ # package than that in the hwpack might have made it to the main
+ # archive and apt-get would install that instead. So we install the
+ # specific package versions that make up the hwpack. /That/ however
+ # would leave all the packages from the hwpack marked as manually
+ # installed, so if a newer hwpack was installed over the top which no
+ # longer depended on one of the packages the older one did, the
+ # package would not be eligible for autoremoval. So we mark the all
+ # packages newly installed as part of hwpack installed (apart from the
+ # dependency package) as automatically installed with apt-get
+ # markauto.
+ #
+ # For "older" hwpacks that don't have a dependency package, we just
+ # manually install the contents of the hwpack.
+
+ dependency_package="hwpack-${HWPACK_NAME}"
+ if grep -q "^${dependency_package}=${HWPACK_VERSION}\$" "${HWPACK_DIR}"/manifest; then
+ DEP_PACKAGE_PRESENT="yes"
+ else
+ DEP_PACKAGE_PRESENT="no"
+ fi
+
+ packages_without_versions=`sed 's/=.*//' "${HWPACK_DIR}"/manifest`
+ packages_with_versions=`cat "${HWPACK_DIR}"/manifest`
+
+ if [ "$INSTALL_LATEST" = "yes" ]; then
+ packages="${packages_without_versions}"
+ else
+ packages="${packages_with_versions}"
+ fi
+
+ if [ "$DEP_PACKAGE_PRESENT" = "yes" ]; then
+ to_be_installed=
+ for package in $packages_without_versions; do
+ if [ "${package}" != "${dependency_package}" ]; then
+ { dpkg --get-selections $package 2>/dev/null| grep -qw 'install$'; } || to_be_installed="$to_be_installed $package"
+ fi
+ done
+ fi
+
+ $sudo apt-get $FORCE_OPTIONS -o "$APT_GET_OPTIONS" install ${packages}
+
+ if [ "$DEP_PACKAGE_PRESENT" = "yes" ]; then
+ if [ -n "${to_be_installed}" ]; then
+ $sudo apt-get $FORCE_OPTIONS -o "$APT_GET_OPTIONS" markauto ${to_be_installed}
+ fi
+ fi
+}
+
+extract_kernel_packages() {
+ echo "Extracting all kernel packages ..."
+
+ ls ${HWPACK_DIR}/pkgs/linux-[ih]*.deb | while read pkg; do
+ echo "Extracting package `basename $pkg`"
+ dpkg-deb -x ${pkg} /
+ done
+
+ # manually generate modules.dep
+ ls /lib/modules | while read kernel; do
+ depmod ${kernel}
+ done;
+}
cleanup() {
# Ensure our temp dir and apt sources are removed.
echo -n "Cleaning up ..."
rm -rf $TEMP_DIR
- rm -f /usr/sbin/policy-rc.d
- mv -f /sbin/start-stop-daemon.REAL /sbin/start-stop-daemon
- if [ -x /sbin/initctl.REAL ]; then
- mv -f /sbin/initctl.REAL /sbin/initctl
+ if [ "x$EXTRACT_KERNEL_ONLY" = "xno" ]; then
+ rm -f /usr/sbin/policy-rc.d
+ mv -f /sbin/start-stop-daemon.REAL /sbin/start-stop-daemon
+ if [ -x /sbin/initctl.REAL ]; then
+ mv -f /sbin/initctl.REAL /sbin/initctl
+ fi
+ $sudo apt-get update -qq
fi
- $sudo apt-get update -qq
echo "Done"
}
+## main
+
+# Try to acquire fd #9 (i.e. /var/lock/hwpack)
+# Using 9 as the file descriptor because of https://launchpad.net/bugs/249620
+exec 9>$LOCKFILE
+flock -n 9 || die "Could not acquire lock: $LOCKFILE"
+
# From now on we'll be making changes to the system, so we need to clean
# things up when the script exits.
trap cleanup EXIT
-# This creates all the directories we need.
-mkdir -p "$HWPACK_DIR"
-
-# Unpack the hwpack tarball. We don't download it here because the chroot may
-# not contain any tools that would allow us to do that.
-echo -n "Unpacking hardware pack ..."
-tar zxf "$HWPACK_TARBALL" -C "$HWPACK_DIR"
-echo "Done"
-
-# Check the format of the hwpack is supported.
-hwpack_format=$(cat ${HWPACK_DIR}/FORMAT)
-supported="false"
-for format in $SUPPORTED_FORMATS; do
- if [ $hwpack_format == $format ]; then
- supported="true"
- break
- fi
-done
-[ $supported == "true" ] || \
- die "Unsupported hwpack format: $hwpack_format. "\
- "Try using a newer version of $(basename $0)."
-
-# Check the architecture of the hwpack matches that of the host system.
-[ "$HWPACK_ARCH" == `dpkg --print-architecture` ] || \
- die "Hardware pack architecture ($HWPACK_ARCH) does not match the host's architecture"
-
-# Install the apt sources that contain the packages we need.
-for filename in $(ls "${HWPACK_DIR}"/sources.list.d/); do
- file="${HWPACK_DIR}"/sources.list.d/$filename
- should_install=0
- stripped_file=${TEMP_DIR}/$filename
- grep -v "\(^#\|^\s*$\)" $file > $stripped_file
- while read line; do
- # Only install files that have at least one line not present in the
- # existing sources lists.
- grep -qF "$line" $(find /etc/apt/sources.list.d/ -name '*.list') /etc/apt/sources.list \
- || should_install=1
- done < $stripped_file
-
- if [ $should_install -eq 1 ]; then
- $sudo cp $file /etc/apt/sources.list.d/hwpack.$filename
- fi
-done
-
-# Import the OpenPGP keys for the files installed above.
-for filename in $(ls "${HWPACK_DIR}"/sources.list.d.gpg/); do
- file="${HWPACK_DIR}"/sources.list.d.gpg/$filename
- $sudo apt-key add $file
-done
-
-# Prevent daemons to start in the chroot
-echo "exit 101" > /usr/sbin/policy-rc.d
-chmod a+x /usr/sbin/policy-rc.d
-
-mv -f /sbin/start-stop-daemon /sbin/start-stop-daemon.REAL
-cat > /sbin/start-stop-daemon << EOF
-#!/bin/sh
-
-echo "Warning: Fake start-stop-daemon called, doing nothing"
-EOF
-chmod 755 /sbin/start-stop-daemon
-
-if [ -x /sbin/initctl ]; then
- mv -f /sbin/initctl /sbin/initctl.REAL
- cat > /sbin/initctl << EOF
-#!/bin/sh
-
-echo "Warning: Fake initctl called, doing nothing"
-EOF
- chmod 755 /sbin/initctl
-fi
-
-# Add one extra apt source for the packages included in the hwpack and make
-# sure it's the first on the list of sources so that it gets precedence over
-# the others.
-echo "deb file:${HWPACK_DIR}/pkgs ./" > "$SOURCES_LIST_FILE"
-cat /etc/apt/sources.list >> "$SOURCES_LIST_FILE"
-
-if [ "$FORCE_YES" == "yes" ]; then
- FORCE_OPTIONS="--yes --force-yes"
-else
- FORCE_OPTIONS=""
-fi
-
-echo "Updating apt package lists ..."
-$sudo apt-get $FORCE_OPTIONS -o "$APT_GET_OPTIONS" update -q
-
-echo -n "Installing packages ..."
-
-# "newer" hwpacks contain a dependency package whose Depends is the
-# same as the packages config setting from the file the hwpack was
-# build from. But if we just installed that, a newer version of a
-# package than that in the hwpack might have made it to the main
-# archive and apt-get would install that instead. So we install the
-# specific package versions that make up the hwpack. /That/ however
-# would leave all the packages from the hwpack marked as manually
-# installed, so if a newer hwpack was installed over the top which no
-# longer depended on one of the packages the older one did, the
-# package would not be eligible for autoremoval. So we mark the all
-# packages newly installed as part of hwpack installed (apart from the
-# dependency package) as automatically installed with apt-get
-# markauto.
-#
-# For "older" hwpacks that don't have a dependency package, we just
-# manually install the contents of the hwpack.
-
-dependency_package="hwpack-${HWPACK_NAME}"
-if grep -q "^${dependency_package}=${HWPACK_VERSION}\$" "${HWPACK_DIR}"/manifest; then
- DEP_PACKAGE_PRESENT="yes"
-else
- DEP_PACKAGE_PRESENT="no"
-fi
-
-packages_without_versions=`sed 's/=.*//' "${HWPACK_DIR}"/manifest`
-packages_with_versions=`cat "${HWPACK_DIR}"/manifest`
-
-if [ "$INSTALL_LATEST" == "yes" ]; then
- packages="${packages_without_versions}"
-else
- packages="${packages_with_versions}"
-fi
-
-if [ "$DEP_PACKAGE_PRESENT" == "yes" ]; then
- to_be_installed=
- for package in $packages_without_versions; do
- if [ "${package}" != "${dependency_package}" ]; then
- { dpkg --get-selections $package 2>/dev/null| grep -qw 'install$'; } || to_be_installed="$to_be_installed $package"
- fi
- done
-fi
-
-$sudo apt-get $FORCE_OPTIONS -o "$APT_GET_OPTIONS" install ${packages}
-
-if [ "$DEP_PACKAGE_PRESENT" == "yes" ]; then
- if [ -n "${to_be_installed}" ]; then
- $sudo apt-get $FORCE_OPTIONS -o "$APT_GET_OPTIONS" markauto ${to_be_installed}
- fi
+# Extract and set up the hwpack at the rootfs
+setup_hwpack
+
+# In case we only care about the kernel, don't mess up with the system
+if [ "x$EXTRACT_KERNEL_ONLY" = "xno" ]; then
+ setup_apt_sources
+ setup_ubuntu_rootfs
+ install_deb_packages
+else
+ extract_kernel_packages
fi
echo "Done"
=== modified file 'linaro-media-create'
@@ -164,14 +164,27 @@
# If --help was specified this won't execute.
# Create temp dir and initialize rest of path vars.
- filesystem_dir = 'binary'
- if not path_in_tarfile_exists('binary/etc', args.binary):
- # The binary image is in the new live format.
- filesystem_dir = 'binary/boot/filesystem.dir'
TMP_DIR = tempfile.mkdtemp()
- ROOTFS_DIR = os.path.join(TMP_DIR, filesystem_dir)
BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc')
ROOT_DISK = os.path.join(TMP_DIR, 'root-disc')
+ BIN_DIR = os.path.join(TMP_DIR, 'rootfs')
+ os.mkdir(BIN_DIR)
+
+ # Identify the correct path for the rootfs
+ filesystem_dir = ''
+ if path_in_tarfile_exists('binary/etc', args.binary):
+ filesystem_dir = 'binary'
+ elif path_in_tarfile_exists('binary/boot/filesystem.dir', args.binary):
+ # The binary image is in the new live format.
+ filesystem_dir = 'binary/boot/filesystem.dir'
+
+ # if not a debian compatible system, just extract the kernel packages
+ extract_kpkgs = False
+ if not path_in_tarfile_exists(
+ filesystem_dir + '/etc/debian_version', args.binary):
+ extract_kpkgs = True
+
+ ROOTFS_DIR = os.path.join(BIN_DIR, filesystem_dir)
ensure_required_commands(args)
@@ -188,28 +201,42 @@
atexit.register(cleanup_tempdir)
- unpack_binary_tarball(args.binary, TMP_DIR)
+ unpack_binary_tarball(args.binary, BIN_DIR)
hwpacks = args.hwpacks
lmc_dir = os.path.dirname(__file__)
if lmc_dir == '':
lmc_dir = None
install_hwpacks(ROOTFS_DIR, TMP_DIR, lmc_dir, args.hwpack_force_yes,
- verified_files, *hwpacks)
+ verified_files, extract_kpkgs, *hwpacks)
if args.rootfs == 'btrfs':
- install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools")
+ if not extract_kpkgs:
+ print ("Desired rootfs type is 'btrfs', trying to auto-install "
+ "the 'btrfs-tools' package")
+ install_packages(ROOTFS_DIR, TMP_DIR, "btrfs-tools")
+ else:
+ print ("Desired rootfs type is 'btrfs', please make sure the "
+ "rootfs also includes 'btrfs-tools'")
boot_partition, root_partition = setup_partitions(
board_config, media, args.image_size, args.boot_label, args.rfs_label,
args.rootfs, args.should_create_partitions, args.should_format_bootfs,
args.should_format_rootfs, args.should_align_boot_part)
- rootfs_uuid = get_uuid(root_partition)
+ uuid = get_uuid(root_partition)
+ # In case we're only extracting the kernel packages, avoid
+ # using uuid because we don't have a working initrd
+ if extract_kpkgs:
+ # XXX: this needs to be smarter as we can't always assume mmcblk devices
+ rootfs_id = '/dev/mmcblk%dp%s' % (
+ board_config.mmc_device_id, 2 + board_config.mmc_part_offset)
+ else:
+ rootfs_id = "UUID=%s" % uuid
if args.should_format_bootfs:
board_config.populate_boot(
- ROOTFS_DIR, rootfs_uuid, boot_partition, BOOT_DISK, media.path,
+ ROOTFS_DIR, rootfs_id, boot_partition, BOOT_DISK, media.path,
args.is_live, args.is_lowmem, args.consoles)
if args.should_format_rootfs:
@@ -217,7 +244,7 @@
if args.swap_file is not None:
create_swap = True
populate_rootfs(ROOTFS_DIR, ROOT_DISK, root_partition, args.rootfs,
- rootfs_uuid, create_swap, str(args.swap_file),
+ rootfs_id, create_swap, str(args.swap_file),
board_config.mmc_device_id, board_config.mmc_part_offset,
board_config)
=== modified file 'linaro_image_tools/media_create/android_boards.py'
@@ -77,10 +77,13 @@
"""
boot_env = {}
boot_env["bootargs"] = cls._get_bootargs(consoles)
+ initrd = False
+ if cls.initrd_addr:
+ initrd = True
# On Android, the DTB file is always built as part of the kernel it
# comes from - and lives in the same directory in the boot tarball, so
# here we don't need to pass the whole path to it.
- boot_env["bootcmd"] = cls._get_bootcmd(cls.dtb_name)
+ boot_env["bootcmd"] = cls._get_bootcmd(initrd, cls.dtb_name)
return boot_env
@classmethod
=== modified file 'linaro_image_tools/media_create/boards.py'
@@ -576,7 +576,7 @@
return cls.get_v1_sfdisk_cmd(should_align_boot_part)
@classmethod
- def _get_bootcmd(cls, d_img_data):
+ def _get_bootcmd(cls, i_img_data, d_img_data):
"""Get the bootcmd for this board.
In general subclasses should not have to override this.
@@ -587,20 +587,22 @@
initrd_addr=cls.initrd_addr, dtb_addr=cls.dtb_addr)
boot_script = (
("%(fatload_command)s mmc %(mmc_option)s %(kernel_addr)s " +
- "%(uimage_path)suImage; ") +
+ "%(uimage_path)suImage; ")) % replacements
+ if i_img_data is not None:
+ boot_script += (
("%(fatload_command)s mmc %(mmc_option)s %(initrd_addr)s " +
"%(uimage_path)suInitrd; ")) % replacements
- if d_img_data is not None:
- assert cls.dtb_addr is not None, (
- "Need a dtb_addr when passing d_img_data")
- boot_script += (
- ("%(fatload_command)s mmc %(mmc_option)s %(dtb_addr)s " +
- "board.dtb; ") +
- "bootm %(kernel_addr)s %(initrd_addr)s %(dtb_addr)s"
- ) % replacements
- else:
- boot_script += (
- "bootm %(kernel_addr)s %(initrd_addr)s" % replacements)
+ if d_img_data is not None:
+ assert cls.dtb_addr is not None, (
+ "Need a dtb_addr when passing d_img_data")
+ boot_script += (
+ ("%(fatload_command)s mmc %(mmc_option)s %(dtb_addr)s " +
+ "board.dtb; ")) % replacements
+ boot_script += (("bootm %(kernel_addr)s")) % replacements
+ if i_img_data is not None:
+ boot_script += ((" %(initrd_addr)s")) % replacements
+ if d_img_data is not None:
+ boot_script += ((" %(dtb_addr)s")) % replacements
return boot_script
@classmethod
@@ -618,7 +620,7 @@
cls.add_boot_args(boot_args_file.read().strip())
@classmethod
- def _get_bootargs(cls, is_live, is_lowmem, consoles, rootfs_uuid):
+ def _get_bootargs(cls, is_live, is_lowmem, consoles, rootfs_id):
"""Get the bootargs for this board.
In general subclasses should not have to override this.
@@ -631,7 +633,7 @@
serial_opts += ' console=%s' % console
lowmem_opt = ''
- boot_snippet = 'root=UUID=%s' % rootfs_uuid
+ boot_snippet = 'root=%s' % rootfs_id
if is_live:
serial_opts += ' %s' % cls.live_serial_opts
boot_snippet = 'boot=casper'
@@ -648,21 +650,21 @@
% replacements)
@classmethod
- def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_uuid,
- d_img_data):
+ def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
+ i_img_data, d_img_data):
"""Get the boot environment for this board.
In general subclasses should not have to override this.
"""
boot_env = {}
boot_env["bootargs"] = cls._get_bootargs(
- is_live, is_lowmem, consoles, rootfs_uuid)
- boot_env["bootcmd"] = cls._get_bootcmd(d_img_data)
+ is_live, is_lowmem, consoles, rootfs_id)
+ boot_env["bootcmd"] = cls._get_bootcmd(i_img_data, d_img_data)
return boot_env
@classmethod
def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
- consoles, chroot_dir, rootfs_uuid, boot_dir,
+ consoles, chroot_dir, rootfs_id, boot_dir,
boot_device_or_file):
if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
parts_dir = bootloader_parts_dir
@@ -670,8 +672,8 @@
parts_dir = chroot_dir
(k_img_data, i_img_data, d_img_data) = cls._get_kflavor_files(
parts_dir)
- boot_env = cls._get_boot_env(is_live, is_lowmem, consoles, rootfs_uuid,
- d_img_data)
+ boot_env = cls._get_boot_env(is_live, is_lowmem, consoles, rootfs_id,
+ i_img_data, d_img_data)
if cls.hwpack_format == HardwarepackHandler.FORMAT_1:
cls._make_boot_files(
@@ -728,7 +730,9 @@
cls.bootloader_dd)
make_uImage(cls.load_addr, k_img_data, boot_dir)
- make_uInitrd(i_img_data, boot_dir)
+
+ if i_img_data is not None:
+ make_uInitrd(i_img_data, boot_dir)
if d_img_data is not None:
make_dtb(d_img_data, boot_dir)
@@ -766,7 +770,7 @@
raise NotImplementedError()
@classmethod
- def populate_boot(cls, chroot_dir, rootfs_uuid, boot_partition, boot_disk,
+ def populate_boot(cls, chroot_dir, rootfs_id, boot_partition, boot_disk,
boot_device_or_file, is_live, is_lowmem, consoles):
parts_dir = 'boot'
if is_live:
@@ -799,7 +803,7 @@
cls.make_boot_files(
bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
- rootfs_uuid, boot_disk, boot_device_or_file)
+ rootfs_id, boot_disk, boot_device_or_file)
@classmethod
def _get_kflavor_files(cls, path):
@@ -833,18 +837,18 @@
def _get_kflavor_files_v2(cls, path):
kernel = _get_file_matching(os.path.join(path, cls.vmlinuz))
if kernel is not None:
+ logger = logging.getLogger("linaro_image_tools")
initrd = _get_file_matching(os.path.join(path, cls.initrd))
- if initrd is not None:
- dtb = None
- if cls.dtb_file is not None:
- dtb = _get_file_matching(os.path.join(path, cls.dtb_file))
- logger = logging.getLogger("linaro_image_tools")
- logger.info("Will use kernel=%s, initrd=%s, dtb=%s." % \
- (kernel, initrd, dtb))
- return (kernel, initrd, dtb)
- raise ValueError(
- "Found kernel matching %s but no initrd matching %s" % (
- cls.vmlinuz, cls.initrd))
+ if initrd is None:
+ logger.warn(
+ "Could not find a valid initrd, skipping uInitd.")
+ dtb = _get_file_matching(os.path.join(path, cls.dtb_file))
+ if dtb is None and cls.dtb_file is not None:
+ logger.warn(
+ "Could not find a valid dtb file, skipping it.")
+ logger.info("Will use kernel=%s, initrd=%s, dtb=%s." % \
+ (kernel, initrd, dtb))
+ return (kernel, initrd, dtb)
raise ValueError(
"No kernel found matching %s." % (cls.vmlinuz))
@@ -912,7 +916,7 @@
@classmethod
def make_boot_files(cls, bootloader_parts_dir, is_live, is_lowmem,
- consoles, chroot_dir, rootfs_uuid, boot_dir,
+ consoles, chroot_dir, rootfs_id, boot_dir,
boot_device_or_file):
# XXX: This is also part of our temporary hack to fix bug 697824; we
# need to call set_appropriate_serial_tty() before doing anything that
@@ -921,7 +925,7 @@
cls.set_appropriate_serial_tty(chroot_dir)
super(OmapConfig, cls).make_boot_files(
bootloader_parts_dir, is_live, is_lowmem, consoles, chroot_dir,
- rootfs_uuid, boot_dir, boot_device_or_file)
+ rootfs_id, boot_dir, boot_device_or_file)
@classmethod
def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
@@ -1511,10 +1515,10 @@
mmc_option = '0:2'
@classmethod
- def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_uuid,
- d_img_data):
+ def _get_boot_env(cls, is_live, is_lowmem, consoles, rootfs_id,
+ i_img_data, d_img_data):
boot_env = super(SamsungConfig, cls)._get_boot_env(
- is_live, is_lowmem, consoles, rootfs_uuid, d_img_data)
+ is_live, is_lowmem, consoles, rootfs_id, i_img_data, d_img_data)
boot_env["ethact"] = "smc911x-0"
boot_env["ethaddr"] = "00:40:5c:26:0a:5b"
=== modified file 'linaro_image_tools/media_create/chroot_utils.py'
@@ -46,7 +46,7 @@
def install_hwpacks(
chroot_dir, tmp_dir, tools_dir, hwpack_force_yes, verified_files,
- *hwpack_files):
+ extract_kpkgs = False, *hwpack_files):
"""Install the given hwpacks onto the given chroot."""
prepare_chroot(chroot_dir, tmp_dir)
@@ -79,18 +79,19 @@
hwpack_verified = False
if os.path.basename(hwpack_file) in verified_files:
hwpack_verified = True
- install_hwpack(chroot_dir, hwpack_file,
+ install_hwpack(chroot_dir, hwpack_file, extract_kpkgs,
hwpack_force_yes or hwpack_verified)
finally:
run_local_atexit_funcs()
-def install_hwpack(chroot_dir, hwpack_file, hwpack_force_yes):
+def install_hwpack(chroot_dir, hwpack_file, extract_kpkgs, hwpack_force_yes):
"""Install an hwpack on the given chroot.
Copy the hwpack file to the chroot and run linaro-hwpack-install passing
that hwpack file to it. If hwpack_force_yes is True, also pass
- --force-yes to linaro-hwpack-install.
+ --force-yes to linaro-hwpack-install. In case extract_kpkgs is True, it
+ will not install all the packages, but just extract the kernel ones.
"""
hwpack_basename = os.path.basename(hwpack_file)
copy_file(hwpack_file, chroot_dir)
@@ -110,6 +111,8 @@
'--hwpack-name', name]
if hwpack_force_yes:
args.append('--force-yes')
+ if extract_kpkgs:
+ args.append('--extract-kernel-only')
args.append('/%s' % hwpack_basename)
cmd_runner.run(args, as_root=True, chroot=chroot_dir).wait()
print "-" * 60
@@ -179,15 +182,20 @@
basename = os.path.basename(filepath)
path_to_orig = os.path.join(tmp_dir, basename)
# Move the existing file from the given directory to the temp dir.
- cmd_runner.run(
- ['mv', '-f', os.path.join(directory, basename), path_to_orig],
- as_root=True).wait()
+ oldpath = os.path.join(directory, basename)
+ if os.path.exists(oldpath):
+ cmd_runner.run(
+ ['mv', '-f', oldpath, path_to_orig], as_root=True).wait()
# Now copy the given file onto the given directory.
cmd_runner.run(['cp', filepath, directory], as_root=True).wait()
def undo():
- cmd_runner.run(
- ['mv', '-f', path_to_orig, directory], as_root=True).wait()
+ if os.path.exists(path_to_orig):
+ cmd_runner.run(
+ ['mv', '-f', path_to_orig, directory], as_root=True).wait()
+ else:
+ cmd_runner.run(
+ ['rm', '-f', oldpath], as_root=True).wait()
local_atexit.append(undo)
=== modified file 'linaro_image_tools/media_create/rootfs.py'
@@ -42,7 +42,7 @@
def populate_rootfs(content_dir, root_disk, partition, rootfs_type,
- rootfs_uuid, should_create_swap, swap_size,
+ rootfs_id, should_create_swap, swap_size,
mmc_device_id, partition_offset, board_config=None):
"""Populate the rootfs and make the necessary tweaks to make it usable.
@@ -64,8 +64,8 @@
move_contents(content_dir, root_disk)
mount_options = rootfs_mount_options(rootfs_type)
- fstab_additions = ["UUID=%s / %s %s 0 1" % (
- rootfs_uuid, rootfs_type, mount_options)]
+ fstab_additions = ["%s / %s %s 0 1" % (
+ rootfs_id, rootfs_type, mount_options)]
if should_create_swap:
print "\nCreating SWAP File\n"
if has_space_left_for_swap(root_disk, swap_size):
=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
@@ -950,7 +950,8 @@
boot_env = board_configs['snowball_emmc']._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="test_boot_env_uuid", d_img_data=None)
+ rootfs_id="UUID=test_boot_env_uuid",
+ i_img_data=None, d_img_data=None)
boards.SnowballEmmcConfig._make_boot_files(boot_env, self.tempdir,
self.temp_bootdir_path, 'boot_device_or_file', k_img_file,
i_img_file, None)
@@ -1577,7 +1578,7 @@
def test_vexpress(self):
boot_commands = board_configs['vexpress']._get_boot_env(
is_live=False, is_lowmem=False, consoles=['ttyXXX'],
- rootfs_uuid="deadbeef", d_img_data=None)
+ rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
expected = {
'bootargs': 'console=tty0 console=ttyAMA0,38400n8 '
'console=ttyXXX root=UUID=deadbeef rootwait ro',
@@ -1589,7 +1590,7 @@
def test_vexpress_a9(self):
boot_commands = board_configs['vexpress-a9']._get_boot_env(
is_live=False, is_lowmem=False, consoles=['ttyXXX'],
- rootfs_uuid="deadbeef", d_img_data=None)
+ rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
expected = {
'bootargs': 'console=tty0 console=ttyAMA0,38400n8 '
'console=ttyXXX root=UUID=deadbeef rootwait ro',
@@ -1601,7 +1602,8 @@
def test_mx51(self):
boot_commands = boards.Mx51Config._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data="mx51.dtb")
+ rootfs_id="UUID=deadbeef", i_img_data="initrd",
+ d_img_data="mx51.dtb")
expected = {
'bootargs': 'console=tty0 console=ttymxc0,115200n8 '
'root=UUID=deadbeef rootwait ro',
@@ -1614,7 +1616,7 @@
def test_smdkv310(self):
boot_commands = board_configs['smdkv310']._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data=None)
+ rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
expected = {
'bootargs': 'console=ttySAC1,115200n8 root=UUID=deadbeef '
'rootwait ro',
@@ -1628,7 +1630,7 @@
def test_origen(self):
boot_commands = board_configs['origen']._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data=None)
+ rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
expected = {
'bootargs': 'console=ttySAC2,115200n8 root=UUID=deadbeef '
'rootwait ro',
@@ -1640,7 +1642,7 @@
def test_ux500(self):
boot_commands = board_configs['ux500']._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data=None)
+ rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
expected = {
'bootargs': 'console=tty0 console=ttyAMA2,115200n8 '
'root=UUID=deadbeef rootwait ro earlyprintk '
@@ -1656,7 +1658,7 @@
def test_snowball_emmc(self):
boot_commands = board_configs['snowball_emmc']._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data=None)
+ rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
expected = {
'bootargs': 'console=tty0 console=ttyAMA2,115200n8 '
'root=UUID=deadbeef rootwait ro earlyprintk '
@@ -1677,7 +1679,8 @@
config.serial_tty = config._serial_tty
boot_commands = config._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data="panda.dtb")
+ rootfs_id="UUID=deadbeef", i_img_data="initrd",
+ d_img_data="panda.dtb")
expected = {
'bootargs': 'console=tty0 console=ttyO2,115200n8 '
'root=UUID=deadbeef rootwait ro earlyprintk fixrtc '
@@ -1697,7 +1700,8 @@
config.serial_tty = config._serial_tty
boot_commands = config._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data="beagle.dtb")
+ rootfs_id="UUID=deadbeef", i_img_data="initrd",
+ d_img_data="beagle.dtb")
expected = {
'bootargs': 'console=tty0 console=ttyO2,115200n8 '
'root=UUID=deadbeef rootwait ro earlyprintk fixrtc '
@@ -1717,7 +1721,8 @@
config.serial_tty = config._serial_tty
boot_cmd = config._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data="igep.dtb")
+ rootfs_id="UUID=deadbeef", i_img_data="initrd",
+ d_img_data="igep.dtb")
expected = {
'bootargs': 'console=tty0 console=ttyO2,115200n8 '
'root=UUID=deadbeef rootwait ro earlyprintk fixrtc '
@@ -1737,7 +1742,8 @@
config.serial_tty = config._serial_tty
boot_commands = config._get_boot_env(
is_live=False, is_lowmem=False, consoles=[],
- rootfs_uuid="deadbeef", d_img_data="overo.dtb")
+ rootfs_id="UUID=deadbeef", i_img_data="initrd",
+ d_img_data="overo.dtb")
expected = {
'bootargs': 'console=tty0 console=ttyO2,115200n8 '
'root=UUID=deadbeef rootwait ro earlyprintk '
@@ -1760,7 +1766,7 @@
extra_boot_args_options = boot_args
boot_commands = config._get_boot_env(
is_live=False, is_lowmem=False, consoles=['ttyXXX'],
- rootfs_uuid="deadbeef", d_img_data=None)
+ rootfs_id="UUID=deadbeef", i_img_data=None, d_img_data=None)
expected = (
' console=ttyXXX root=UUID=deadbeef rootwait ro %s' % boot_args)
self.assertEqual(expected, boot_commands['bootargs'])
@@ -2874,10 +2880,10 @@
class TestPopulateBoot(TestCaseWithFixtures):
expected_args = (
- 'chroot_dir/boot', False, False, [], 'chroot_dir', 'rootfs_uuid',
+ 'chroot_dir/boot', False, False, [], 'chroot_dir', 'rootfs_id',
'boot_disk', 'boot_device_or_file')
expected_args_live = (
- 'chroot_dir/casper', True, False, [], 'chroot_dir', 'rootfs_uuid',
+ 'chroot_dir/casper', True, False, [], 'chroot_dir', 'rootfs_id',
'boot_disk', 'boot_device_or_file')
expected_calls = [
'mkdir -p boot_disk',
@@ -2903,7 +2909,7 @@
def call_populate_boot(self, config, is_live=False):
config.populate_boot(
- 'chroot_dir', 'rootfs_uuid', 'boot_partition', 'boot_disk',
+ 'chroot_dir', 'rootfs_id', 'boot_partition', 'boot_disk',
'boot_device_or_file', is_live, False, [])
def test_populate_boot_live(self):
@@ -3000,7 +3006,7 @@
populate_rootfs(
contents_dir, root_disk, partition='/dev/rootfs',
- rootfs_type='ext3', rootfs_uuid='uuid', should_create_swap=True,
+ rootfs_type='ext3', rootfs_id='UUID=uuid', should_create_swap=True,
swap_size=100, mmc_device_id=0, partition_offset=0)
self.assertEqual(
@@ -3308,14 +3314,13 @@
fixture = self.useFixture(MockCmdRunnerPopenFixture())
temporarily_overwrite_file_on_dir('/path/to/file', '/dir', '/tmp/dir')
self.assertEquals(
- ['%s mv -f /dir/file /tmp/dir/file' % sudo_args,
- '%s cp /path/to/file /dir' % sudo_args],
+ ['%s cp /path/to/file /dir' % sudo_args],
fixture.mock.commands_executed)
fixture.mock.calls = []
run_local_atexit_funcs()
self.assertEquals(
- ['%s mv -f /tmp/dir/file /dir' % sudo_args],
+ ['%s rm -f /dir/file' % sudo_args],
fixture.mock.commands_executed)
def test_copy_file(self):
@@ -3355,10 +3360,12 @@
hwpack_name = "foo"
hwpack_version = "4"
hwpack_architecture = "armel"
+ extract_kpkgs = False
self.create_minimal_v3_hwpack(hwpack_tgz_location, hwpack_name,
hwpack_version, hwpack_architecture)
force_yes = False
- install_hwpack(chroot_dir, hwpack_tgz_location, force_yes)
+ install_hwpack(chroot_dir, hwpack_tgz_location,
+ extract_kpkgs, force_yes)
self.assertEquals(
['%s cp %s %s' % (sudo_args, hwpack_tgz_location, chroot_dir),
'%s %s %s linaro-hwpack-install --hwpack-version %s '
@@ -3374,6 +3381,38 @@
['%s rm -f %s/hwpack.tgz' % (sudo_args, chroot_dir)],
fixture.mock.commands_executed)
+ def test_install_hwpack_extract(self):
+ self.useFixture(MockSomethingFixture(
+ sys, 'stdout', open('/dev/null', 'w')))
+ fixture = self.useFixture(MockCmdRunnerPopenFixture())
+ chroot_dir = 'chroot_dir'
+ hwpack_dir = tempfile.mkdtemp()
+ hwpack_file_name = 'hwpack.tgz'
+ hwpack_tgz_location = os.path.join(hwpack_dir, hwpack_file_name)
+ hwpack_name = "foo"
+ hwpack_version = "4"
+ hwpack_architecture = "armel"
+ extract_kpkgs = True
+ self.create_minimal_v3_hwpack(hwpack_tgz_location, hwpack_name,
+ hwpack_version, hwpack_architecture)
+ force_yes = False
+ install_hwpack(chroot_dir, hwpack_tgz_location,
+ extract_kpkgs, force_yes)
+ self.assertEquals(
+ ['%s cp %s %s' % (sudo_args, hwpack_tgz_location, chroot_dir),
+ '%s %s %s linaro-hwpack-install --hwpack-version %s '
+ '--hwpack-arch %s --hwpack-name %s --extract-kernel-only /%s'
+ % (sudo_args, chroot_args, chroot_dir,
+ hwpack_version, hwpack_architecture, hwpack_name,
+ hwpack_file_name)],
+ fixture.mock.commands_executed)
+
+ fixture.mock.calls = []
+ run_local_atexit_funcs()
+ self.assertEquals(
+ ['%s rm -f %s/hwpack.tgz' % (sudo_args, chroot_dir)],
+ fixture.mock.commands_executed)
+
def test_install_hwpacks(self):
self.useFixture(MockSomethingFixture(
sys, 'stdout', open('/dev/null', 'w')))
@@ -3389,6 +3428,7 @@
hwpack_file_names = ['hwpack1.tgz', 'hwpack2.tgz']
hwpack_tgz_locations = []
hwpack_names = []
+ extract_kpkgs = False
for hwpack_file_name in hwpack_file_names:
hwpack_tgz_location = os.path.join(hwpack_dir, hwpack_file_name)
hwpack_tgz_locations.append(hwpack_tgz_location)
@@ -3400,7 +3440,7 @@
hwpack_architecture)
install_hwpacks(
- chroot_dir, tmp_dir, prefer_dir, force_yes, [],
+ chroot_dir, tmp_dir, prefer_dir, force_yes, [], extract_kpkgs,
hwpack_tgz_locations[0], hwpack_tgz_locations[1])
linaro_hwpack_install = find_command(
'linaro-hwpack-install', prefer_dir=prefer_dir)
@@ -3463,14 +3503,12 @@
prepare_chroot('chroot', '/tmp/dir')
run_local_atexit_funcs()
expected = [
- 'mv -f chroot/etc/resolv.conf /tmp/dir/resolv.conf',
'cp /etc/resolv.conf chroot/etc',
- 'mv -f chroot/etc/hosts /tmp/dir/hosts',
'cp /etc/hosts chroot/etc',
'cp /usr/bin/qemu-arm-static chroot/usr/bin',
'rm -f chroot/usr/bin/qemu-arm-static',
- 'mv -f /tmp/dir/hosts chroot/etc',
- 'mv -f /tmp/dir/resolv.conf chroot/etc']
+ 'rm -f chroot/etc/hosts',
+ 'rm -f chroot/etc/resolv.conf']
expected = [
"%s %s" % (sudo_args, line) for line in expected]
self.assertEquals(expected, fixture.mock.commands_executed)
@@ -3508,7 +3546,7 @@
def mock_run_local_atexit_functions():
self.run_local_atexit_functions_called = True
- def mock_install_hwpack(p1, p2, p3):
+ def mock_install_hwpack(p1, p2, p3, p4):
raise Exception('hwpack mock exception')
self.useFixture(MockSomethingFixture(
@@ -3524,10 +3562,11 @@
force_yes = True
exception_caught = False
+ extract_kpkgs = False
try:
install_hwpacks(
'chroot', '/tmp/dir', preferred_tools_dir(), force_yes, [],
- 'hwp.tgz', 'hwp2.tgz')
+ extract_kpkgs, 'hwp.tgz', 'hwp2.tgz')
except:
exception_caught = True
self.assertTrue(self.run_local_atexit_functions_called)