layerscape: add byte_swap.py script for ls-rcw package
[openwrt/openwrt.git] / package / firmware / layerscape / ls-rcw / patches / 0001-rcw-add-a-python-script-for-byte-swapping.patch
1 From ebded197f9c12168d61973043fd9ebd5d49528a8 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Mon, 25 Dec 2017 14:11:02 +0800
4 Subject: [PATCH] rcw: add a python script for byte swapping
5
6 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
7 ---
8 Makefile | 2 ++
9 byte_swap.py | 32 ++++++++++++++++++++++++++++++++
10 2 files changed, 34 insertions(+)
11 create mode 100755 byte_swap.py
12
13 diff --git a/Makefile b/Makefile
14 index fb55c8b..27e3ba2 100644
15 --- a/Makefile
16 +++ b/Makefile
17 @@ -11,6 +11,8 @@ all install clean:
18 @for board in $(BOARDS); do \
19 $(MAKE) -C $$board $@ DESTDIR=$(DESTDIR)/$$board; \
20 done
21 + chmod 755 ./byte_swap.py; \
22 + ./byte_swap.py ls1046ardb/RR_FFSSPPPH_1133_5559/rcw_1800_qspiboot.bin 8
23
24 release: $(foreach board,$(BOARDS),rcw-$(board)-$(VER).tar.gz)
25
26 diff --git a/byte_swap.py b/byte_swap.py
27 new file mode 100755
28 index 0000000..7ee4129
29 --- /dev/null
30 +++ b/byte_swap.py
31 @@ -0,0 +1,32 @@
32 +#!/usr/bin/env python
33 +"""
34 +Swap the 4/8 bytes endian except for PBI CRC
35 +2016-10-9: Initial version
36 +
37 +Usage:
38 + ./byte_swap.py <file_name> <byte>
39 +"""
40 +import sys
41 +
42 +try:
43 + file_name = sys.argv[1]
44 + byte = int(sys.argv[2])
45 +except:
46 + print("Usage: ./byte_swap.py <file_name> <byte>")
47 + print("E.g.: ./byte_swap.py rcw_1600.bin 8\n")
48 + exit
49 +
50 +with open(file_name,'rb') as file:
51 + tmp = file.read()
52 +file.close()
53 +
54 +with open(file_name + '.swap','wb') as file:
55 + for i in range(0, len(tmp) - 1, byte):
56 + if(tmp[i:i+4].encode('hex')) == "08610040":
57 + #print("PBI CRC command")
58 + file.write(tmp[i:i+8])
59 + break
60 + file.write(tmp[i:i+byte][::-1])
61 +file.close()
62 +
63 +print("Swapped file: " + file_name + '.swap')
64 --
65 2.7.4
66