def install_uboot(self, device): """ Flashes uboot to the given device, using dd. This method needs`, :attr:`uboot_file` to be already set. :attr:`uboot_spl` to be already set. :attr:`uboot_seek` to be already set. :attr:`uboot_bs` to be already set. :param device: Device where to flash UBL and uboot (i.e. '/dev/sdb'). :exception BoardError: On error. """ self._l.info('Installing uboot') cmd = ('sudo dd' + ' if=' + self._uboot_file + ' of=' + device + ' seek=' + self._uboot_seek + ' bs=' + self._uboot_bs ) #The default values are: seek=2 bs=512 if self._e.check_call(cmd) != 0: raise BoardError('Failed to flash uboot into %s' % device) if self._uboot_spl != None: cmd = ('sudo dd' + ' if=' + self._uboot_spl + ' of=' + device + ' seek=1 bs=1K') if self._e.check_call(cmd) != 0: raise BoardError('Failed to flash SPL into %s' % device)
def install_uboot_env(self, mount_point): """ Installs the uboot environment (uEnv.txt) to the given mount point. This methods needs :attr:`uboot_load_addr` and :attr:`workdir` to be already set. :param mount_point: Path where to install the uboot environment. :exception BoardError: On error. """ self._l.info('Installing uboot environment') uboot_load_addr = hexutils.str_to_hex(self._uboot_load_addr) uenv_file = os.path.join(self._workdir, "uEnv.txt") if not self._dryrun: with open(uenv_file, "w") as uenv: bootargs = 'bootargs=%s' % self._bootargs.strip() uenvcmd = ('uenvcmd=echo Running uenvcmd ...; run loaduimage; ' 'bootm %s' % uboot_load_addr) self._l.debug(" uEnv.txt <= '%s'" % bootargs) uenv.write("%s\n" % bootargs) self._l.debug(" uEnv.txt <= '%s'" % uenvcmd) uenv.write("%s\n" % uenvcmd) cmd = 'sudo cp %s %s' % (uenv_file, mount_point) if self._e.check_call(cmd) != 0: raise BoardError('Failed to install uboot env file.')
def install_sd_components(self, sd): """ Installs the specified components for each partition. :exception BoardError: On failure installing the components. """ i = 1 for part in sd.partitions: cmd = 'mount | grep %s | cut -f 3 -d " "' % sd.partition_name(i) output = self._e.check_output(cmd)[1] mount_point = output.replace('\n', '') for comp in part.components: if comp == SDCardPartition.COMPONENT_BOOTLOADER: self.install_uboot(mount_point) self.install_uboot_env(mount_point) elif comp == SDCardPartition.COMPONENT_KERNEL: self.install_kernel(mount_point) if self._kernel_devicetree: self.install_kernel_devicetree(mount_point) elif comp == SDCardPartition.COMPONENT_ROOTFS: self.install_rootfs(mount_point) else: raise BoardError('Invalid component: %s' % comp) i += 1
def install_uboot(self, mount_point): """ Copies the uboot min and uboot images to the given mount point. :param mount_point: Path where to install the uboot images. :exception BoardError: On error. """ self._l.info('Installing uboot') cmd = 'sudo cp %s %s/MLO' % (self._uboot_min_file, mount_point) if self._e.check_call(cmd) != 0: raise BoardError('Failed copying %s to %s' % (self._uboot_min_file, mount_point)) cmd = 'sudo cp %s %s/u-boot.bin' % (self._uboot_file, mount_point) if self._e.check_call(cmd) != 0: raise BoardError('Failed copying %s to %s' % (self._uboot_file, mount_point))
def install_rootfs(self, mount_point): """ If any, installs :attr:`rootfs` to the given mount point. :param mount_point: Path to where install rootfs. :exception BoardError: On error. """ if self._rootfs: self._l.info('Installing rootfs (this may take a while)') cmd = 'cd %s ; find . | sudo cpio -pdum %s' % (self._rootfs, mount_point) if self._e.check_call(cmd) != 0: raise BoardError('Failed installing rootfs ' 'into %s' % mount_point) if self._e.check_call('sync') != 0: raise BoardError('Unable to sync') else: self._l.warning('No directory for "%s", omitting...' % (SDCardPartition.COMPONENT_ROOTFS))
def install_usb_components(self, usb): """ Installs the specified components for each partition, as required in external (usb-script) mode. :exception BoardError: On failure installing the components. """ for part in usb.partitions: for comp in part.components: if comp == USBPartition.COMPONENT_BOOTLOADER: self.install_uboot(usb.name) else: raise BoardError('Invalid component: %s' % comp)
def install_ld_components_external(self, ld): """ Installs the specified components for each partition, as required in external (sd-script) mode. :exception BoardError: On failure installing the components. """ for part in ld.partitions: for comp in part.components: if comp == LoopDevicePartition.COMPONENT_BOOTLOADER: self.install_uboot(ld.name) else: raise BoardError('Invalid component: %s' % comp)
def install_kernel(self, mount_point): """ Installs the kernel image on the given mount point. This methods needs :attr:`kernel_image` to be already set. :param mount_point: Path to where install the kernel image. :exception BoardError: On error. """ self._l.info('Installing kernel') cmd = 'sudo cp %s %s/uImage' % (self._kernel_image, mount_point) if self._e.check_call(cmd) != 0: raise BoardError('Failed copying %s to %s' % (self._kernel_image, mount_point))
def install_ld_components_external(self, ld): """ Installs the specified components for each partition, as required in external (sd-script) mode. :exception BoardError: On failure installing the components. """ for part in ld.partitions: cmd = 'mount | grep %s | cut -f 3 -d " "' % part.device output = self._e.check_output(cmd)[1] mount_point = output.replace('\n', '') for comp in part.components: if comp == LoopDevicePartition.COMPONENT_BOOTLOADER: self.install_uboot(mount_point) else: raise BoardError('Invalid component: %s' % comp)
def install_uboot_env(self, mount_point): """ Installs the uboot environment (uEnv.txt) to the given mount point. :param mount_point: Path where to install the uboot environment. :exception BoardError: On error. """ self._l.info('Installing uboot environment') uenv_file = os.path.join(self._workdir, "uEnv.txt") if not self._dryrun: with open(uenv_file, "w") as uenv: bootargs = 'bootargs=%s' % self._bootargs.strip() self._l.debug(" uEnv.txt <= '%s'" % bootargs) uenv.write("%s\n" % bootargs) cmd = 'sudo cp %s %s' % (uenv_file, mount_point) if self._e.check_call(cmd) != 0: raise BoardError('Failed to install uboot env file.')
def install_uboot_bootscript(self, mount_point): """ Installs the uboot script (bootscript) to the given mount point. This methods needs :attr:`uboot_bootscript` to be already set. :param mount_point: Path where to install the uboot script. :exception BoardError: On error. """ if self._bootscript: self._l.info('Installing uboot script') cmd = 'sudo cp %s %s/' % (self._bootscript, mount_point) if self._e.check_call(cmd) != 0: raise BoardError('Failed copying %s to %s' % (self._bootscript, mount_point)) else: self._l.warning('No bootscript file, omitting...')
def install_uboot_env(self, mount_point): """ Installs the uboot environment (uEnv.txt) to the given mount point. This methods needs :attr:`uboot_load_addr` and :attr:`workdir` to be already set. :param mount_point: Path where to install the uboot environment. :exception BoardError: On error. """ self._l.info('Installing uboot environment') uboot_load_addr = hexutils.str_to_hex(self._uboot_load_addr) uenv_file = os.path.join(self._workdir, "uEnv.txt") if not self._dryrun: with open(uenv_file, "w") as uenv: bootargs = 'bootargs=%s' % self._bootargs.strip() if self._kernel_tftp: loadtftpimage = 'loadtftpimage=%s'% self._tftp_loader.get_env_load_file_to_ram( self._kernel_image, uboot_load_addr) self._l.debug(" uEnv.txt <= '%s'" % loadtftpimage) uenv.write("%s\n" % loadtftpimage) kernel_load = 'run loadtftpimage' else: kernel_load = 'run loaduimage' uenvcmd = ('uenvcmd=echo Running uenvcmd ...; %s; ' % kernel_load) if self._kernel_devicetree: uenvcmd = uenvcmd + ' run loadfdt; bootm ${loadaddr} - ${fdt_addr}' else: uenvcmd = uenvcmd + ' bootm' self._l.debug(" uEnv.txt <= '%s'" % bootargs) uenv.write("%s\n" % bootargs) self._l.debug(" uEnv.txt <= 'autostart=no") uenv.write("autostart=no\n") self._l.debug(" uEnv.txt <= '%s'" % uenvcmd) uenv.write("%s\n" % uenvcmd) cmd = 'sudo cp %s %s' % (uenv_file, mount_point) if self._e.check_call(cmd) != 0: raise BoardError('Failed to install uboot env file.')
def install_ld_components(self, ld): """ Installs the specified components for each partition. :exception BoardError: On failure installing the components. """ for part in ld.partitions: cmd = 'mount | grep %s | cut -f 3 -d " "' % part.device output = self._e.check_output(cmd)[1] mount_point = output.replace('\n', '') for comp in part.components: if comp == LoopDevicePartition.COMPONENT_BOOTLOADER: self.install_uboot(ld.name) self.install_uboot_env(mount_point) elif comp == LoopDevicePartition.COMPONENT_KERNEL: self.install_kernel(mount_point) elif comp == LoopDevicePartition.COMPONENT_ROOTFS: self.install_rootfs(mount_point) else: raise BoardError('Invalid component: %s' % comp)
def install_uboot(self, device): """ Flashes UBL and uboot to the given device, using the uflash tool. This method needs :attr:`uflash_bin`, :attr:`ubl_file`, :attr:`uboot_file`, :attr:`uboot_entry_addr`, and :attr:`uboot_load_addr` to be already set. :param device: Device where to flash UBL and uboot (i.e. '/dev/sdb'). :exception BoardError: On error. """ uboot_load_addr = hexutils.str_to_hex(self._uboot_load_addr) uboot_entry_addr = hexutils.str_to_hex(self._uboot_entry_addr) self._l.info('Installing uboot') cmd = ('sudo ' + self._uflash_bin + ' -d ' + device + ' -b ' + self._uboot_file + ' -e ' + uboot_entry_addr + ' -l ' + uboot_load_addr) if self._e.check_call(cmd) != 0: raise BoardError('Failed to flash UBL and uboot into %s' % device)
def default(self): """Return default board. BoardError if none.""" self._check_status() if not self._default_board: raise BoardError("No default board") return self._default_board