layerscape: define only one package for ls-rcw
[openwrt/staging/stintel.git] / package / firmware / layerscape / ls-rcw / patches / 0002-Convert-to-python3.patch
1 From 7bd43eb9e5cdf2035793d50a31bf13052eb9812a Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Wed, 19 Jun 2019 10:25:41 +0800
4 Subject: [PATCH 2/2] Convert to python3
5
6 Python 2.7 will not be maintained past 2020. Let's convert
7 to python3 for rcw. Below were the changes of this patch.
8 - Adapted print usage
9 - Didn't use tab anymore
10 - Handled str and bytes type separately
11 - Other minor changes
12
13 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
14 ---
15 Makefile.inc | 2 +-
16 rcw.py | 144 +++++++++++++++++++++++++++++------------------------------
17 2 files changed, 73 insertions(+), 73 deletions(-)
18
19 diff --git a/Makefile.inc b/Makefile.inc
20 index 7d9a3d3..8bee2be 100644
21 --- a/Makefile.inc
22 +++ b/Makefile.inc
23 @@ -1,6 +1,6 @@
24 DESTDIR = $(shell basename $(CURDIR))
25 INSTALL = install
26 -PYTHON ?= python2
27 +PYTHON ?= python3
28 RCW = $(PYTHON) ../rcw.py
29 QSPI_SWAP_LIST = $(shell pwd)/../qspi_swap_list.txt
30 QSPI_SWAP_SCRIPT=$(shell pwd)/../qspi_swap.sh
31 diff --git a/rcw.py b/rcw.py
32 index e5cd28b..619770a 100755
33 --- a/rcw.py
34 +++ b/rcw.py
35 @@ -1,4 +1,4 @@
36 -#!/usr/bin/env python2
37 +#!/usr/bin/env python3
38
39 # rcw.py -- compiles an RCW source file into an PBL/RCW binary
40
41 @@ -95,7 +95,7 @@ from optparse import OptionParser, OptionGroup
42 class ordered_dict(dict):
43 def __init__(self, *args, **kwargs):
44 dict.__init__(self, *args, **kwargs)
45 - self._order = self.keys()
46 + self._order = list(self.keys())
47
48 def __setitem__(self, key, value):
49 dict.__setitem__(self, key, value)
50 @@ -132,7 +132,7 @@ def crc32(data):
51
52 crc = 0xffffffff
53 for i in data:
54 - crc = (crc << 8) ^ table[(crc >> 24) ^ ord(i)]
55 + crc = (crc << 8) ^ table[(crc >> 24) ^ int(i)]
56 crc = crc & 0xffffffff
57
58 return crc
59 @@ -187,7 +187,7 @@ def command_line():
60 options.output = '/dev/stdout'
61
62 if options.reverse and not options.rcwi:
63 - print "Error: -r option requires --rcw"
64 + print("Error: -r option requires --rcw")
65 sys.exit(1)
66
67 # Checks if the bits for the given field overlap those of another field that
68 @@ -196,27 +196,27 @@ def check_for_overlap(name, begin, end):
69 global symbols
70
71 if name in symbols:
72 - print 'Error: Duplicate bitfield definition for', name
73 + print('Error: Duplicate bitfield definition for', name)
74 return
75
76 # Iterate over the list of symbols that have already been defined
77 - for n, [b, e] in symbols.iteritems():
78 + for n, [b, e] in symbols.items():
79 # check if either 'begin' or 'end' is inside an bitfield range
80 if (b <= begin <= e) or (b <= end <= e):
81 - print 'Error: Bitfield', name, 'overlaps with', n
82 + print('Error: Bitfield', name, 'overlaps with', n)
83
84 #
85 # Build a u-boot PBI section for SPI/SD/NAND boot
86 -# refer: Chapter 10, u-boot of QorIQ_SDK_Infocenter.pdf
87 +# refer: Chapter 10, u-boot of QorIQ_SDK_Infocenter.pdf
88 #
89 # pre-cond 1: u-boot.xxd should be created
90 # how to create u-boot.xxd
91 -# xxd u-boot.bin > u-boot.xxd1 && cut -d " " -f1-10 u-boot.xxd1 > u-boot.xxd && rm -f u-boot.xxd1
92 +# xxd u-boot.bin > u-boot.xxd1 && cut -d " " -f1-10 u-boot.xxd1 > u-boot.xxd && rm -f u-boot.xxd1
93 #
94 # rcw file should include spi_boot.rcw as well
95 #
96 def build_pbi_uboot(lines):
97 - subsection = ''
98 + subsection = b''
99 cnt = 1
100 l_tmp = []
101
102 @@ -224,55 +224,55 @@ def build_pbi_uboot(lines):
103 for l in lines:
104 # prepare 0x40 per lines except the last one
105 # add flush at the end
106 - lstr = l.split()
107 - addr = int(lstr[0][:-1], 16)
108 + lstr = l.split()
109 + addr = int(lstr[0][:-1], 16)
110
111 # print l
112 #
113 # last two lines take 0x20 numbers
114 #
115 - if ((cnt % 2 == 0) and (cnt > len(lines) -4)):
116 + if ((cnt % 2 == 0) and (cnt > len(lines) -4)):
117 l_tmp.append(l)
118 b = []
119
120 - for t in l_tmp:
121 + for t in l_tmp:
122 lstr = t.split()
123
124 - for i in range(1, len(lstr)):
125 + for i in range(1, len(lstr)):
126 b.append(int(lstr[i], 16))
127
128 subsection += struct.pack('>LHHHHHHHHHHHHHHHH',\
129 - 0x0C1F80000 + (addr - 0x10),\
130 - b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],\
131 - b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15])
132 + 0x0C1F80000 + (addr - 0x10),\
133 + b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],\
134 + b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15])
135 l_tmp = []
136 #
137 # the rest of lines take 0x40 numbers
138 elif (cnt % 4 == 0):
139 l_tmp.append(l)
140 - b = []
141 - for t in l_tmp:
142 + b = []
143 + for t in l_tmp:
144 lstr = t.split()
145 - for i in range(1, len(lstr)):
146 + for i in range(1, len(lstr)):
147 b.append(int(lstr[i], 16))
148
149 subsection += struct.pack('>LHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH',\
150 - 0x081F80000 + (addr - 0x30),\
151 - b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],\
152 - b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15],\
153 - b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], \
154 - b[24], b[25], b[26], b[27], b[28], b[29], b[30], b[31])
155 + 0x081F80000 + (addr - 0x30),\
156 + b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],\
157 + b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15],\
158 + b[16], b[17], b[18], b[19], b[20], b[21], b[22], b[23], \
159 + b[24], b[25], b[26], b[27], b[28], b[29], b[30], b[31])
160 l_tmp = []
161 else:
162 l_tmp.append(l)
163
164 - cnt = cnt + 1
165 + cnt = cnt + 1
166
167 return subsection
168
169 # Build a PBI section
170 def build_pbi(lines):
171 - subsection = ''
172 + subsection = b''
173 global vars
174
175 if 'pbiformat' in vars:
176 @@ -286,9 +286,9 @@ def build_pbi(lines):
177 for l in lines:
178 # Check for an instruction without 0-2 parameters
179 # The + ' ' is a hack to make the regex work for just 'flush'
180 - m = re.match(r'\s*([a-z]+)(|\.b1|\.b2|\.b4|\.short|\.long)\s*(?<=\s)([^,]*),?([^,]*),?([^,]*),?([^,]*)', l + ' ')
181 + m = re.match(r'\s*([a-z]+)(|\.b1|\.b2|\.b4|\.short|\.long)\s*(?<=\s)([^,]*),?([^,]*),?([^,]*),?([^,]*)', l.decode("ascii") + ' ')
182 if not m:
183 - print 'Unknown PBI subsection command "%s"' % l
184 + print('Unknown PBI subsection command "%s"' % l)
185 return ''
186 op = m.group(1)
187 opsize = m.group(2)
188 @@ -306,7 +306,7 @@ def build_pbi(lines):
189 p4 = eval(p4, {"__builtins__":None}, {}) if len(p4) else None
190 if op == 'wait':
191 if p1 == None:
192 - print 'Error: "wait" instruction requires one parameter'
193 + print('Error: "wait" instruction requires one parameter')
194 return ''
195 if pbiformat == 2:
196 v1 = struct.pack(endianess + 'L', 0x80820000 | p1)
197 @@ -318,7 +318,7 @@ def build_pbi(lines):
198 subsection += v2
199 elif op == 'write':
200 if p1 == None or p2 == None:
201 - print 'Error: "write" instruction requires two parameters'
202 + print('Error: "write" instruction requires two parameters')
203 return ''
204 if pbiformat == 2:
205 v1 = struct.pack(endianess + 'L', (opsizebytes << 28) | p1)
206 @@ -329,7 +329,7 @@ def build_pbi(lines):
207 subsection += v2
208 elif op == 'awrite':
209 if p1 == None or p2 == None:
210 - print 'Error: "awrite" instruction requires two parameters'
211 + print('Error: "awrite" instruction requires two parameters')
212 return ''
213 if pbiformat == 2:
214 v1 = struct.pack(endianess + 'L', 0x80000000 + (opsizebytes << 26) + p1)
215 @@ -340,10 +340,10 @@ def build_pbi(lines):
216 subsection += v2
217 elif op == 'poll':
218 if pbiformat != 2:
219 - print 'Error: "poll" not support for old PBI format'
220 + print('Error: "poll" not support for old PBI format')
221 return ''
222 if p1 == None or p2 == None or p3 == None:
223 - print 'Error: "poll" instruction requires three parameters'
224 + print('Error: "poll" instruction requires three parameters')
225 return ''
226 if opsize == '.long':
227 cmd = 0x81
228 @@ -357,19 +357,19 @@ def build_pbi(lines):
229 subsection += v3
230 elif op == 'loadacwindow':
231 if pbiformat != 2:
232 - print 'Error: "loadacwindow" not supported for old PBI format'
233 + print('Error: "loadacwindow" not supported for old PBI format')
234 return ''
235 if p1 == None:
236 - print 'Error: "loadacwindow" instruction requires one parameter'
237 + print('Error: "loadacwindow" instruction requires one parameter')
238 return ''
239 v1 = struct.pack(endianess + 'L', 0x80120000 + p1)
240 subsection += v1
241 elif op == 'blockcopy':
242 if pbiformat != 2:
243 - print 'Error: "blockcopy" not supported for old PBI format'
244 + print('Error: "blockcopy" not supported for old PBI format')
245 return ''
246 if p1 == None or p2 == None or p3 == None or p4 == None:
247 - print 'Error: "blockcopy" instruction requires four parameters'
248 + print('Error: "blockcopy" instruction requires four parameters')
249 return ''
250 v1 = struct.pack(endianess + 'L', 0x80000000 + (p1 & 0xff))
251 v2 = struct.pack(endianess + 'L', p2)
252 @@ -382,7 +382,7 @@ def build_pbi(lines):
253 elif op == 'flush':
254 subsection += struct.pack('>LL', 0x09000000 | (int(vars['pbladdr'], 16) & 0x00ffff00), 0)
255 else:
256 - print 'Unknown PBI subsection command "%s"' % l
257 + print('Unknown PBI subsection command "%s"' % l)
258 return ''
259
260 return subsection
261 @@ -394,7 +394,7 @@ def parse_subsection(header, lines):
262 elif header == "uboot":
263 return build_pbi_uboot(lines)
264
265 - print 'Error: unknown subsection "%s"' % header
266 + print('Error: unknown subsection "%s"' % header)
267 return ''
268
269 # Parse the .rcw file, one line at a time
270 @@ -408,10 +408,10 @@ def parse_source_file(source):
271 symbols = ordered_dict()
272
273 in_subsection = False # True == we're in a subsection
274 - pbi = ''
275 + pbi = b''
276
277 for l2 in source:
278 - l = re.sub(r'\s+', '', l2) # Remove all whitespace
279 + l = re.sub(r'\s+', '', l2.decode("ascii")) # Remove all whitespace
280
281 if not len(l): # Skip blank or comment-only lines
282 continue
283 @@ -466,14 +466,14 @@ def parse_source_file(source):
284 (name, value) = m.groups()
285 value = int(value, 0)
286 if not name in symbols:
287 - print 'Error: Unknown bitfield', name
288 + print('Error: Unknown bitfield', name)
289 else:
290 if options.warnings and (name in assignments):
291 - print 'Warning: Duplicate assignment for bitfield', name
292 + print('Warning: Duplicate assignment for bitfield', name)
293 assignments[name] = value
294 continue
295
296 - print 'Error: unknown command', ' '.join(l2)
297 + print('Error: unknown command', ' '.join(l2))
298
299 # Parse the -D command line parameter for additional bitfield assignments
300 def parse_cmdline_bitfields():
301 @@ -484,12 +484,12 @@ def parse_cmdline_bitfields():
302 # This is the same regex as used in parse_source_file()
303 m = re.search(r'([A-Z0-9_]+)=([0-9a-zA-Z]+)', l)
304 if not m:
305 - print 'Unrecognized command-line bitfield:', l
306 + print('Unrecognized command-line bitfield:', l)
307 else:
308 (name, value) = m.groups()
309 value = int(value, 0)
310 if not name in symbols:
311 - print 'Error: Unknown bitfield', name
312 + print('Error: Unknown bitfield', name)
313 else:
314 # Don't bother printing a warning, since the command-line will
315 # normally be used to overwrite values in the .rcw file
316 @@ -510,7 +510,7 @@ def read_source_file(filename):
317 global options
318
319 if not find_program('gcc'):
320 - print 'Could not find gcc in PATH'
321 + print('Could not find gcc in PATH')
322 return None
323
324 i = ['-I', '.'] # Always look in the current directory
325 @@ -521,7 +521,7 @@ def read_source_file(filename):
326 shell=False, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
327 ret = p.communicate()
328 if p.returncode != 0:
329 - print ret[1],
330 + print(ret[1],)
331 return None
332
333 return ret[0].splitlines()
334 @@ -532,13 +532,13 @@ def check_vars():
335 global options
336
337 if not 'size' in vars:
338 - print 'Error: "%size" variable must be specified'
339 + print('Error: "%size" variable must be specified')
340 sys.exit(1)
341
342 if options.pbl:
343 if 'pbiformat' in vars and int(vars['pbiformat'], 0) == 2:
344 if 'sysaddr' in vars:
345 - print 'Error: PBL format does not use %sysaddr'
346 + print('Error: PBL format does not use %sysaddr')
347 sys.exit(1)
348 #if 'pbladdr' in vars:
349 # print 'Error: PBL format does not use %pbladdr'
350 @@ -546,7 +546,7 @@ def check_vars():
351 else:
352 # If we want the PBL header/footer, the vars for those must be defined
353 if not 'sysaddr' in vars:
354 - print 'Error: PBL format requires %sysaddr to be defined'
355 + print('Error: PBL format requires %sysaddr to be defined')
356 sys.exit(1)
357
358 # Create a .bin file
359 @@ -581,7 +581,7 @@ def create_binary():
360 dont64bswapcrc = 0
361 if 'dont64bswapcrc' in vars and int(vars['dont64bswapcrc'], 0):
362 dont64bswapcrc = 1
363 - bits = 0L
364 + bits = 0
365
366 # Magic hack. If a pbi is specified and we didn't set the size,
367 # set it for the new format!
368 @@ -593,7 +593,7 @@ def create_binary():
369 pbilen += 2
370 assignments['PBI_LENGTH'] = pbilen
371
372 - for n, v in assignments.iteritems():
373 + for n, v in assignments.items():
374 # n = name of symbol
375 # v = value to assign
376 bb, ee = symbols[n] # First bit and last bit
377 @@ -603,13 +603,13 @@ def create_binary():
378
379 # Make sure it's not too large
380 if v >= (1 << s):
381 - print 'Error: Value', v, 'is too large for field', n
382 + print('Error: Value', v, 'is too large for field', n)
383 continue
384
385 # If we treat the bitfield as "classic" numbered, reverse
386 # the value before adding it!
387 if b != bb:
388 - v = int(bin(v)[2:].zfill(s)[::-1], 2)
389 + v = int(bin(int(v))[2:].zfill(s)[::-1], 2)
390
391 # Set the bits. We assume that bits [b:e] are already zero. They can be
392 # non-zero only if we have overlapping bitfield definitions, which we
393 @@ -617,7 +617,7 @@ def create_binary():
394 bits += v << ((size - 1) - e)
395
396 # Generate the binary. First, apply the preamble, if requested
397 - binary = ''
398 + binary = b''
399 if options.pbl:
400 # Starting with LS2, we have a larger field and a different
401 # format.
402 @@ -626,7 +626,7 @@ def create_binary():
403 # Load RCW command
404 binary += struct.pack(endianess + 'L', 0x80100000)
405 else:
406 - length_byte = (((size / 8) & 63) << 1) | 1
407 + length_byte = (((size // 8) & 63) << 1) | 1
408 binary += struct.pack(endianess + 'L', (length_byte << 24) | (int(vars['sysaddr'], 16) & 0x00ffffff))
409
410 # Then convert 'bits' into an array of bytes
411 @@ -634,7 +634,7 @@ def create_binary():
412 byte = bits >> i & 0xff
413 if classicbitnumbers:
414 byte = int(bin(byte)[2:].zfill(8)[::-1], 2)
415 - binary += chr(byte)
416 + binary += bytes([byte])
417
418 if options.pbl:
419 if pbiformat == 2:
420 @@ -672,11 +672,11 @@ def create_binary():
421 # Precise bit any byte ordering of the CRC calculation is
422 # not clearly specified. This is empirical.
423 if classicbitnumbers:
424 - newcrcbinary = ''
425 + newcrcbinary = b''
426 for c in crcbinary:
427 - byte = ord(c)
428 + byte = int(c)
429 byte = int(bin(byte)[2:].zfill(8)[::-1], 2)
430 - newcrcbinary += chr(byte)
431 + newcrcbinary += bytes([byte])
432 crcbinary = newcrcbinary
433
434 # Calculate and add the CRC
435 @@ -693,7 +693,7 @@ def create_binary():
436 l = len(binary)
437 if dont64bswapcrc and options.pbl:
438 l -= 8
439 - newbinary = ''
440 + newbinary = b''
441 for i in range(0, l, 8):
442 x64 = struct.unpack('>Q', binary[i:i + 8])[0]
443 newbinary += struct.pack('<Q', x64)
444 @@ -771,7 +771,7 @@ def create_source():
445 # We skip the checksum field
446 pbi = binary[8 + (size / 8) + 4:]
447 else:
448 - print 'Weird binary RCW format!'
449 + print('Weird binary RCW format!')
450 bitbytes = ''
451 else:
452 if binary[0:4] == preambletst:
453 @@ -780,7 +780,7 @@ def create_source():
454 bitbytes = rcw
455 pbi = binary[8 + (size / 8):]
456 else:
457 - print 'Weird binary RCW format!'
458 + print('Weird binary RCW format!')
459 bitbytes = ''
460 else:
461 bitbytes = binary
462 @@ -827,16 +827,16 @@ def create_source():
463 bits &= ~(mask << shift)
464
465 if bits:
466 - print 'Unknown bits in positions:',
467 + print('Unknown bits in positions:',)
468 mask = 1
469 n = 0
470 while bits:
471 if (bits & mask):
472 - print n,
473 + print(n,)
474 n += 1
475 bits &= ~mask
476 mask <<= 1
477 - print
478 + print()
479
480 if len(pbi) > 0:
481 l = len(pbi)
482 @@ -953,7 +953,7 @@ def create_source():
483 if cnt == 0:
484 cnt = 64
485 if i + cnt >= l:
486 - print 'Error in write 0x%08x at offset %d within PBI\n' % (word, i)
487 + print('Error in write 0x%08x at offset %d within PBI\n' % (word, i))
488 if (addr & 0x00ffff00 == pbladdr):
489 arg1 = struct.unpack(endianess + 'L', pbi[i:i+4])[0]
490 i += 4
491 @@ -986,8 +986,8 @@ def create_source():
492
493 return source
494
495 -if (sys.version_info < (2,6)) or (sys.version_info >= (3,0)):
496 - print 'Only Python versions 2.6 or 2.7 are supported.'
497 +if (sys.version_info < (3,0)):
498 + print('Only Python versions 3.0+ are supported.')
499 sys.exit(1)
500
501 # Make all 'print' statements output to stderr instead of stdout
502 --
503 2.7.4
504