-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpython3.patch
More file actions
executable file
·337 lines (307 loc) · 15.4 KB
/
python3.patch
File metadata and controls
executable file
·337 lines (307 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
From 3d6dc4971e2a60f091a349299f2c056d1cd7f725 Mon Sep 17 00:00:00 2001
From: Paskal Sitepu <rmnscnce@ya.ru>
Date: Tue, 29 Aug 2023 16:41:21 +0700
Subject: [PATCH] scripts: Makefile.lib: Drop python2 requirement for mkdtimg
This also updates the mkdtboimg.py to the latest one found in [1]
[1]: https://android.googlesource.com/platform/system/libufdt/+/cccfce249bbc1d7b87786f1426c7c75fbbfd70e8/utils/src/mkdtboimg.py
Signed-off-by: Paskal Sitepu <rmnscnce@ya.ru>
---
scripts/Makefile.lib | 2 +-
scripts/dtc/libfdt/mkdtboimg.py | 121 ++++++++++++++++++++++----------
2 files changed, 86 insertions(+), 37 deletions(-)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 405fc5a37150..2eb94c9e08fb 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -332,7 +332,7 @@ dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
# mkdtimg
#----------------------------------------------------------------------------
quiet_cmd_mkdtimg = DTBOIMG $@
-cmd_mkdtimg = python2 $(srctree)/scripts/dtc/libfdt/mkdtboimg.py create $@ --page_size=4096 $(filter-out FORCE,$^)
+cmd_mkdtimg = python3 $(srctree)/scripts/dtc/libfdt/mkdtboimg.py create $@ --page_size=4096 $(filter-out FORCE,$^)
# cat
diff --git a/scripts/dtc/libfdt/mkdtboimg.py b/scripts/dtc/libfdt/mkdtboimg.py
index 03f0fd1b727b..5eeb5ea08a55 100644
--- a/scripts/dtc/libfdt/mkdtboimg.py
+++ b/scripts/dtc/libfdt/mkdtboimg.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
# Copyright 2017, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,12 +18,13 @@
"""Tool for packing multiple DTB/DTBO files into a single image"""
import argparse
+import fnmatch
import os
+import struct
+import zlib
from array import array
from collections import namedtuple
-import struct
from sys import stdout
-import zlib
class CompressionFormat(object):
"""Enum representing DT compression format for a DT entry.
@@ -36,14 +37,18 @@ class DtEntry(object):
"""Provides individual DT image file arguments to be added to a DTBO.
Attributes:
- _REQUIRED_KEYS: 'keys' needed to be present in the dictionary passed to instantiate
- an object of this class.
- _COMPRESSION_FORMAT_MASK: Mask to retrieve compression info for DT entry from flags field
+ REQUIRED_KEYS_V0: 'keys' needed to be present in the dictionary passed to instantiate
+ an object of this class when a DTBO header of version 0 is used.
+ REQUIRED_KEYS_V1: 'keys' needed to be present in the dictionary passed to instantiate
+ an object of this class when a DTBO header of version 1 is used.
+ COMPRESSION_FORMAT_MASK: Mask to retrieve compression info for DT entry from flags field
when a DTBO header of version 1 is used.
"""
- _COMPRESSION_FORMAT_MASK = 0x0f
- REQUIRED_KEYS = ('dt_file', 'dt_size', 'dt_offset', 'id', 'rev', 'flags',
- 'custom0', 'custom1', 'custom2')
+ COMPRESSION_FORMAT_MASK = 0x0f
+ REQUIRED_KEYS_V0 = ('dt_file', 'dt_size', 'dt_offset', 'id', 'rev',
+ 'custom0', 'custom1', 'custom2', 'custom3')
+ REQUIRED_KEYS_V1 = ('dt_file', 'dt_size', 'dt_offset', 'id', 'rev',
+ 'flags', 'custom0', 'custom1', 'custom2')
@staticmethod
def __get_number_or_prop(arg):
@@ -82,7 +87,14 @@ class members with. Expected keys in dictionary are from
the tuple (_REQUIRED_KEYS)
"""
- missing_keys = set(self.REQUIRED_KEYS) - set(kwargs)
+ self.__version = kwargs['version']
+ required_keys = None
+ if self.__version == 0:
+ required_keys = self.REQUIRED_KEYS_V0
+ elif self.__version == 1:
+ required_keys = self.REQUIRED_KEYS_V1
+
+ missing_keys = set(required_keys) - set(kwargs)
if missing_keys:
raise ValueError('Missing keys in DtEntry constructor: %r' %
sorted(missing_keys))
@@ -92,10 +104,13 @@ class members with. Expected keys in dictionary are from
self.__dt_size = kwargs['dt_size']
self.__id = self.__get_number_or_prop(kwargs['id'])
self.__rev = self.__get_number_or_prop(kwargs['rev'])
- self.__flags = self.__get_number_or_prop(kwargs['flags'])
+ if self.__version == 1:
+ self.__flags = self.__get_number_or_prop(kwargs['flags'])
self.__custom0 = self.__get_number_or_prop(kwargs['custom0'])
self.__custom1 = self.__get_number_or_prop(kwargs['custom1'])
self.__custom2 = self.__get_number_or_prop(kwargs['custom2'])
+ if self.__version == 0:
+ self.__custom3 = self.__get_number_or_prop(kwargs['custom3'])
def __str__(self):
sb = []
@@ -107,26 +122,30 @@ def __str__(self):
value=self.__id))
sb.append('{key:>20} = {value:08x}'.format(key='rev',
value=self.__rev))
+ if self.__version == 1:
+ sb.append('{key:>20} = {value:08x}'.format(key='flags',
+ value=self.__flags))
sb.append('{key:>20} = {value:08x}'.format(key='custom[0]',
- value=self.__flags))
- sb.append('{key:>20} = {value:08x}'.format(key='custom[1]',
value=self.__custom0))
- sb.append('{key:>20} = {value:08x}'.format(key='custom[2]',
+ sb.append('{key:>20} = {value:08x}'.format(key='custom[1]',
value=self.__custom1))
- sb.append('{key:>20} = {value:08x}'.format(key='custom[3]',
+ sb.append('{key:>20} = {value:08x}'.format(key='custom[2]',
value=self.__custom2))
+ if self.__version == 0:
+ sb.append('{key:>20} = {value:08x}'.format(key='custom[3]',
+ value=self.__custom3))
return '\n'.join(sb)
- def compression_info(self, version):
+ def compression_info(self):
"""CompressionFormat: compression format for DT image file.
Args:
version: Version of DTBO header, compression is only
supported from version 1.
"""
- if version is 0:
+ if self.__version == 0:
return CompressionFormat.NO_COMPRESSION
- return self.flags & self._COMPRESSION_FORMAT_MASK
+ return self.flags & self.COMPRESSION_FORMAT_MASK
@property
def dt_file(self):
@@ -181,6 +200,10 @@ def custom2(self):
"""int: DT entry custom2 for this DT image."""
return self.__custom2
+ @property
+ def custom3(self):
+ """int: DT entry custom3 for this DT image."""
+ return self.__custom3
class Dtbo(object):
"""
@@ -232,10 +255,17 @@ def _update_dt_entry_header(self, dt_entry, metadata_offset):
dtbo_offset: Offset where the DT image file for this dt_entry can
be found in the resulting DTBO image.
"""
- struct.pack_into('>8I', self.__metadata, metadata_offset, dt_entry.size,
- dt_entry.dt_offset, dt_entry.image_id, dt_entry.rev,
- dt_entry.flags, dt_entry.custom0, dt_entry.custom1,
- dt_entry.custom2)
+ if self.version == 0:
+ struct.pack_into('>8I', self.__metadata, metadata_offset, dt_entry.size,
+ dt_entry.dt_offset, dt_entry.image_id, dt_entry.rev,
+ dt_entry.custom0, dt_entry.custom1, dt_entry.custom2,
+ dt_entry.custom3)
+ elif self.version == 1:
+ struct.pack_into('>8I', self.__metadata, metadata_offset, dt_entry.size,
+ dt_entry.dt_offset, dt_entry.image_id, dt_entry.rev,
+ dt_entry.flags, dt_entry.custom0, dt_entry.custom1,
+ dt_entry.custom2)
+
def _update_metadata(self):
"""Updates the DTBO metadata.
@@ -244,7 +274,7 @@ def _update_metadata(self):
Tree table entries and update the DTBO header.
"""
- self.__metadata = array('c', ' ' * self.__metadata_size)
+ self.__metadata = array('b', b' ' * self.__metadata_size)
metadata_offset = self.header_size
for dt_entry in self.__dt_entries:
self._update_dt_entry_header(dt_entry, metadata_offset)
@@ -290,15 +320,21 @@ def _read_dt_entries_from_metadata(self):
if self.__dt_entries:
raise ValueError('DTBO DT entries can be added only once')
- offset = self.dt_entries_offset / 4
+ offset = self.dt_entries_offset // 4
params = {}
+ params['version'] = self.version
params['dt_file'] = None
for i in range(0, self.dt_entry_count):
dt_table_entry = self.__metadata[offset:offset + self._DT_ENTRY_HEADER_INTS]
params['dt_size'] = dt_table_entry[0]
params['dt_offset'] = dt_table_entry[1]
for j in range(2, self._DT_ENTRY_HEADER_INTS):
- params[DtEntry.REQUIRED_KEYS[j + 1]] = str(dt_table_entry[j])
+ required_keys = None
+ if self.version == 0:
+ required_keys = DtEntry.REQUIRED_KEYS_V0
+ elif self.version == 1:
+ required_keys = DtEntry.REQUIRED_KEYS_V1
+ params[required_keys[j + 1]] = str(dt_table_entry[j])
dt_entry = DtEntry(**params)
self.__dt_entries.append(dt_entry)
offset += self._DT_ENTRY_HEADER_INTS
@@ -465,14 +501,13 @@ def add_dt_entries(self, dt_entries):
dt_offset = (self.header_size +
dt_entry_count * self.dt_entry_size)
- dt_entry_buf = ""
+ dt_entry_buf = b""
for dt_entry in dt_entries:
if not isinstance(dt_entry, DtEntry):
raise ValueError('Adding invalid DT entry object to DTBO')
entry = self._find_dt_entry_with_same_file(dt_entry)
- dt_entry_compression_info = dt_entry.compression_info(self.version)
- if entry and (entry.compression_info(self.version)
- == dt_entry_compression_info):
+ dt_entry_compression_info = dt_entry.compression_info()
+ if entry and (entry.compression_info() == dt_entry_compression_info):
dt_entry.dt_offset = entry.dt_offset
dt_entry.size = entry.size
else:
@@ -510,7 +545,7 @@ def extract_dt_file(self, idx, fout, decompress):
offset = self.dt_entries[idx].dt_offset
self.__file.seek(offset, 0)
fout.seek(0)
- compression_format = self.dt_entries[idx].compression_info(self.version)
+ compression_format = self.dt_entries[idx].compression_info()
if decompress and compression_format:
if (compression_format == CompressionFormat.ZLIB_COMPRESSION or
compression_format == CompressionFormat.GZIP_COMPRESSION):
@@ -580,6 +615,9 @@ def parse_dt_entry(global_args, arglist):
parser.add_argument('--custom2', type=str, dest='custom2',
action='store',
default=global_args.global_custom2)
+ parser.add_argument('--custom3', type=str, dest='custom3',
+ action='store',
+ default=global_args.global_custom3)
return parser.parse_args(arglist)
@@ -612,7 +650,7 @@ def parse_dt_entries(global_args, arg_list):
raise ValueError('Input DT images must be provided')
total_images = len(img_file_idx)
- for idx in xrange(total_images):
+ for idx in range(total_images):
start_idx = img_file_idx[idx]
if idx == total_images - 1:
argv = arg_list[start_idx:]
@@ -621,6 +659,7 @@ def parse_dt_entries(global_args, arg_list):
argv = arg_list[start_idx:end_idx]
args = parse_dt_entry(global_args, argv)
params = vars(args)
+ params['version'] = global_args.version
params['dt_offset'] = 0
params['dt_size'] = os.fstat(params['dt_file'].fileno()).st_size
dt_entries.append(DtEntry(**params))
@@ -753,6 +792,8 @@ def parse_create_args(arg_list):
action='store', default='0')
parser.add_argument('--custom2', type=str, dest='global_custom2',
action='store', default='0')
+ parser.add_argument('--custom3', type=str, dest='global_custom3',
+ action='store', default='0')
args = parser.parse_args(argv)
return args, remainder
@@ -769,7 +810,7 @@ def parse_dump_cmd_args(arglist):
parser = argparse.ArgumentParser(prog='dump')
parser.add_argument('--output', '-o', nargs='?',
- type=argparse.FileType('wb'),
+ type=argparse.FileType('w'),
dest='outfile',
default=stdout)
parser.add_argument('--dtb', '-b', nargs='?', type=str,
@@ -789,7 +830,7 @@ def parse_config_create_cmd_args(arglist):
"""
parser = argparse.ArgumentParser(prog='cfg_create')
parser.add_argument('conf_file', nargs='?',
- type=argparse.FileType('rb'),
+ type=argparse.FileType('r'),
default=None)
cwd = os.getcwd()
parser.add_argument('--dtb-dir', '-d', nargs='?', type=str,
@@ -845,15 +886,22 @@ def create_dtbo_image_from_config(fout, argv):
if not args.conf_file:
raise ValueError('Configuration file must be provided')
- _DT_KEYS = ('id', 'rev', 'flags', 'custom0', 'custom1', 'custom2')
+ _DT_KEYS = ('id', 'rev', 'flags', 'custom0', 'custom1', 'custom2', 'custom3')
_GLOBAL_KEY_TYPES = {'dt_type': str, 'page_size': int, 'version': int}
global_args, dt_args = parse_config_file(args.conf_file,
_DT_KEYS, _GLOBAL_KEY_TYPES)
+ version = global_args['version']
+
params = {}
+ params['version'] = version
dt_entries = []
for dt_arg in dt_args:
- filepath = args.dtbdir + os.sep + dt_arg['filename']
+ filepath = dt_arg['filename']
+ if not os.path.isabs(filepath):
+ for root, dirnames, filenames in os.walk(args.dtbdir):
+ for filename in fnmatch.filter(filenames, os.path.basename(filepath)):
+ filepath = os.path.join(root, filename)
params['dt_file'] = open(filepath, 'rb')
params['dt_offset'] = 0
params['dt_size'] = os.fstat(params['dt_file'].fileno()).st_size
@@ -865,7 +913,7 @@ def create_dtbo_image_from_config(fout, argv):
dt_entries.append(DtEntry(**params))
# Create and write DTBO file
- dtbo = Dtbo(fout, global_args['dt_type'], global_args['page_size'], global_args['version'])
+ dtbo = Dtbo(fout, global_args['dt_type'], global_args['page_size'], version)
dt_entry_buf = dtbo.add_dt_entries(dt_entries)
dtbo.commit(dt_entry_buf)
fout.close()
@@ -916,6 +964,7 @@ def print_create_usage(progname):
sb.append(' --custom0=<number>')
sb.append(' --custom1=<number>')
sb.append(' --custom2=<number>\n')
+ sb.append(' --custom3=<number>\n')
sb.append(' The value could be a number or a DT node path.')
sb.append(' <number> could be a 32-bits digit or hex value, ex. 68000, 0x6800.')