]> code.ossystems Code Review - meta-freescale.git/commitdiff
change-file-endianess: add recipe
authorChunrong Guo <B40290@freescale.com>
Wed, 4 Feb 2015 07:18:11 +0000 (15:18 +0800)
committerOtavio Salvador <otavio@ossystems.com.br>
Fri, 6 Feb 2015 01:08:27 +0000 (23:08 -0200)
     provides the tcl script for endian swap

Signed-off-by: Chunrong Guo <B40290@freescale.com>
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
meta-fsl-arm/recipes-bsp/change-file-endianess/change-file-endianess.bb [new file with mode: 0644]
meta-fsl-arm/recipes-bsp/change-file-endianess/change-file-endianess/byte_swap.tcl [new file with mode: 0755]

diff --git a/meta-fsl-arm/recipes-bsp/change-file-endianess/change-file-endianess.bb b/meta-fsl-arm/recipes-bsp/change-file-endianess/change-file-endianess.bb
new file mode 100644 (file)
index 0000000..2ad8c58
--- /dev/null
@@ -0,0 +1,23 @@
+DESCRIPTION = "provides the tcl script for endian swap"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \
+                    file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
+
+
+SRC_URI = "file://byte_swap.tcl"
+
+RDEPENDS += "tcl-native"
+
+inherit native
+
+S = "${WORKDIR}"
+
+do_configure[noexec] = "1"
+do_compile[noexec] = "1"
+
+do_install () {
+    install -d ${D}/${bindir}
+    install -m 755 ${WORKDIR}/byte_swap.tcl ${D}/${bindir}
+}
+
+BBCLASSEXTEND = "native nativesdk"
diff --git a/meta-fsl-arm/recipes-bsp/change-file-endianess/change-file-endianess/byte_swap.tcl b/meta-fsl-arm/recipes-bsp/change-file-endianess/change-file-endianess/byte_swap.tcl
new file mode 100755 (executable)
index 0000000..aca956b
--- /dev/null
@@ -0,0 +1,29 @@
+puts $argv
+set i_file [lindex $argv 0]
+set o_file [lindex $argv 1]
+set num_b  [lindex $argv 2]
+puts ""
+
+set fileid_i [open $i_file "r"]
+set fileid_o [open $o_file "w+"]
+fconfigure $fileid_i -translation {binary binary}
+fconfigure $fileid_o -translation {binary binary}
+
+set old_bin [read $fileid_i]
+set new_bin {}
+for {set i 0} {$i<[string length $old_bin]} {incr i $num_b} {
+        for {set j $num_b} {$j>0} {incr j -1} {
+                append new_bin [string index $old_bin [expr $i+($j-1)]]
+        }
+}
+
+for {set i 0} {$i<[string length $old_bin]} {incr i $num_b} {
+        set binValue [string range $old_bin [expr $i+0] [expr $i+($num_b-1)]]
+        binary scan $binValue H[expr $num_b*2] hexValue
+        
+        set binValue [string range $new_bin [expr $i+0] [expr $i+($num_b-1)]]
+        binary scan $binValue H[expr $num_b*2] hexValue
+}
+
+puts -nonewline $fileid_o $new_bin
+close $fileid_o