blob: 78d3301bc10e88891536813525095679c4bfd9c5 [file] [log] [blame]
Simon Glass48bca842022-01-09 20:13:56 -07001# SPDX-License-Identifier: GPL-2.0+
2# Copyright 2022 Google LLC
3#
4"""Bintool implementation for mkimage"""
5
6import re
7
8from binman import bintool
9
10class Bintoolmkimage(bintool.Bintool):
11 """Image generation for U-Boot
12
13 This bintool supports running `mkimage` with some basic parameters as
Marek Vasutbb3354e2024-04-26 00:54:08 +020014 needed by binman.
Simon Glass48bca842022-01-09 20:13:56 -070015
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 Schulz21811f62022-09-01 17:51:39 +020021 super().__init__(name, 'Generate image for U-Boot', r'mkimage version (.*)')
Simon Glass48bca842022-01-09 20:13:56 -070022
23 # pylint: disable=R0913
24 def run(self, reset_timestamp=False, output_fname=None, external=False,
Alexander Kochetkova730a282024-09-16 11:24:46 +030025 pad=None, align=None, priv_keys_dir=None):
Simon Glass48bca842022-01-09 20:13:56 -070026 """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 Karlmanc59ea892023-01-21 19:01:39 +000036 align: Bytes to use for alignment of the FIT and its external data
Alexander Kochetkova730a282024-09-16 11:24:46 +030037 priv_keys_dir: Path to directory containing private keys
Simon Glass48bca842022-01-09 20:13:56 -070038 version: True to get the mkimage version
39 """
40 args = []
41 if external:
42 args.append('-E')
43 if pad:
44 args += ['-p', f'{pad:x}']
Jonas Karlmanc59ea892023-01-21 19:01:39 +000045 if align:
46 args += ['-B', f'{align:x}']
Simon Glass48bca842022-01-09 20:13:56 -070047 if reset_timestamp:
48 args.append('-t')
Alexander Kochetkova730a282024-09-16 11:24:46 +030049 if priv_keys_dir:
50 args += ['-k', f'{priv_keys_dir}']
Simon Glass48bca842022-01-09 20:13:56 -070051 if output_fname:
52 args += ['-F', output_fname]
Simon Glass48bca842022-01-09 20:13:56 -070053 return self.run_cmd(*args)
54
55 def fetch(self, method):
56 """Fetch handler for mkimage
57
58 This installs mkimage using the apt utility.
59
60 Args:
61 method (FETCH_...): Method to use
62
63 Returns:
64 True if the file was fetched and now installed, None if a method
65 other than FETCH_BIN was requested
66
67 Raises:
68 Valuerror: Fetching could not be completed
69 """
70 if method != bintool.FETCH_BIN:
71 return None
72 return self.apt_install('u-boot-tools')