diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 600: * Initial support for Arndale BL1 binary (samsung_bl0_*)

Message ID 20130115184813.2787.29651.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Fathi Boudra Jan. 15, 2013, 6:48 p.m. UTC
Merge authors:
  Fathi Boudra (fboudra)
Related merge proposals:
  https://code.launchpad.net/~fboudra/linaro-image-tools/initial-arndale-bl1-support/+merge/143023
  proposed by: Fathi Boudra (fboudra)
  review: Approve - Milo Casagrande (milo)
  review: Resubmit - Fathi Boudra (fboudra)
  https://code.launchpad.net/~fboudra/linaro-image-tools/samsung-variables-init/+merge/143019
  proposed by: Fathi Boudra (fboudra)
  review: Approve - Milo Casagrande (milo)
------------------------------------------------------------
revno: 600 [merge]
committer: Fathi Boudra <fathi.boudra@linaro.org>
branch nick: linaro-image-tools
timestamp: Tue 2013-01-15 20:45:34 +0200
message:
  * Initial support for Arndale BL1 binary (samsung_bl0_*)
    It assumes a pre-defined binary file. Long term, it should be a set of new
    keys to add in Arndale hardware pack configuration.
  * Add ethact/ethaddr to Arndale boot_env (LP: #1097265)
    Arndale board doesn't have a MAC address. To get network working out of
    the box, we define one in U-Boot environment.
modified:
  linaro_image_tools/media_create/boards.py
  linaro_image_tools/media_create/tests/test_media_create.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/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-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py	2013-01-09 09:22:50 +0000
+++ linaro_image_tools/media_create/boards.py	2013-01-14 14:56:31 +0000
@@ -188,16 +188,19 @@ 
         self.wireless_interfaces = None
         # Samsung Boot-loader implementation notes and terminology
         #
-        # * BL0, BL1 etc. are the various bootloaders in order of execution
-        # * BL0 is the first stage bootloader, located in ROM; it loads BL1/SPL
-        # from MMC offset +1s and runs it.
-        # * BL1 is the secondary program loader (SPL), a small version
-        #   of U-Boot with a checksum; it inits DRAM and loads a 1024s long BL2
-        #   from MMC and runs it.
-        # * BL2 is the U-Boot.
-        #
-        # samsung_bl1_{start,len}: Offset and maximum size for BL1
-        # samsung_bl2_{start,len}: Offset and maximum size for BL2
+        # BL0, BL1, BL2, BL3 are the boot loader stages in order of execution
+        #
+        # BL0 - embedded boot loader on the internal ROM
+        # BL1 - chip-specific boot loader provided by Samsung
+        # BL2 - tiny boot loader; SPL (Second Program Loader)
+        # BL3 - customized boot loader; U-Boot
+        #
+        # In linaro-image-tools, variables have been named samsung_blN-1
+        # e.g BL1 is samsung_bl0, BL2 is samsung_bl1, BL3 is samsung_bl2
+        #
+        # samsung_bl0_{start,len}: Offset and maximum size for BL1
+        # samsung_bl1_{start,len}: Offset and maximum size for BL2
+        # samsung_bl2_{start,len}: Offset and maximum size for BL3
         # samsung_env_{start,len}: Offset and maximum size for settings
         #
         self.samsung_bl1_start = 1
@@ -376,25 +379,33 @@ 
             samsung_bl1_start = self.get_metadata_field(
                 SAMSUNG_BL1_START_FIELD)
             if samsung_bl1_start:
-                self.samsung_v310_bl1_start = int(samsung_bl1_start)
-            samsung_bl1_len = self.get_metadata_field(SAMSUNG_BL1_LEN_FIELD)
+                self.samsung_bl1_start = int(samsung_bl1_start)
+
+            samsung_bl1_len = self.get_metadata_field(
+                SAMSUNG_BL1_LEN_FIELD)
             if samsung_bl1_len:
-                self.samsung_v310_bl1_len = int(samsung_bl1_len)
-            samsung_env_len = self.get_metadata_field(SAMSUNG_ENV_LEN_FIELD)
-            if samsung_env_len:
-                self.samsung_v310_env_len = int(samsung_env_len)
-            samsung_bl2_start = \
-                self.get_metadata_field(SAMSUNG_BL2_START_FIELD)
+                self.samsung_bl1_len = int(samsung_bl1_len)
+
+            samsung_bl2_start = self.get_metadata_field(
+                SAMSUNG_BL2_START_FIELD)
             if samsung_bl2_start:
                 self.samsung_bl2_start = int(samsung_bl2_start)
-            samsung_bl2_len = self.get_metadata_field(SAMSUNG_BL2_LEN_FIELD)
+
+            samsung_bl2_len = self.get_metadata_field(
+                SAMSUNG_BL2_LEN_FIELD)
             if samsung_bl2_len:
-                self.samsung_v310_bl2_len = int(samsung_bl2_len)
-            samsung_env_start = \
-                self.get_metadata_field(SAMSUNG_ENV_START_FIELD)
+                self.samsung_bl2_len = int(samsung_bl2_len)
+
+            samsung_env_start = self.get_metadata_field(
+                SAMSUNG_ENV_START_FIELD)
             if samsung_env_start is not None:
                 self.samsung_env_start = int(samsung_env_start)
 
+            samsung_env_len = self.get_metadata_field(
+                SAMSUNG_ENV_LEN_FIELD)
+            if samsung_env_len:
+                self.samsung_env_len = int(samsung_env_len)
+
             self.bootloader_copy_files = self.hardwarepack_handler.get_field(
                 "bootloader_copy_files")[0]
 
@@ -1563,20 +1574,81 @@ 
 class ArndaleConfig(SamsungConfig):
     def __init__(self):
         super(ArndaleConfig, self).__init__()
+        self.bl0_file = 'lib/firmware/arndale/arndale-bl1.bin'
         self.boot_script = 'boot.scr'
         self.bootloader_flavor = 'arndale'
-        self.dtb_addr = '0x41f00000'
-        self.initrd_addr = '0x42000000'
-        self.kernel_addr = '0x40007000'
         self.kernel_flavors = ['arndale']
-        self.load_addr = '0x40008000'
         self.mmc_option = '0:2'
         self.mmc_part_offset = 1
-        self.samsung_bl1_start = 17
-        self.samsung_bl2_start = 49
-        self.samsung_env_start = 1073
-        self.serial_tty = 'ttySAC2'
-        self._extra_serial_options = 'console=%s,115200n8'
+        self.samsung_bl0_start = 1
+        self.samsung_bl0_len = 16
+
+    def _get_boot_env(self, is_live, is_lowmem, consoles, rootfs_id,
+                      i_img_data, d_img_data):
+        boot_env = super(SamsungConfig, self)._get_boot_env(
+            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"
+
+        return boot_env
+
+    def _make_boot_files_v2(self, boot_env, chroot_dir, boot_dir,
+                            boot_device_or_file, k_img_data, i_img_data,
+                            d_img_data):
+        with self.hardwarepack_handler:
+            bl0_file = self._get_samsung_bl0(chroot_dir)
+            if self.samsung_bl0_start:
+                self._dd_file(bl0_file, boot_device_or_file,
+                              self.samsung_bl0_start)
+
+            spl_file = self.get_file('spl_file')
+            if self.spl_in_boot_part:
+                assert spl_file is not None, (
+                    "SPL binary could not be found")
+                logger.info(
+                    "Copying spl '%s' to boot partition." % spl_file)
+                cmd_runner.run(["cp", "-v", spl_file, boot_dir],
+                               as_root=True).wait()
+                # XXX: Is this really needed?
+                cmd_runner.run(["sync"]).wait()
+
+            if self.spl_dd:
+                self._dd_file(spl_file, boot_device_or_file, self.spl_dd)
+
+            bootloader_file = self.get_file('bootloader_file')
+            if self.bootloader_dd:
+                self._dd_file(bootloader_file, boot_device_or_file,
+                              self.bootloader_dd)
+
+        make_uImage(self.load_addr, k_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)
+
+        if self.boot_script is not None:
+            boot_script_path = os.path.join(boot_dir, self.boot_script)
+            make_boot_script(boot_env, boot_script_path)
+
+            # Only used for Omap, will this be bad for the other boards?
+            make_boot_ini(boot_script_path, boot_dir)
+
+        if self.env_dd:
+            # Do we need to zero out the env before flashing it?
+            _dd("/dev/zero", boot_device_or_file,
+                count=self.samsung_env_len,
+                seek=self.samsung_env_start)
+            env_size = self.samsung_env_len * SECTOR_SIZE
+            env_file = make_flashable_env(boot_env, env_size)
+            self._dd_file(env_file, boot_device_or_file,
+                          self.samsung_env_start)
+
+    def _get_samsung_bl0(self, chroot_dir):
+        bl0_file = os.path.join(chroot_dir, self.bl0_file)
+        return bl0_file
 
 
 class I386Config(BoardConfig):

=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
--- linaro_image_tools/media_create/tests/test_media_create.py	2013-01-09 09:22:50 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py	2013-01-15 18:45:34 +0000
@@ -31,6 +31,7 @@ 
 import struct
 import tarfile
 import dbus
+import shutil
 
 from mock import MagicMock
 from StringIO import StringIO
@@ -805,6 +806,57 @@ 
     config = boards.ArndaleConfig
 
 
+class TestArndaleBootFiles(TestCaseWithFixtures):
+    def test_arndale_make_boot_files_v2(self):
+        popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
+        board_conf = boards.ArndaleConfig()
+        board_conf.hwpack_format = HardwarepackHandler.FORMAT_1
+        board_conf.load_addr = '0x40008000'
+        board_conf.boot_script = None
+
+        board_conf.hardwarepack_handler = (
+            TestSetMetadata.MockHardwarepackHandler('ahwpack.tar.gz'))
+
+        self.tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
+        self.temp_bootdir_path = os.path.join(self.tempdir, 'boot')
+        self.temp_bl0_path = os.path.join(self.tempdir,
+                                          'lib', 'firmware', 'arndale')
+        k_img_file = os.path.join(self.tempdir, 'vmlinuz-1-arndale')
+        i_img_file = os.path.join(self.tempdir, 'initrd.img-1-arndale')
+        bl0_file = os.path.join(self.temp_bl0_path, 'arndale-bl1.bin')
+        os.makedirs(self.temp_bl0_path)
+        open(bl0_file, 'w').close()
+
+        boot_env = {'ethact': 'smc911x-0',
+                    'initrd_high': '0xffffffff',
+                    'ethaddr': '00:40:5c:26:0a:5b',
+                    'fdt_high': '0xffffffff',
+                    'bootcmd': 'fatload mmc 0:2 None uImage; bootm None',
+                    'bootargs': 'root=UUID=test_boot_env_uuid rootwait ro'}
+
+        board_conf._make_boot_files_v2(
+            boot_env=boot_env,
+            chroot_dir=self.tempdir,
+            boot_dir=self.temp_bootdir_path,
+            boot_device_or_file='boot_device_or_file',
+            k_img_data=k_img_file,
+            i_img_data=i_img_file,
+            d_img_data=None)
+
+        expected_commands = [
+            ('sudo -E dd if=%s of=boot_device_or_file bs=512 conv=notrunc '
+             'seek=1' % bl0_file),
+            ('sudo -E mkimage -A arm -O linux -T kernel -C none -a %s -e %s '
+             '-n Linux -d %s %s/uImage' % (board_conf.load_addr,
+             board_conf.load_addr, k_img_file, self.temp_bootdir_path)),
+            ('sudo -E mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 '
+             '-n initramfs -d %s %s/uInitrd' % (
+             i_img_file, self.temp_bootdir_path))]
+        self.assertEqual(expected_commands,
+                         popen_fixture.mock.commands_executed)
+        shutil.rmtree(self.tempdir)
+
+
 class TestCreateToc(TestCaseWithFixtures):
     ''' Tests boards.SnowballEmmcConfig.create_toc()'''
 
@@ -1977,6 +2029,22 @@ 
             'initrd_high': '0xffffffff'}
         self.assertEqual(expected, boot_commands)
 
+    def test_arndale(self):
+        board_conf = get_board_config('arndale')
+        boot_commands = board_conf._get_boot_env(
+            is_live=False, is_lowmem=False, consoles=[],
+            rootfs_id="UUID=deadbeef", i_img_data="initrd", d_img_data=None)
+        expected = {
+            'bootargs': 'root=UUID=deadbeef rootwait ro',
+            'bootcmd': 'fatload mmc 0:2 None uImage; '
+                       'fatload mmc 0:2 None uInitrd; '
+                       'bootm None None',
+                       'ethact': 'smc911x-0',
+                       'ethaddr': '00:40:5c:26:0a:5b',
+                       'fdt_high': '0xffffffff',
+                       'initrd_high': '0xffffffff'}
+        self.assertEqual(expected, boot_commands)
+
     def test_ux500(self):
         board_conf = get_board_config('ux500')
         boot_commands = board_conf._get_boot_env(