1 From f13ff4fe020c9018eb5a472b7c8a69a54e45ce29 Mon Sep 17 00:00:00 2001
2 From: Yutang Jiang <yutang.jiang@nxp.com>
3 Date: Tue, 18 Oct 2016 22:37:17 +0800
4 Subject: [PATCH 93/93] add byte_swap.tcl script for uboot can run/save in
7 Signed-off-by: Yutang Jiang <yutang.jiang@nxp.com>
10 byte_swap.tcl | 36 ++++++++++++++++++++++++++++++++++++
11 2 files changed, 37 insertions(+)
12 create mode 100755 byte_swap.tcl
14 diff --git a/Makefile b/Makefile
15 index 1c2818c..b73375f 100644
18 @@ -836,6 +836,7 @@ dtbs dts/dt.dtb: checkdtc u-boot
20 u-boot-dtb.bin: u-boot.bin dts/dt.dtb FORCE
21 $(call if_changed,cat)
22 + tclsh byte_swap.tcl u-boot-dtb.bin u-boot-swap.bin 8
25 $(Q)$(MAKE) $(build)=arch/arm/imx-common $@
26 diff --git a/byte_swap.tcl b/byte_swap.tcl
28 index 0000000..a4e8008
33 +set i_file [lindex $argv 0]
34 +set o_file [lindex $argv 1]
35 +set num_b [lindex $argv 2]
38 +set fileid_i [open $i_file "r"]
39 +set fileid_o [open $o_file "w+"]
40 +fconfigure $fileid_i -translation {binary binary}
41 +fconfigure $fileid_o -translation {binary binary}
43 +set old_bin [read $fileid_i]
45 +set old_length [string length $old_bin]
46 +set old_rem [expr $old_length % $num_b]
48 + for {set i 0} {$i< [expr $num_b - $old_rem]} {incr i 1} {
52 +for {set i 0} {$i<[string length $old_bin]} {incr i $num_b} {
53 + for {set j $num_b} {$j>0} {incr j -1} {
54 + append new_bin [string index $old_bin [expr $i+($j-1)]]
58 +for {set i 0} {$i<[string length $old_bin]} {incr i $num_b} {
59 + set binValue [string range $old_bin [expr $i+0] [expr $i+($num_b-1)]]
60 + binary scan $binValue H[expr $num_b*2] hexValue
62 + set binValue [string range $new_bin [expr $i+0] [expr $i+($num_b-1)]]
63 + binary scan $binValue H[expr $num_b*2] hexValue
66 +puts -nonewline $fileid_o $new_bin