Simon Glass | 48bca84 | 2022-01-09 20:13:56 -0700 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
| 2 | # Copyright 2022 Google LLC |
| 3 | # |
| 4 | """Bintool implementation for mkimage""" |
| 5 | |
| 6 | import re |
| 7 | |
| 8 | from binman import bintool |
| 9 | |
| 10 | class Bintoolmkimage(bintool.Bintool): |
| 11 | """Image generation for U-Boot |
| 12 | |
| 13 | This bintool supports running `mkimage` with some basic parameters as |
Marek Vasut | bb3354e | 2024-04-26 00:54:08 +0200 | [diff] [blame] | 14 | needed by binman. |
Simon Glass | 48bca84 | 2022-01-09 20:13:56 -0700 | [diff] [blame] | 15 | |
| 16 | Normally binman uses the mkimage built by U-Boot. But when run outside the |
| 17 | U-Boot build system, binman can use the version installed in your system. |
| 18 | Support is provided for fetching this on Debian-like systems, using apt. |
| 19 | """ |
| 20 | def __init__(self, name): |
Quentin Schulz | 21811f6 | 2022-09-01 17:51:39 +0200 | [diff] [blame] | 21 | super().__init__(name, 'Generate image for U-Boot', r'mkimage version (.*)') |
Simon Glass | 48bca84 | 2022-01-09 20:13:56 -0700 | [diff] [blame] | 22 | |
| 23 | # pylint: disable=R0913 |
| 24 | def run(self, reset_timestamp=False, output_fname=None, external=False, |
Jonas Karlman | c59ea89 | 2023-01-21 19:01:39 +0000 | [diff] [blame] | 25 | pad=None, align=None): |
Simon Glass | 48bca84 | 2022-01-09 20:13:56 -0700 | [diff] [blame] | 26 | """Run mkimage |
| 27 | |
| 28 | Args: |
| 29 | reset_timestamp: True to update the timestamp in the FIT |
| 30 | output_fname: Output filename to write to |
| 31 | external: True to create an 'external' FIT, where the binaries are |
| 32 | located outside the main data structure |
| 33 | pad: Bytes to use for padding the FIT devicetree output. This allows |
| 34 | other things to be easily added later, if required, such as |
| 35 | signatures |
Jonas Karlman | c59ea89 | 2023-01-21 19:01:39 +0000 | [diff] [blame] | 36 | align: Bytes to use for alignment of the FIT and its external data |
Simon Glass | 48bca84 | 2022-01-09 20:13:56 -0700 | [diff] [blame] | 37 | version: True to get the mkimage version |
| 38 | """ |
| 39 | args = [] |
| 40 | if external: |
| 41 | args.append('-E') |
| 42 | if pad: |
| 43 | args += ['-p', f'{pad:x}'] |
Jonas Karlman | c59ea89 | 2023-01-21 19:01:39 +0000 | [diff] [blame] | 44 | if align: |
| 45 | args += ['-B', f'{align:x}'] |
Simon Glass | 48bca84 | 2022-01-09 20:13:56 -0700 | [diff] [blame] | 46 | if reset_timestamp: |
| 47 | args.append('-t') |
| 48 | if output_fname: |
| 49 | args += ['-F', output_fname] |
Simon Glass | 48bca84 | 2022-01-09 20:13:56 -0700 | [diff] [blame] | 50 | return self.run_cmd(*args) |
| 51 | |
| 52 | def fetch(self, method): |
| 53 | """Fetch handler for mkimage |
| 54 | |
| 55 | This installs mkimage using the apt utility. |
| 56 | |
| 57 | Args: |
| 58 | method (FETCH_...): Method to use |
| 59 | |
| 60 | Returns: |
| 61 | True if the file was fetched and now installed, None if a method |
| 62 | other than FETCH_BIN was requested |
| 63 | |
| 64 | Raises: |
| 65 | Valuerror: Fetching could not be completed |
| 66 | """ |
| 67 | if method != bintool.FETCH_BIN: |
| 68 | return None |
| 69 | return self.apt_install('u-boot-tools') |