diff mbox

[Branch,~linaro-maintainers/linaro-image-tools/trunk] Rev 328: Move to boottarball for Android images.

Message ID 20110426163921.23439.37434.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

James Westby April 26, 2011, 4:39 p.m. UTC
Merge authors:
  Jeremy Chang (jeremychang)
Related merge proposals:
  https://code.launchpad.net/~jeremychang/linaro-image-tools/android-boottarball/+merge/58545
  proposed by: Jeremy Chang (jeremychang)
  review: Approve - James Westby (james-w)
------------------------------------------------------------
revno: 328 [merge]
committer: James Westby <james.westby@linaro.org>
branch nick: trunk
timestamp: Tue 2011-04-26 12:37:19 -0400
message:
  Move to boottarball for Android images.
added:
  linaro_image_tools/media_create/android_boards.py
modified:
  linaro-android-media-create
  linaro_image_tools/media_create/__init__.py
  linaro_image_tools/media_create/boards.py
  linaro_image_tools/media_create/partitions.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro-android-media-create'
--- linaro-android-media-create	2011-04-22 07:42:34 +0000
+++ linaro-android-media-create	2011-04-26 16:37:19 +0000
@@ -25,10 +25,9 @@ 
 
 from linaro_image_tools import cmd_runner
 
-from linaro_image_tools.media_create.boards import android_board_configs
+from linaro_image_tools.media_create.android_boards import android_board_configs
 from linaro_image_tools.media_create.check_device import (
     confirm_device_selection_and_ensure_it_is_ready)
-from linaro_image_tools.media_create.chroot_utils import install_hwpacks
 from linaro_image_tools.media_create.partitions import (
     Media,
     setup_partitions,
@@ -46,9 +45,7 @@ 
 
 # Just define the global variables
 TMP_DIR = None
-ROOTFS_DIR = None
 BOOT_DISK = None
-ROOT_DISK = None
 SYSTEM_DISK = None
 CACHE_DISK = None
 DATA_DISK = None
@@ -61,11 +58,11 @@ 
 def cleanup_tempdir():
     """Remove TEMP_DIR with all its contents.
 
-    Before doing so, make sure BOOT_DISK and ROOT_DISK are not mounted.
+    Before doing so, make sure DISKs are not mounted.
     """
     devnull = open('/dev/null', 'w')
     # ignore non-zero return codes
-    for disk in BOOT_DISK, ROOT_DISK, SYSTEM_DISK, CACHE_DISK, DATA_DISK, \
+    for disk in BOOT_DISK, SYSTEM_DISK, CACHE_DISK, DATA_DISK, \
                 SDCARD_DISK:
         if disk is not None:
             try:
@@ -86,10 +83,6 @@ 
     if not is_arm_host():
         required_commands.append('qemu-arm-static')
         required_commands.append('qemu-img')
-    if args.rootfs in ['ext2', 'ext3', 'ext4']:
-        required_commands.append('mkfs.%s' % args.rootfs)
-    else:
-        required_commands.append('mkfs.btrfs')
     for command in required_commands:
         ensure_command(command)
 
@@ -108,12 +101,11 @@ 
     # If --help was specified this won't execute.
     # Create temp dir and initialize rest of path vars.
     TMP_DIR = tempfile.mkdtemp()
-    ROOT_DIR = os.path.join(TMP_DIR, 'root')
+    BOOT_DIR = os.path.join(TMP_DIR, 'boot')
     SYSTEM_DIR = os.path.join(TMP_DIR, 'system')
     DATA_DIR = os.path.join(TMP_DIR, 'data')
 
     BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc')
-    ROOT_DISK = os.path.join(TMP_DIR, 'root-disc')
     SYSTEM_DISK = os.path.join(TMP_DIR, 'system-disc')
     CACHE_DISK = os.path.join(TMP_DIR, 'cache-disc')
     DATA_DISK = os.path.join(TMP_DIR, 'userdata-disc')
@@ -135,23 +127,22 @@ 
         # All good, move on.
         pass
 
-
-    cmd_runner.run(['mkdir', '-p', ROOT_DIR]).wait()
+    cmd_runner.run(['mkdir', '-p', BOOT_DIR]).wait()
     cmd_runner.run(['mkdir', '-p', SYSTEM_DIR]).wait()
     cmd_runner.run(['mkdir', '-p', DATA_DIR]).wait()
 
-    unpack_android_binary_tarball(args.root, ROOT_DIR)
+    unpack_android_binary_tarball(args.boot, BOOT_DIR)
     unpack_android_binary_tarball(args.system, SYSTEM_DIR)
     unpack_android_binary_tarball(args.userdata, DATA_DIR)
 
     # Create partitions    
-    boot_partition, root_partition, system_partition, cache_partition, \
+    boot_partition, system_partition, cache_partition, \
         data_partition, sdcard_partition = setup_android_partitions( \
-        board_config, media, 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)
+        board_config, media, args.boot_label, args.should_create_partitions,
+        args.should_align_boot_part)
 
-    populate_partition(ROOT_DIR, ROOT_DISK, root_partition)
+    populate_partition(BOOT_DIR + "/boot", BOOT_DISK, boot_partition)
+    board_config.populate_boot_script(boot_partition, BOOT_DISK, args.consoles)
     populate_partition(SYSTEM_DIR + "/system", SYSTEM_DISK, system_partition)
     populate_partition(DATA_DIR + "/data", DATA_DISK, data_partition)
     print "Done creating Linaro Android image on %s" % args.device

=== modified file 'linaro_image_tools/media_create/__init__.py'
--- linaro_image_tools/media_create/__init__.py	2011-03-31 19:03:31 +0000
+++ linaro_image_tools/media_create/__init__.py	2011-04-18 09:00:33 +0000
@@ -20,7 +20,7 @@ 
 import argparse
 
 from linaro_image_tools.media_create.boards import board_configs
-from linaro_image_tools.media_create.boards import android_board_configs
+from linaro_image_tools.media_create.android_boards import android_board_configs
 
 
 KNOWN_BOARDS = board_configs.keys()
@@ -122,14 +122,12 @@ 
         '--dev', required=True, dest='board', choices=ANDROID_KNOWN_BOARDS,
         help='Generate an SD card or image for the given board.')
     parser.add_argument(
-        '--rootfs', default='ext4', choices=['ext3', 'ext4'],
-        help='Type of filesystem to use for the rootfs')
-    parser.add_argument(
-        '--rfs_label', default='rootfs',
-        help='Label to use for the root filesystem.')
-    parser.add_argument(
         '--boot_label', default='boot',
         help='Label to use for the boot filesystem.')
+    parser.add_argument(
+        '--console', action='append', dest='consoles', default=[],
+        help=('Add a console to kernel boot parameter; this parameter can be '
+              'defined multiple times.'))
 
     parser.add_argument(
         '--system', default='system.tar.bz2', required=True,
@@ -138,16 +136,10 @@ 
         '--userdata', default='userdata.tar.bz2', required=True,
         help=('The tarball containing the Android data paritition'))
     parser.add_argument(
-        '--root', default='root.tar.bz2', required=True,
+        '--boot', default='boot.tar.bz2', required=True,
         help=('The tarball containing the Android root partition'))
 
     parser.add_argument(
-        '--no-rootfs', dest='should_format_rootfs', action='store_false',
-        help='Do not deploy the root filesystem.')
-    parser.add_argument(
-        '--no-bootfs', dest='should_format_bootfs', action='store_false',
-        help='Do not deploy the boot filesystem.')
-    parser.add_argument(
         '--no-part', dest='should_create_partitions', action='store_false',
         help='Reuse existing partitions on the given media.')
     parser.add_argument(

=== added file 'linaro_image_tools/media_create/android_boards.py'
--- linaro_image_tools/media_create/android_boards.py	1970-01-01 00:00:00 +0000
+++ linaro_image_tools/media_create/android_boards.py	2011-04-22 15:09:08 +0000
@@ -0,0 +1,158 @@ 
+# Copyright (C) 2011 Linaro
+#
+# Author: Jeremy Chang <jeremy.chang@linaro.org>
+#
+# This file is part of Linaro Image Tools.
+#
+# Linaro Image Tools 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, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Linaro Image Tools 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 Linaro Image Tools.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Configuration for boards supported by linaro-android-media-create.
+
+To add support for a new board, you need to create a subclass of
+AndroidBoardConfig, set appropriate values for its variables and add it to
+android_board_configs at the bottom of this file.
+"""
+
+from linaro_image_tools.media_create.partitions import SECTOR_SIZE
+from linaro_image_tools.media_create.boards import PART_ALIGN_S
+from linaro_image_tools.media_create.boards import BeagleConfig
+from linaro_image_tools.media_create.boards import PandaConfig
+from linaro_image_tools.media_create.boards import (
+    align_up,
+    align_partition,
+    make_boot_script
+    )
+
+from linaro_image_tools import cmd_runner
+import os
+
+class AndroidBoardConfig(object):
+    @classmethod
+    def _get_bootargs(cls, consoles):
+        """Get the bootargs for this board.
+
+        In general subclasses should not have to override this.
+        """
+        boot_args_options = 'rootwait ro'
+        if cls.extra_boot_args_options is not None:
+            boot_args_options += ' %s' % cls.extra_boot_args_options
+        boot_args_options += ' %s' % cls.android_specific_args
+        serial_opts = cls._extra_serial_opts
+        for console in consoles:
+            serial_opts += ' console=%s' % console
+
+        replacements = dict(
+            serial_opts=serial_opts,
+            boot_args_options=boot_args_options)
+        return (
+            "%(serial_opts)s "
+            "%(boot_args_options)s"
+             % replacements)
+
+    @classmethod
+    def _get_boot_env(cls, consoles):
+        """Get the boot environment for this board.
+
+        In general subclasses should not have to override this.
+        """
+        boot_env = {}
+        boot_env["bootargs"] = cls._get_bootargs(consoles)
+        boot_env["bootcmd"] = cls._get_bootcmd(None)
+        return boot_env
+
+    @classmethod
+    def populate_boot_script(cls, boot_partition, boot_disk, consoles):
+        cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
+        cmd_runner.run(['mount', boot_partition, boot_disk],
+            as_root=True).wait()
+
+        boot_env = cls._get_boot_env(consoles)
+        cmdline_filepath = os.path.join(boot_disk, "cmdline") 
+        cmdline_file = open(cmdline_filepath, 'r')
+        android_kernel_cmdline = cmdline_file.read()
+        boot_env['bootargs'] = boot_env['bootargs'] + ' ' + \
+            android_kernel_cmdline
+        cmdline_file.close()
+
+        boot_dir = boot_disk
+        boot_script_path = os.path.join(boot_dir, cls.boot_script)
+        make_boot_script(boot_env, boot_script_path)
+
+        cmd_runner.run(['sync']).wait()
+        try:
+            cmd_runner.run(['umount', boot_disk], as_root=True).wait()
+        except cmd_runner.SubcommandNonZeroReturnValue:
+            pass
+
+    @classmethod
+    def get_sfdisk_cmd(cls, should_align_boot_part=False):
+        if cls.fat_size == 32:
+            partition_type = '0x0C'
+        else:
+            partition_type = '0x0E'
+
+        BOOT_MIN_SIZE_S = align_up(128 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
+        SYSTEM_MIN_SIZE_S = align_up(256 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
+        CACHE_MIN_SIZE_S = align_up(256 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
+        USERDATA_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
+        SDCARD_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
+
+        # align on sector 63 for compatibility with broken versions of x-loader
+        # unless align_boot_part is set
+        boot_align = 63
+        if should_align_boot_part:
+            boot_align = PART_ALIGN_S
+
+        # can only start on sector 1 (sector 0 is MBR / partition table)
+        boot_start, boot_end, boot_len = align_partition(
+            1, BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
+        # apparently OMAP3 ROMs require the vfat length to be an even number
+        # of sectors (multiple of 1 KiB); decrease the length if it's odd,
+        # there should still be enough room
+        boot_len = boot_len - boot_len % 2
+        boot_end = boot_start + boot_len - 1
+
+        system_start, _system_end, _system_len = align_partition(
+            boot_end + 1, SYSTEM_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
+        cache_start, _cache_end, _cache_len = align_partition(
+            _system_end + 1, CACHE_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
+        userdata_start, _userdata_end, _userdata_len = align_partition(
+            _cache_end + 1, USERDATA_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
+        sdcard_start, _sdcard_end, _sdcard_len = align_partition(
+            _userdata_end + 1, SDCARD_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
+ 
+        return '%s,%s,%s,*\n%s,%s,L\n%s,%s,L\n%s,-,E\n%s,%s,L\n%s,,,-' % (
+            boot_start, boot_len, partition_type, system_start, _system_len,
+            cache_start, _cache_len, userdata_start, userdata_start,
+            _userdata_len, sdcard_start)
+
+
+class AndroidOmapConfig(AndroidBoardConfig):
+    pass
+
+
+class AndroidBeagleConfig(AndroidOmapConfig, BeagleConfig):
+    _extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'
+    android_specific_args = 'init=/init androidboot.console=ttyO2'
+
+
+class AndroidPandaConfig(AndroidOmapConfig, PandaConfig):
+    _extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'
+    android_specific_args = 'init=/init androidboot.console=ttyO2'
+
+
+android_board_configs = {
+    'beagle': AndroidBeagleConfig,
+    'panda': AndroidPandaConfig,
+    }

=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py	2011-04-21 13:12:57 +0000
+++ linaro_image_tools/media_create/boards.py	2011-04-26 16:37:19 +0000
@@ -193,54 +193,6 @@ 
         return '%s,%s,%s,*\n%s,,,-' % (
             boot_start, boot_len, partition_type, root_start)
 
-    # TODO: Create separate config classes for android and move this method
-    # into them, also renaming it to get_sfdisk_cmd() so that we don't need
-    # the image_type check in partitions.py.
-    @classmethod
-    def get_android_sfdisk_cmd(cls, should_align_boot_part=False):
-        if cls.fat_size == 32:
-            partition_type = '0x0C'
-        else:
-            partition_type = '0x0E'
-
-        BOOT_MIN_SIZE_S = align_up(128 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
-        ROOT_MIN_SIZE_S = align_up(128 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
-        SYSTEM_MIN_SIZE_S = align_up(256 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
-        CACHE_MIN_SIZE_S = align_up(256 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
-        USERDATA_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
-        SDCARD_MIN_SIZE_S = align_up(512 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
-
-        # align on sector 63 for compatibility with broken versions of x-loader
-        # unless align_boot_part is set
-        boot_align = 63
-        if should_align_boot_part:
-            boot_align = PART_ALIGN_S
-
-        # can only start on sector 1 (sector 0 is MBR / partition table)
-        boot_start, boot_end, boot_len = align_partition(
-            1, BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
-        # apparently OMAP3 ROMs require the vfat length to be an even number
-        # of sectors (multiple of 1 KiB); decrease the length if it's odd,
-        # there should still be enough room
-        boot_len = boot_len - boot_len % 2
-        boot_end = boot_start + boot_len - 1
-
-        root_start, _root_end, _root_len = align_partition(
-            boot_end + 1, ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
-        system_start, _system_end, _system_len = align_partition(
-            _root_end + 1, SYSTEM_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
-        cache_start, _cache_end, _cache_len = align_partition(
-            _system_end + 1, CACHE_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
-        userdata_start, _userdata_end, _userdata_len = align_partition(
-            _cache_end + 1, USERDATA_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
-        sdcard_start, _sdcard_end, _sdcard_len = align_partition(
-            _userdata_end + 1, SDCARD_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
-
-        return '%s,%s,%s,*\n%s,%s,L\n%s,%s,L\n%s,-,E\n%s,%s,L\n%s,%s,L\n%s,,,-' % (
-            boot_start, boot_len, partition_type, root_start, _root_len,
-            system_start, _system_len, cache_start, cache_start, _cache_len,
-            userdata_start, _userdata_len, sdcard_start)
-
     @classmethod
     def _get_bootcmd(cls, d_img_data):
         """Get the bootcmd for this board.
@@ -743,11 +695,6 @@ 
     'smdkv310': SMDKV310Config,
     }
 
-android_board_configs = {
-    'beagle': BeagleConfig,
-    'panda': PandaConfig,
-    }
-
 
 def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None,
         skip=None):

=== modified file 'linaro_image_tools/media_create/partitions.py'
--- linaro_image_tools/media_create/partitions.py	2011-04-05 11:06:49 +0000
+++ linaro_image_tools/media_create/partitions.py	2011-04-11 16:41:55 +0000
@@ -42,40 +42,28 @@ 
 
 
 def setup_android_partitions(board_config, media, bootfs_label,
-                     rootfs_label, rootfs_type, should_create_partitions,
-                     should_format_bootfs, should_format_rootfs,
-                     should_align_boot_part=False):
+                     should_create_partitions, should_align_boot_part=False):
     cylinders = None
 
     if should_create_partitions:
         create_partitions(
             board_config, media, HEADS, SECTORS, cylinders,
-            should_align_boot_part=should_align_boot_part, image_type="ANDROID")
+            should_align_boot_part=should_align_boot_part)
 
-    bootfs, rootfs, system, cache, data, sdcard = \
+    bootfs, system, cache, data, sdcard = \
         get_android_partitions_for_media (media, board_config)
     ensure_partition_is_not_mounted(bootfs)
-    ensure_partition_is_not_mounted(rootfs)
     ensure_partition_is_not_mounted(system)
     ensure_partition_is_not_mounted(cache)
     ensure_partition_is_not_mounted(data)
     ensure_partition_is_not_mounted(sdcard)
 
-    if should_format_bootfs:
-        print "\nFormating boot partition\n"
-        proc = cmd_runner.run(
-            ['mkfs.vfat', '-F', str(board_config.fat_size), bootfs, '-n',
-             bootfs_label],
-            as_root=True)
-        proc.wait()
-
-    if should_format_rootfs:
-        print "\nFormating root partition\n"
-        mkfs = 'mkfs.%s' % rootfs_type
-        proc = cmd_runner.run(
-            [mkfs, rootfs, '-L', rootfs_label],
-            as_root=True)
-        proc.wait()
+    print "\nFormating boot partition\n"
+    proc = cmd_runner.run(
+        ['mkfs.vfat', '-F', str(board_config.fat_size), bootfs, '-n',
+         bootfs_label],
+        as_root=True)
+    proc.wait()
 
     ext4_partitions = {"system": system, "cache": cache, "userdata": data}
     for label, dev in ext4_partitions.iteritems():
@@ -91,7 +79,7 @@ 
         as_root=True)
     proc.wait()
 
-    return bootfs, rootfs, system, cache, data, sdcard
+    return bootfs, system, cache, data, sdcard
 
 # I wonder if it'd make sense to convert this into a small shim which calls
 # the appropriate function for the given type of device?  I think it's still
@@ -277,22 +265,20 @@ 
 
     boot_partition = _get_device_file_for_partition_number(
         media.path, 1 + board_config.mmc_part_offset)
-    root_partition = _get_device_file_for_partition_number(
-        media.path, 2 + board_config.mmc_part_offset)
     system_partition = _get_device_file_for_partition_number(
+        media.path, 2 + board_config.mmc_part_offset)
+    cache_partition = _get_device_file_for_partition_number(
         media.path, 3 + board_config.mmc_part_offset)
-    cache_partition = _get_device_file_for_partition_number(
+    data_partition = _get_device_file_for_partition_number(
         media.path, 5 + board_config.mmc_part_offset)
-    data_partition = _get_device_file_for_partition_number(
+    sdcard_partition = _get_device_file_for_partition_number(
         media.path, 6 + board_config.mmc_part_offset)
-    sdcard_partition = _get_device_file_for_partition_number(
-        media.path, 7 + board_config.mmc_part_offset)
-
-    assert boot_partition is not None and root_partition is not None, (
-        "Could not find boot/root partition for %s" % media.path)
-
-    return boot_partition, root_partition, system_partition, \
-        cache_partition, data_partition, sdcard_partition
+
+    assert boot_partition is not None, (
+        "Could not find boot partition for %s" % media.path)
+
+    return boot_partition, system_partition, cache_partition, \
+        data_partition, sdcard_partition
 
 def get_boot_and_root_partitions_for_media(media, board_config):
     """Return the device files for the boot and root partitions of media.
@@ -388,7 +374,7 @@ 
 
 
 def create_partitions(board_config, media, heads, sectors, cylinders=None,
-                      should_align_boot_part=False, image_type=None):
+                      should_align_boot_part=False):
     """Partition the given media according to the board requirements.
 
     :param board_config: A BoardConfig class.
@@ -407,14 +393,8 @@ 
             ['parted', '-s', media.path, 'mklabel', 'msdos'], as_root=True)
         proc.wait()
 
-    # XXX: We should get rid of this by using separate config classes for
-    # android -- see comment in get_android_sfdisk_cmd() for more details.
-    if image_type == "ANDROID":
-        sfdisk_cmd = board_config.get_android_sfdisk_cmd(
-            should_align_boot_part=should_align_boot_part)
-    else:
-        sfdisk_cmd = board_config.get_sfdisk_cmd(
-            should_align_boot_part=should_align_boot_part)
+    sfdisk_cmd = board_config.get_sfdisk_cmd(
+        should_align_boot_part=should_align_boot_part)
 
     run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path)