コード例 #1
0
ファイル: u_boot.py プロジェクト: Linaro/lava-dispatcher
    def validate(self):
        if 'media' not in self.job.device.get('parameters', []):
            return
        media_keys = self.job.device['parameters']['media'].keys()
        if self.parameters['commands'] not in list(media_keys):
            return
        super(UBootSecondaryMedia, self).validate()
        if 'kernel_type' not in self.parameters:
            self.errors = "Missing kernel_type for secondary media boot"
        self.logger.debug("Mapping kernel_type: %s", self.parameters['kernel_type'])
        bootcommand = map_kernel_uboot(self.parameters['kernel_type'], self.job.device.get('parameters', None))
        self.logger.debug("Using bootcommand: %s", bootcommand)
        self.set_namespace_data(
            action='uboot-prepare-kernel', label='kernel-type',
            key='kernel-type', value=self.parameters.get('kernel_type', ''))
        self.set_namespace_data(
            action='uboot-prepare-kernel', label='bootcommand', key='bootcommand', value=bootcommand)

        media_params = self.job.device['parameters']['media'][self.parameters['commands']]
        if self.get_namespace_data(action='storage-deploy', label='u-boot', key='device') not in media_params:
            self.errors = "%s does not match requested media type %s" % (
                self.get_namespace_data(
                    action='storage-deploy', label='u-boot', key='device'), self.parameters['commands']
            )
        if not self.valid:
            return
        self.set_namespace_data(
            action=self.name,
            label='uuid',
            key='boot_part',
            value='%s:%s' % (
                media_params[self.get_namespace_data(action='storage-deploy', label='u-boot', key='device')]['device_id'],
                self.parameters['boot_part']
            )
        )
コード例 #2
0
 def validate(self):
     super().validate()
     if 'parameters' not in self.job.device['actions']['deploy']:
         return
     self.params = self.job.device['actions']['deploy']['parameters']
     self.kernel_type = self.get_namespace_data(action='download-action',
                                                label='type',
                                                key='kernel')
     self.bootcommand = None
     if 'parameters' not in self.job.device:
         if self.kernel_type:
             self.errors = "Kernel boot type is not supported by this device."
     if self.kernel_type:
         self.set_namespace_data(action=self.name,
                                 label='prepared-kernel',
                                 key='exists',
                                 value=True)
         self.bootcommand = map_kernel_uboot(
             self.kernel_type, self.job.device.get('parameters'))
         self.kernel_type = str(self.kernel_type).lower()
         if self.bootcommand not in self.job.device['parameters']:
             self.errors = "Requested kernel boot type '%s' is not supported by this device." % self.bootcommand
         if self.kernel_type == "bootm" or self.kernel_type == "bootz" or self.kernel_type == "booti":
             self.errors = "booti, bootm and bootz are deprecated, please use 'image', 'uimage' or 'zimage'"
         which('mkimage')
         if 'mkimage_arch' not in self.params:
             self.errors = "Missing architecture for uboot mkimage support (mkimage_arch in u-boot parameters)"
         if self.bootcommand == 'bootm' and self.kernel_type != 'uimage':
             self.mkimage_conversion = True
     self.set_namespace_data(action='uboot-prepare-kernel',
                             label='bootcommand',
                             key='bootcommand',
                             value=self.bootcommand)
コード例 #3
0
ファイル: prepare.py プロジェクト: Linaro/lava-dispatcher
 def validate(self):
     super(UBootPrepareKernelAction, self).validate()
     if 'parameters' not in self.job.device['actions']['deploy']:
         return
     self.params = self.job.device['actions']['deploy']['parameters']
     self.kernel_type = self.get_namespace_data(
         action='download-action',
         label='type',
         key='kernel'
     )
     self.bootcommand = None
     if 'parameters' not in self.job.device:
         if self.kernel_type:
             self.errors = "Kernel boot type is not supported by this device."
     if self.kernel_type:
         self.set_namespace_data(action=self.name, label='prepared-kernel', key='exists', value=True)
         self.bootcommand = map_kernel_uboot(self.kernel_type, self.job.device.get('parameters', None))
         self.kernel_type = str(self.kernel_type).lower()
         if self.bootcommand not in self.job.device['parameters']:
             self.errors = "Requested kernel boot type '%s' is not supported by this device." % self.bootcommand
         if self.kernel_type == "bootm" or self.kernel_type == "bootz" or self.kernel_type == "booti":
             self.errors = "booti, bootm and bootz are deprecated, please use 'image', 'uimage' or 'zimage'"
         which('mkimage')
         if 'mkimage_arch' not in self.params:
             self.errors = "Missing architecture for uboot mkimage support (mkimage_arch in u-boot parameters)"
         if self.bootcommand == 'bootm' and self.kernel_type != 'uimage':
             self.mkimage_conversion = True
     self.set_namespace_data(
         action='uboot-prepare-kernel', label='bootcommand',
         key='bootcommand', value=self.bootcommand)
コード例 #4
0
    def validate(self):
        if "media" not in self.job.device.get("parameters", []):
            return
        media_keys = self.job.device["parameters"]["media"].keys()
        if self.parameters["commands"] not in list(media_keys):
            return
        super().validate()
        if "kernel_type" not in self.parameters:
            self.errors = "Missing kernel_type for secondary media boot"
        self.logger.debug("Mapping kernel_type: %s", self.parameters["kernel_type"])
        bootcommand = map_kernel_uboot(
            self.parameters["kernel_type"], self.job.device.get("parameters")
        )
        self.logger.debug("Using bootcommand: %s", bootcommand)
        self.set_namespace_data(
            action="uboot-prepare-kernel",
            label="kernel-type",
            key="kernel-type",
            value=self.parameters.get("kernel_type", ""),
        )
        self.set_namespace_data(
            action="uboot-prepare-kernel",
            label="bootcommand",
            key="bootcommand",
            value=bootcommand,
        )

        media_params = self.job.device["parameters"]["media"][
            self.parameters["commands"]
        ]
        if (
            self.get_namespace_data(
                action="storage-deploy", label="u-boot", key="device"
            )
            not in media_params
        ):
            self.errors = "%s does not match requested media type %s" % (
                self.get_namespace_data(
                    action="storage-deploy", label="u-boot", key="device"
                ),
                self.parameters["commands"],
            )
        if not self.valid:
            return
        self.set_namespace_data(
            action=self.name,
            label="uuid",
            key="boot_part",
            value="%s:%s"
            % (
                media_params[
                    self.get_namespace_data(
                        action="storage-deploy", label="u-boot", key="device"
                    )
                ]["device_id"],
                self.parameters["boot_part"],
            ),
        )
コード例 #5
0
ファイル: u_boot.py プロジェクト: yuhua-eric/lava
    def validate(self):
        if 'media' not in self.job.device.get('parameters', []):
            return
        media_keys = self.job.device['parameters']['media'].keys()
        if self.parameters['commands'] not in list(media_keys):
            return
        super().validate()
        if 'kernel_type' not in self.parameters:
            self.errors = "Missing kernel_type for secondary media boot"
        self.logger.debug("Mapping kernel_type: %s",
                          self.parameters['kernel_type'])
        bootcommand = map_kernel_uboot(self.parameters['kernel_type'],
                                       self.job.device.get('parameters'))
        self.logger.debug("Using bootcommand: %s", bootcommand)
        self.set_namespace_data(action='uboot-prepare-kernel',
                                label='kernel-type',
                                key='kernel-type',
                                value=self.parameters.get('kernel_type', ''))
        self.set_namespace_data(action='uboot-prepare-kernel',
                                label='bootcommand',
                                key='bootcommand',
                                value=bootcommand)

        media_params = self.job.device['parameters']['media'][
            self.parameters['commands']]
        if self.get_namespace_data(action='storage-deploy',
                                   label='u-boot',
                                   key='device') not in media_params:
            self.errors = "%s does not match requested media type %s" % (
                self.get_namespace_data(
                    action='storage-deploy', label='u-boot',
                    key='device'), self.parameters['commands'])
        if not self.valid:
            return
        self.set_namespace_data(
            action=self.name,
            label='uuid',
            key='boot_part',
            value='%s:%s' % (media_params[self.get_namespace_data(
                action='storage-deploy', label='u-boot',
                key='device')]['device_id'], self.parameters['boot_part']))
コード例 #6
0
 def validate(self):
     super().validate()
     if "parameters" not in self.job.device["actions"]["deploy"]:
         return
     self.params = self.job.device["actions"]["deploy"]["parameters"]
     self.kernel_type = self.get_namespace_data(action="download-action",
                                                label="type",
                                                key="kernel")
     self.bootcommand = None
     if "parameters" not in self.job.device:
         if self.kernel_type:
             self.errors = "Kernel boot type is not supported by this device."
     if self.kernel_type:
         self.set_namespace_data(action=self.name,
                                 label="prepared-kernel",
                                 key="exists",
                                 value=True)
         self.bootcommand = map_kernel_uboot(
             self.kernel_type, self.job.device.get("parameters"))
         self.kernel_type = str(self.kernel_type).lower()
         if self.bootcommand not in self.job.device["parameters"]:
             self.errors = (
                 "Requested kernel boot type '%s' is not supported by this device."
                 % self.bootcommand)
         if (self.kernel_type == "bootm" or self.kernel_type == "bootz"
                 or self.kernel_type == "booti"):
             self.errors = "booti, bootm and bootz are deprecated, please use 'image', 'uimage' or 'zimage'"
         which("mkimage")
         if "mkimage_arch" not in self.params:
             self.errors = "Missing architecture for uboot mkimage support (mkimage_arch in u-boot parameters)"
         if self.bootcommand == "bootm" and self.kernel_type != "uimage":
             self.mkimage_conversion = True
     self.set_namespace_data(
         action="uboot-prepare-kernel",
         label="bootcommand",
         key="bootcommand",
         value=self.bootcommand,
     )
コード例 #7
0
    def test_substitutions(self, which_mock):
        """
        Test substitution of secondary media values into u-boot commands

        Unlike most u-boot calls, removable knows in advance all the values it needs to substitute
        into the boot commands for the secondary deployment as these are fixed by the device config
        and the image details from the job submission.
        """
        job_parser = JobParser()
        (rendered, _) = self.factory.create_device("cubie1.jinja2")
        cubie = NewDevice(yaml_safe_load(rendered))
        sample_job_file = os.path.join(
            os.path.dirname(__file__), "sample_jobs/cubietruck-removable.yaml")
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(sample_job_data, cubie, 4212, None, "")
        job.logger = DummyLogger()
        job.validate()
        boot_params = [
            methods for methods in job.parameters["actions"]
            if "boot" in methods.keys()
        ][1]["boot"]
        self.assertIn("ramdisk", boot_params)
        self.assertIn("kernel", boot_params)
        self.assertIn("dtb", boot_params)
        self.assertIn("root_uuid", boot_params)
        self.assertIn("boot_part", boot_params)
        self.assertNotIn("type", boot_params)
        self.assertGreater(len(job.pipeline.actions), 1)
        self.assertIsNotNone(job.pipeline.actions[1].pipeline)
        u_boot_action = [
            action for action in job.pipeline.actions
            if action.name == "uboot-action"
        ][1]
        overlay = [
            action for action in u_boot_action.pipeline.actions
            if action.name == "bootloader-overlay"
        ][0]
        self.assertIsNotNone(
            overlay.get_namespace_data(action="storage-deploy",
                                       label="u-boot",
                                       key="device"))

        methods = cubie["actions"]["boot"]["methods"]
        self.assertIn("u-boot", methods)
        self.assertIn("usb", methods["u-boot"])
        self.assertIn("commands", methods["u-boot"]["usb"])
        commands_list = methods["u-boot"]["usb"]["commands"]
        device_id = u_boot_action.get_namespace_data(action="storage-deploy",
                                                     label="u-boot",
                                                     key="device")
        self.assertIsNotNone(device_id)
        kernel_type = u_boot_action.parameters["kernel_type"]
        bootcommand = map_kernel_uboot(kernel_type,
                                       device_params=cubie.get("parameters"))
        substitutions = {
            "{BOOTX}":
            "%s %s %s %s" % (
                bootcommand,
                cubie["parameters"][bootcommand]["kernel"],
                cubie["parameters"][bootcommand]["ramdisk"],
                cubie["parameters"][bootcommand]["dtb"],
            ),
            "{RAMDISK}":
            boot_params["ramdisk"],
            "{KERNEL}":
            boot_params["kernel"],
            "{DTB}":
            boot_params["dtb"],
            "{ROOT}":
            boot_params["root_uuid"],
            "{ROOT_PART}":
            "%s:%s" % (
                cubie["parameters"]["media"]["usb"][device_id]["device_id"],
                u_boot_action.parameters["boot_part"],
            ),
        }
        self.assertEqual("bootz 0x42000000 0x43300000 0x43000000",
                         substitutions["{BOOTX}"])
        self.assertEqual("/boot/initrd.img-3.16.0-4-armmp-lpae.u-boot",
                         substitutions["{RAMDISK}"])
        commands = substitute(commands_list, substitutions)
        print(commands)
        self.assertEqual(
            commands,
            [
                "usb start",
                "setenv autoload no",
                "load usb 0:0:1 {KERNEL_ADDR} /boot/vmlinuz-3.16.0-4-armmp-lpae",
                "load usb 0:0:1 {RAMDISK_ADDR} /boot/initrd.img-3.16.0-4-armmp-lpae.u-boot",
                "setenv initrd_size ${filesize}",
                "load usb 0:0:1 {DTB_ADDR} /boot/dtb-3.16.0-4-armmp-lpae",
                "console=ttyS0,115200n8 root=UUID=159d17cc-697c-4125-95a0-a3775e1deabe  ip=dhcp",
                "bootz 0x42000000 0x43300000 0x43000000",
            ],
        )
コード例 #8
0
ファイル: test_strings.py プロジェクト: iwamatsu/lava
def test_map_kernel_uboot():
    assert map_kernel_uboot("uimage", {}) == "bootm"
    assert map_kernel_uboot("zimage", {}) == "bootm"
    assert map_kernel_uboot("zimage", {"bootz": None}) == "bootz"
    assert map_kernel_uboot("image", {}) == "bootm"
    assert map_kernel_uboot("image", {"booti": None}) == "booti"
コード例 #9
0
    def test_substitutions(self):
        """
        Test substitution of secondary media values into u-boot commands

        Unlike most u-boot calls, removable knows in advance all the values it needs to substitute
        into the boot commands for the secondary deployment as these are fixed by the device config
        and the image details from the job submission.
        """
        job_parser = JobParser()
        cubie = NewDevice(
            os.path.join(os.path.dirname(__file__), '../devices/cubie1.yaml'))
        sample_job_file = os.path.join(
            os.path.dirname(__file__), 'sample_jobs/cubietruck-removable.yaml')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(sample_job_data, cubie, 4212, None, "")
        job.logger = DummyLogger()
        job.validate()
        boot_params = [
            methods for methods in job.parameters['actions']
            if 'boot' in methods.keys()
        ][1]['boot']
        self.assertIn('ramdisk', boot_params)
        self.assertIn('kernel', boot_params)
        self.assertIn('dtb', boot_params)
        self.assertIn('root_uuid', boot_params)
        self.assertIn('boot_part', boot_params)
        self.assertNotIn('type', boot_params)
        self.assertGreater(len(job.pipeline.actions), 1)
        self.assertIsNotNone(job.pipeline.actions[1].internal_pipeline)
        u_boot_action = [
            action for action in job.pipeline.actions
            if action.name == 'uboot-action'
        ][1]
        overlay = [
            action for action in u_boot_action.internal_pipeline.actions
            if action.name == 'bootloader-overlay'
        ][0]
        self.assertIsNotNone(
            overlay.get_namespace_data(action='storage-deploy',
                                       label='u-boot',
                                       key='device'))

        methods = cubie['actions']['boot']['methods']
        self.assertIn('u-boot', methods)
        self.assertIn('usb', methods['u-boot'])
        self.assertIn('commands', methods['u-boot']['usb'])
        commands_list = methods['u-boot']['usb']['commands']
        device_id = u_boot_action.get_namespace_data(action='storage-deploy',
                                                     label='u-boot',
                                                     key='device')
        self.assertIsNotNone(device_id)
        kernel_type = u_boot_action.parameters['kernel_type']
        bootcommand = map_kernel_uboot(kernel_type,
                                       device_params=cubie.get(
                                           'parameters', None))
        substitutions = {
            '{BOOTX}':
            "%s %s %s %s" % (
                bootcommand,
                cubie['parameters'][bootcommand]['kernel'],
                cubie['parameters'][bootcommand]['ramdisk'],
                cubie['parameters'][bootcommand]['dtb'],
            ),
            '{RAMDISK}':
            boot_params['ramdisk'],
            '{KERNEL}':
            boot_params['kernel'],
            '{DTB}':
            boot_params['dtb'],
            '{ROOT}':
            boot_params['root_uuid'],
            '{ROOT_PART}':
            "%s:%s" %
            (cubie['parameters']['media']['usb'][device_id]['device_id'],
             u_boot_action.parameters['boot_part'])
        }
        self.assertEqual('bootz 0x42000000 0x43300000 0x43000000',
                         substitutions['{BOOTX}'])
        self.assertEqual('/boot/initrd.img-3.16.0-4-armmp-lpae.u-boot',
                         substitutions['{RAMDISK}'])
        commands = substitute(commands_list, substitutions)
        self.assertEqual(commands, [
            'usb start', 'usb info', 'setenv autoload no',
            "setenv initrd_high '0xffffffff'", "setenv fdt_high '0xffffffff'",
            'setenv initrd_addr_r ${ramdisk_addr_r}',
            "setenv loadkernel 'load usb 0:1 ${kernel_addr_r} /boot/vmlinuz-3.16.0-4-armmp-lpae'",
            "setenv loadinitrd 'load usb 0:1 ${initrd_addr_r} /boot/initrd.img-3.16.0-4-armmp-lpae.u-boot; setenv initrd_size ${filesize}'",
            "setenv loadfdt 'load usb 0:1 ${fdt_addr_r} /boot/dtb-3.16.0-4-armmp-lpae'",
            "setenv bootargs 'console=ttyS0,115200n8 root=UUID=159d17cc-697c-4125-95a0-a3775e1deabe ip=dhcp'",
            "setenv bootcmd 'run loadkernel; run loadinitrd; run loadfdt; bootz 0x42000000 0x43300000 0x43000000'",
            'boot'
        ])
コード例 #10
0
    def test_substitutions(self):
        """
        Test substitution of secondary media values into u-boot commands

        Unlike most u-boot calls, removable knows in advance all the values it needs to substitute
        into the boot commands for the secondary deployment as these are fixed by the device config
        and the image details from the job submission.
        """
        job_parser = JobParser()
        cubie = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/cubie1.yaml'))
        sample_job_file = os.path.join(os.path.dirname(__file__), 'sample_jobs/cubietruck-removable.yaml')
        with open(sample_job_file) as sample_job_data:
            job = job_parser.parse(sample_job_data, cubie, 4212, None, "")
        job.logger = DummyLogger()
        job.validate()
        boot_params = [
            methods for methods in job.parameters['actions'] if 'boot' in methods.keys()][1]['boot']
        self.assertIn('ramdisk', boot_params)
        self.assertIn('kernel', boot_params)
        self.assertIn('dtb', boot_params)
        self.assertIn('root_uuid', boot_params)
        self.assertIn('boot_part', boot_params)
        self.assertNotIn('type', boot_params)
        self.assertGreater(len(job.pipeline.actions), 1)
        self.assertIsNotNone(job.pipeline.actions[1].internal_pipeline)
        u_boot_action = [action for action in job.pipeline.actions if action.name == 'uboot-action'][1]
        overlay = [action for action in u_boot_action.internal_pipeline.actions if action.name == 'bootloader-overlay'][0]
        self.assertIsNotNone(overlay.get_namespace_data(action='storage-deploy', label='u-boot', key='device'))

        methods = cubie['actions']['boot']['methods']
        self.assertIn('u-boot', methods)
        self.assertIn('usb', methods['u-boot'])
        self.assertIn('commands', methods['u-boot']['usb'])
        commands_list = methods['u-boot']['usb']['commands']
        device_id = u_boot_action.get_namespace_data(action='storage-deploy', label='u-boot', key='device')
        self.assertIsNotNone(device_id)
        kernel_type = u_boot_action.parameters['kernel_type']
        bootcommand = map_kernel_uboot(kernel_type, device_params=cubie.get('parameters', None))
        substitutions = {
            '{BOOTX}': "%s %s %s %s" % (
                bootcommand,
                cubie['parameters'][bootcommand]['kernel'],
                cubie['parameters'][bootcommand]['ramdisk'],
                cubie['parameters'][bootcommand]['dtb'],),
            '{RAMDISK}': boot_params['ramdisk'],
            '{KERNEL}': boot_params['kernel'],
            '{DTB}': boot_params['dtb'],
            '{ROOT}': boot_params['root_uuid'],
            '{ROOT_PART}': "%s:%s" % (
                cubie['parameters']['media']['usb'][device_id]['device_id'],
                u_boot_action.parameters['boot_part']
            )
        }
        self.assertEqual('bootz 0x42000000 0x43300000 0x43000000', substitutions['{BOOTX}'])
        self.assertEqual('/boot/initrd.img-3.16.0-4-armmp-lpae.u-boot', substitutions['{RAMDISK}'])
        commands = substitute(commands_list, substitutions)
        self.assertEqual(
            commands,
            [
                'usb start',
                'usb info',
                'setenv autoload no',
                "setenv initrd_high '0xffffffff'",
                "setenv fdt_high '0xffffffff'",
                'setenv initrd_addr_r ${ramdisk_addr_r}',
                "setenv loadkernel 'load usb 0:1 ${kernel_addr_r} /boot/vmlinuz-3.16.0-4-armmp-lpae'",
                "setenv loadinitrd 'load usb 0:1 ${initrd_addr_r} /boot/initrd.img-3.16.0-4-armmp-lpae.u-boot; setenv initrd_size ${filesize}'",
                "setenv loadfdt 'load usb 0:1 ${fdt_addr_r} /boot/dtb-3.16.0-4-armmp-lpae'",
                "setenv bootargs 'console=ttyS0,115200n8 root=UUID=159d17cc-697c-4125-95a0-a3775e1deabe ip=dhcp'",
                "setenv bootcmd 'run loadkernel; run loadinitrd; run loadfdt; bootz 0x42000000 0x43300000 0x43000000'", 'boot'
            ]
        )