=== modified file 'linaro-hwpack-install'
--- linaro-hwpack-install	2012-08-17 04:37:44 +0000
+++ linaro-hwpack-install	2012-10-04 09:12:57 +0000
@@ -53,7 +53,7 @@
   exit 1
 }
 
-usage_msg="Usage: $(basename $0) [--install-latest] [--force-yes] --hwpack-version <version> --hwpack-arch <architecture> --hwpack-name <name> HWPACK_TARBALL"
+usage_msg="Usage: $(basename $0) [--install-latest] [--force-yes] [--extract-kernel-only] --hwpack-version <version> --hwpack-arch <architecture> --hwpack-name <name> HWPACK_TARBALL"
 if [ $# -eq 0 ]; then
   die $usage_msg
 fi
@@ -256,14 +256,17 @@
 extract_kernel_packages() {
   echo "Extracting all kernel packages ..."
 
+  # We assume the hwpack is always available at the rootfs
+  ROOTFS_DIR=$(dirname $HWPACK_TARBALL)
+
   ls ${HWPACK_DIR}/pkgs/linux-[ih]*.deb | while read pkg; do
     echo "Extracting package `basename $pkg`"
-    dpkg-deb -x ${pkg} /
+    dpkg-deb -x ${pkg} $ROOTFS_DIR
   done
 
   # manually generate modules.dep
-  ls /lib/modules | while read kernel; do
-    depmod ${kernel} || true
+  ls $ROOTFS_DIR/lib/modules | while read kernel; do
+    depmod -b $ROOTFS_DIR ${kernel} || true
   done;
 }
 

=== modified file 'linaro_image_tools/media_create/chroot_utils.py'
--- linaro_image_tools/media_create/chroot_utils.py	2012-08-09 12:08:40 +0000
+++ linaro_image_tools/media_create/chroot_utils.py	2012-10-04 09:12:57 +0000
@@ -45,28 +45,33 @@
 
 
 def install_hwpacks(
-    chroot_dir, tmp_dir, tools_dir, hwpack_force_yes, verified_files,
+    rootfs_dir, tmp_dir, tools_dir, hwpack_force_yes, verified_files,
     extract_kpkgs=False, *hwpack_files):
-    """Install the given hwpacks onto the given chroot."""
-    prepare_chroot(chroot_dir, tmp_dir)
-
-    linaro_hwpack_install_path = find_command(
-        'linaro-hwpack-install', prefer_dir=tools_dir)
-    # FIXME: shouldn't use chroot/usr/bin as this might conflict with installed
-    # packages; would be best to use some custom directory like
-    # chroot/linaro-image-tools/bin
-    copy_file(linaro_hwpack_install_path,
-              os.path.join(chroot_dir, 'usr', 'bin'))
-
-    try:
-        mount_chroot_proc(chroot_dir)
+    """Install the given hwpacks onto the given rootfs."""
+
+    # In case we just want to extract the kernel packages, don't force qemu
+    # with chroot, as we could have archs without qemu support
+
+    if not extract_kpkgs:
+        prepare_chroot(rootfs_dir, tmp_dir)
+
+        linaro_hwpack_install_path = find_command(
+            'linaro-hwpack-install', prefer_dir=tools_dir)
+
+        # FIXME: shouldn't use chroot/usr/bin as this might conflict with
+        # installed packages; would be best to use some custom directory like
+        # chroot/linaro-image-tools/bin
+        copy_file(linaro_hwpack_install_path,
+                  os.path.join(rootfs_dir, 'usr', 'bin'))
+
+        mount_chroot_proc(rootfs_dir)
         try:
             # Sometimes the host will have qemu-user-static installed but
             # another package (i.e. scratchbox) will have mangled its config
             # and thus we won't be able to chroot and install the hwpack, so
             # we fail here and tell the user to ensure qemu-arm-static is
             # setup before trying again.
-            cmd_runner.run(['true'], as_root=True, chroot=chroot_dir).wait()
+            cmd_runner.run(['true'], as_root=True, chroot=rootfs_dir).wait()
         except:
             print ("Cannot proceed with hwpack installation because "
                    "there doesn't seem to be a binfmt interpreter registered "
@@ -75,26 +80,27 @@
                    "configured before trying again.")
             raise
 
+    try:
         for hwpack_file in hwpack_files:
             hwpack_verified = False
             if os.path.basename(hwpack_file) in verified_files:
                 hwpack_verified = True
-            install_hwpack(chroot_dir, hwpack_file, extract_kpkgs,
+            install_hwpack(rootfs_dir, hwpack_file, extract_kpkgs,
                            hwpack_force_yes or hwpack_verified)
     finally:
         run_local_atexit_funcs()
 
 
-def install_hwpack(chroot_dir, hwpack_file, extract_kpkgs, hwpack_force_yes):
-    """Install an hwpack on the given chroot.
+def install_hwpack(rootfs_dir, hwpack_file, extract_kpkgs, hwpack_force_yes):
+    """Install an hwpack on the given rootfs.
 
-    Copy the hwpack file to the chroot and run linaro-hwpack-install passing
+    Copy the hwpack file to the rootfs 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. 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)
+    copy_file(hwpack_file, rootfs_dir)
     print "-" * 60
     print "Installing (linaro-hwpack-install) %s in target rootfs." % (
         hwpack_basename)
@@ -111,9 +117,15 @@
             '--hwpack-name', name]
     if hwpack_force_yes:
         args.append('--force-yes')
+
     if extract_kpkgs:
         args.append('--extract-kernel-only')
-    args.append('/%s' % hwpack_basename)
+        args.append(os.path.join(rootfs_dir, hwpack_basename))
+        chroot_dir = None
+    else:
+        args.append('/%s' % hwpack_basename)
+        chroot_dir = rootfs_dir
+
     cmd_runner.run(args, as_root=True, chroot=chroot_dir).wait()
     print "-" * 60
 

=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
--- linaro_image_tools/media_create/tests/test_media_create.py	2012-09-20 08:19:28 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py	2012-10-04 09:12:57 +0000
@@ -3585,11 +3585,10 @@
                        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)],
+             '%s linaro-hwpack-install --hwpack-version %s '
+             '--hwpack-arch %s --hwpack-name %s --extract-kernel-only %s/%s'
+                % (sudo_args, hwpack_version, hwpack_architecture, hwpack_name,
+                   chroot_dir, hwpack_file_name)],
             fixture.mock.commands_executed)
 
         fixture.mock.calls = []

