=== modified file 'linaro-android-media-create'
@@ -42,6 +42,7 @@
from linaro_image_tools.media_create import get_android_args_parser
from linaro_image_tools.utils import (
additional_android_option_checks,
+ andorid_hwpack_in_boot_tarball,
ensure_command,
get_logger
)
@@ -109,15 +110,6 @@
DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')
SDCARD_DISK = os.path.join(TMP_DIR, 'sdcard-disc')
- board_config = get_board_config(args.dev)
- if args.hwpack:
- board_config.from_file(args.hwpack)
- else:
- logger.warning("No Android hwpack provided: default board values "
- "will be used.")
- board_config.add_boot_args(args.extra_boot_args)
- board_config.add_boot_args_from_file(args.extra_boot_args_file)
-
if args.dev == 'iMX53':
# XXX: remove this and the corresponding entry in android_board_configs
logger.warning("DEPRECATION WARNING: iMX53 is deprecated, please "
@@ -141,6 +133,23 @@
unpack_android_binary_tarball(args.system, SYSTEM_DIR)
unpack_android_binary_tarball(args.userdata, DATA_DIR)
+ board_config = get_board_config(args.dev)
+
+ hwpack_exists, config_file = andorid_hwpack_in_boot_tarball(BOOT_DIR)
+ if not args.hwpack and not hwpack_exists:
+ # No hwpack in the boot tarball nor provided on the command line.
+ logger.warning("No hwpack found in the boot tarball nor passed on "
+ "the command line. Default values will be used.")
+ elif not args.hwpack and hwpack_exists:
+ board_config.from_file(config_file)
+ elif args.hwpack:
+ logger.warning("Values from the hwpack provided on the command line "
+ "will be used.")
+ board_config.from_file(args.hwpack)
+
+ board_config.add_boot_args(args.extra_boot_args)
+ board_config.add_boot_args_from_file(args.extra_boot_args_file)
+
# Create partitions
boot_partition, system_partition, cache_partition, \
data_partition, sdcard_partition = setup_android_partitions( \
=== modified file 'linaro_image_tools/tests/test_utils.py'
@@ -37,7 +37,9 @@
IncompatibleOptions,
InvalidHwpackFile,
UnableToFindPackageProvidingCommand,
+ additional_android_option_checks,
additional_option_checks,
+ andorid_hwpack_in_boot_tarball,
check_file_integrity_and_log_errors,
ensure_command,
find_command,
@@ -335,6 +337,49 @@
sys.argv.remove("--mmc")
+class TestAndroidOptionChecks(TestCaseWithFixtures):
+
+ def test_hwpack_is_file(self):
+ class HwPacksArgs:
+ def __init__(self, hwpack):
+ self.hwpack = hwpack
+
+ try:
+ tmpdir = tempfile.mkdtemp()
+ self.assertRaises(InvalidHwpackFile,
+ additional_android_option_checks,
+ HwPacksArgs(tmpdir))
+ finally:
+ os.rmdir(tmpdir)
+
+ def test_android_hwpack_in_boot(self):
+ """Test presence of config file in boot directory."""
+ try:
+ tmpdir = tempfile.mkdtemp()
+ boot_dir = os.path.join(tmpdir, "boot")
+ os.mkdir(boot_dir)
+ config_file = os.path.join(boot_dir, "config")
+ expected = (True, config_file)
+ with open(config_file, "w"):
+ self.assertEqual(expected,
+ andorid_hwpack_in_boot_tarball(tmpdir))
+ finally:
+ os.unlink(config_file)
+ os.removedirs(boot_dir)
+
+ def test_android_hwpack_not_in_boot(self):
+ """Test missing config file."""
+ try:
+ tmpdir = tempfile.mkdtemp()
+ boot_dir = os.path.join(tmpdir, "boot")
+ os.mkdir(boot_dir)
+ config_file = os.path.join(boot_dir, "config")
+ expected = (False, config_file)
+ self.assertEqual(expected, andorid_hwpack_in_boot_tarball(tmpdir))
+ finally:
+ os.removedirs(boot_dir)
+
+
class TestHwpackIsFile(TestCaseWithFixtures):
"""Testing '--hwpack' option only allows regular files."""
=== modified file 'linaro_image_tools/utils.py'
@@ -30,6 +30,11 @@
DEFAULT_LOGGER_NAME = 'linaro_image_tools'
+# The boot path in the boot tarball.
+BOOT_DIR_IN_TARBALL = "boot"
+# The name of the hwpack file found in the boot tarball.
+HWPACK_NAME = "config"
+
# try_import was copied from python-testtools 0.9.12 and was originally
# licensed under a MIT-style license but relicensed under the GPL in Linaro
@@ -354,6 +359,19 @@
"--hwpack argument (%s) is not a regular file" % args.hwpack)
+def andorid_hwpack_in_boot_tarball(boot_dir):
+ """Simple check for existence of a path.
+
+ Needed to make cli command testable in some way.
+ :param boot_dir: The path where the boot tarball has been extracted.
+ :type str
+ :return A tuple with a bool if the path exists, and the path to the config
+ file.
+ """
+ conf_file = os.path.join(boot_dir, BOOT_DIR_IN_TARBALL, HWPACK_NAME)
+ return os.path.exists(conf_file), conf_file
+
+
def check_required_args(args):
"""Check that the required args are passed."""
if args.dev is None: