wolfssl: fix build in busybox environments
[oweals/openwrt.git] / package / firmware / layerscape / ls-rcw / patches / 0001-rcw-support-byte-swapping-without-tclsh-tool.patch
1 From c87a500c45f36ad248b1298d63e590d1d7e74f12 Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Tue, 3 Jul 2018 11:06:47 +0800
4 Subject: [PATCH] rcw: support byte swapping without tclsh tool
5
6 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
7 ---
8  Makefile     |    4 ----
9  byte_swap.py |   32 ++++++++++++++++++++++++++++++++
10  qspi_swap.sh |    2 +-
11  3 files changed, 33 insertions(+), 5 deletions(-)
12  create mode 100755 byte_swap.py
13
14 diff --git a/Makefile b/Makefile
15 index 9f0587e..393bb2c 100644
16 --- a/Makefile
17 +++ b/Makefile
18 @@ -13,10 +13,6 @@ TCLSH := $(shell command -v tclsh 2> /dev/null)
19  VER = $(shell git describe --tags)
20  
21  all install clean:
22 -ifndef TCLSH
23 -       $(error "tclsh is not available. please  install it.")
24 -       exit 1
25 -endif
26         @for board in $(BOARDS); do \
27                 $(MAKE) -C $$board $@ DESTDIR=$(DESTDIR)/$$board; \
28         done
29 diff --git a/byte_swap.py b/byte_swap.py
30 new file mode 100755
31 index 0000000..386310e
32 --- /dev/null
33 +++ b/byte_swap.py
34 @@ -0,0 +1,32 @@
35 +#!/usr/bin/env python
36 +"""
37 +Swap the 4/8 bytes endian except for PBI CRC
38 +2016-10-9: Initial version
39 +
40 +Usage:
41 +       ./byte_swap.py <file_name> <byte>
42 +"""
43 +import sys
44 +
45 +try:
46 +    file_name = sys.argv[1]
47 +    byte = int(sys.argv[2])
48 +except:
49 +    print("Usage: ./byte_swap.py <file_name> <byte>")
50 +    print("E.g.: ./byte_swap.py rcw_1600.bin 8\n")
51 +    exit
52 +
53 +with open(file_name,'rb') as file:
54 +    tmp = file.read()
55 +file.close()
56 +
57 +with open(file_name + '.swapped','wb') as file:
58 +    for i in range(0, len(tmp) - 1, byte):
59 +       if(tmp[i:i+4].encode('hex')) == "08610040":
60 +           #print("PBI CRC command")
61 +           file.write(tmp[i:i+8])
62 +           break
63 +       file.write(tmp[i:i+byte][::-1])
64 +file.close()
65 +
66 +print("Swapped file: " + file_name + '.swapped')
67 diff --git a/qspi_swap.sh b/qspi_swap.sh
68 index 0b58e44..d23fd8b 100755
69 --- a/qspi_swap.sh
70 +++ b/qspi_swap.sh
71 @@ -9,7 +9,7 @@ do
72         if [ "$board_name" = "$current_dir" ]; then
73                 if [ -e $filename ]; then
74                         swapped_file="$filename.swapped"
75 -                       tclsh ../tools/byte_swap.tcl $filename $swapped_file 8
76 +                       ../byte_swap.py $filename 8
77                 fi
78         fi
79  done < $1
80 -- 
81 1.7.1
82