~milo/lava-dispatcher/tar-repo

« back to all changes in this revision

Viewing changes to lava_dispatcher/device/fastmodel.py

UEFI support for Fastmodels. Add interactive bootloader support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    ensure_directory,
49
49
    extract_targz,
50
50
    DrainConsoleOutput,
 
51
    string_to_list,
51
52
    )
52
53
 
53
54
 
68
69
        self._dtb = None
69
70
        self._initrd = None
70
71
        self._uefi = None
 
72
        self._bootloader = 'u_boot'
71
73
 
72
74
    def _customize_android(self):
73
75
        with image_partition_mounted(self._sd_image, self.DATA_PARTITION) as d:
92
94
 
93
95
    def _copy_needed_files_from_directory(self, subdir):
94
96
        odir = os.path.dirname(self._sd_image)
95
 
 
96
 
        if self._axf is None:
 
97
        if self._bootloader == 'u_boot':
 
98
            # Extract the bootwrapper from the image
97
99
            for fname in self.config.simulator_axf_files:
98
 
                src = os.path.join(subdir, fname)
99
 
                if os.path.exists(src):
100
 
                    self._axf = '%s/%s' % (odir, os.path.split(src)[1])
101
 
                    if src != self._axf:
102
 
                        shutil.copyfile(src, self._axf)
 
100
                if self._axf is None:
 
101
                    self._axf = self._find_and_copy(
 
102
                                   subdir, odir, fname)
 
103
                else:
103
104
                    break
104
 
 
105
 
        if self.config.simulator_kernel:
106
 
            self._copy_boot_files_from_directory(odir, subdir)
107
 
 
108
 
    def _copy_boot_files_from_directory(self, odir, subdir):
109
 
        # TODO: Optimize this loop
110
 
        for root, dirs, files in os.walk(subdir):
111
 
              for file in files:
112
 
                  if re.match(self.config.simulator_kernel, file) and self._kernel is None:
113
 
                      self._kernel = os.path.join(odir, file)
114
 
                      if odir != subdir:                         
115
 
                          kernel = os.path.join(subdir, file)
116
 
                          shutil.copyfile(kernel, self._kernel)
117
 
                  elif re.match(self.config.simulator_initrd, file) and self._initrd is None:
118
 
                      self._initrd = os.path.join(odir, file)
119
 
                      if odir != subdir:
120
 
                          initrd = os.path.join(subdir, file)
121
 
                          shutil.copyfile(initrd, self._initrd)
122
 
                  elif re.match(self.config.simulator_dtb, file) and self._dtb is None:
123
 
                      self._dtb = os.path.join(odir, file)
124
 
                      if odir != subdir:
125
 
                          dtb = os.path.join(subdir, file)
126
 
                          shutil.copyfile(dtb, self._dtb) 
127
 
                  elif re.match(self.config.simulator_uefi, file) and self._uefi is None:
128
 
                      self._uefi = os.path.join(odir, file)
129
 
                      if odir != subdir:
130
 
                          uefi = os.path.join(subdir, file)
131
 
                          shutil.copyfile(uefi, self._uefi)
 
105
            # Extract the kernel from the image
 
106
            if self.config.simulator_kernel and self._kernel is None:
 
107
                self._kernel = self._find_and_copy(
 
108
                                   subdir, odir, self.config.simulator_kernel)
 
109
            # Extract the initrd from the image
 
110
            if self.config.simulator_initrd and self._initrd is None:
 
111
                self._initrd = self._find_and_copy(
 
112
                                   subdir, odir, self.config.simulator_initrd)
 
113
            # Extract the dtb from the image
 
114
            if self.config.simulator_dtb and self._dtb is None:
 
115
                self._dtb = self._find_and_copy(
 
116
                                subdir, odir, self.config.simulator_dtb)
 
117
        elif self._bootloader == 'uefi':
 
118
            # Extract the uefi binary from the image
 
119
            if self.config.simulator_uefi and self._uefi is None:
 
120
                self._uefi = self._find_and_copy(
 
121
                                 subdir, odir, self.config.simulator_uefi)
132
122
 
133
123
    def _check_needed_files(self):
134
 
        # AXF is needed in all cases
135
 
        if not self._axf:
136
 
            raise RuntimeError('No AXF found, %r' %
137
 
                               self.config.simulator_axf_files)
138
 
        # Kernel is needed only for b.L models
139
 
        if self._kernel is None and self.config.simulator_kernel:
140
 
            raise RuntimeError('No kernel found, %r' %
141
 
                               self.config.simulator_kernel)
142
 
        # Initrd is needed only for b.L models
143
 
        if self._initrd is None and self.config.simulator_initrd:
144
 
            raise RuntimeError('No initrd found, %r' %
145
 
                               self.config.simulator_initrd)
146
 
        # DTB is needed only for b.L models
147
 
        if self._dtb is None and self.config.simulator_dtb:
148
 
            raise RuntimeError('No initrd found, %r' %
149
 
                               self.config.simulator_dtb)
 
124
        if self._bootloader == 'u_boot':
 
125
            # AXF is needed when we are not using UEFI
 
126
            if self._axf is None and self.config.simulator_axf_files:
 
127
                raise RuntimeError('No AXF found, %r' %
 
128
                                   self.config.simulator_axf_files)
 
129
            # Kernel is needed only for b.L models
 
130
            if self._kernel is None and self.config.simulator_kernel:
 
131
                raise RuntimeError('No KERNEL found, %r' %
 
132
                                   self.config.simulator_kernel)
 
133
            # Initrd is needed only for b.L models
 
134
            if self._initrd is None and self.config.simulator_initrd:
 
135
                raise RuntimeError('No INITRD found, %r' %
 
136
                                   self.config.simulator_initrd)
 
137
            # DTB is needed only for b.L models
 
138
            if self._dtb is None and self.config.simulator_dtb:
 
139
                raise RuntimeError('No DTB found, %r' %
 
140
                                   self.config.simulator_dtb)
 
141
        elif self._bootloader == 'uefi':
 
142
            # UEFI binary is needed when specified
 
143
            if self._uefi is None and self.config.simulator_uefi:
 
144
                raise RuntimeError('No UEFI binary found, %r' %
 
145
                                   self.config.simulator_uefi)
150
146
 
151
147
    def deploy_android(self, boot, system, data):
152
148
        logging.info("Deploying Android on %s" % self.config.hostname)
170
166
        rootfs = download_image(rootfs, self.context, decompress=False)
171
167
        odir = os.path.dirname(rootfs)
172
168
 
 
169
        self._bootloader = bootloader
 
170
 
173
171
        generate_fastmodel_image(self.context, hwpack, rootfs, odir, bootloader)
174
172
        self._sd_image = '%s/sd.img' % odir
175
173
 
210
208
        d = os.path.dirname(self._sd_image)
211
209
        os.chmod(d, stat.S_IRWXG | stat.S_IRWXU)
212
210
        os.chmod(self._sd_image, stat.S_IRWXG | stat.S_IRWXU)
213
 
        os.chmod(self._axf, stat.S_IRWXG | stat.S_IRWXU)
 
211
        if self._axf:
 
212
            os.chmod(self._axf, stat.S_IRWXG | stat.S_IRWXU)
214
213
        if self._kernel:
215
214
            os.chmod(self._kernel, stat.S_IRWXG | stat.S_IRWXU)
 
215
        if self._initrd:
 
216
            os.chmod(self._initrd, stat.S_IRWXG | stat.S_IRWXU)
216
217
        if self._dtb:
217
218
            os.chmod(self._dtb, stat.S_IRWXG | stat.S_IRWXU)
218
 
        if self._initrd:
219
 
            os.chmod(self._initrd, stat.S_IRWXG | stat.S_IRWXU)
220
219
        if self._uefi:
221
220
            os.chmod(self._uefi, stat.S_IRWXG | stat.S_IRWXU)
222
221
 
223
222
        #lmc ignores the parent directories group owner
224
223
        st = os.stat(d)
225
 
        os.chown(self._axf, st.st_uid, st.st_gid)
226
224
        os.chown(self._sd_image, st.st_uid, st.st_gid)
 
225
        if self._axf:
 
226
            os.chown(self._axf, st.st_uid, st.st_gid)
227
227
        if self._kernel:
228
228
            os.chown(self._kernel, st.st_uid, st.st_gid)
 
229
        if self._initrd:
 
230
            os.chown(self._initrd, st.st_uid, st.st_gid)
229
231
        if self._dtb:
230
232
            os.chown(self._dtb, st.st_uid, st.st_gid)
231
 
        if self._initrd:
232
 
            os.chown(self._initrd, st.st_uid, st.st_gid)
233
233
        if self._uefi:
234
234
            os.chown(self._uefi, st.st_uid, st.st_gid)
235
235
 
 
236
    def _enter_bootloader(self):
 
237
        if self.proc.expect(self.config.interrupt_boot_prompt) != 0:
 
238
            raise Exception("Failed to enter bootloader")
 
239
        self.proc.sendline(self.config.interrupt_boot_command)
 
240
 
236
241
    def power_off(self, proc):
237
242
        super(FastModelTarget, self).power_off(proc)
238
243
        if self._sim_proc is not None:
263
268
        self._fix_perms()
264
269
 
265
270
        options = boot_options.as_string(self, join_pattern=' -C %s=%s')
 
271
 
 
272
        if self.config.simulator_boot_wrapper and self._uefi is None:
 
273
            options = '%s %s' % (self.config.simulator_boot_wrapper, options)
 
274
 
266
275
        sim_cmd = '%s %s' % (self.config.simulator_command, options)
267
276
        sim_cmd = sim_cmd.format(
268
277
            AXF=self._axf, IMG=self._sd_image, KERNEL=self._kernel,
289
298
            timeout=1200)
290
299
        self.proc.logfile_read = self._create_rtsm_ostream(
291
300
            self.proc.logfile_read)
 
301
 
 
302
        if self._uefi:
 
303
            self._enter_bootloader()
 
304
            self._customize_bootloader()
 
305
 
292
306
        return self.proc
293
307
 
294
308
    def get_test_data_attachments(self):