0001-rcw-support-byte-swapping-without-tclsh-tool.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From c87a500c45f36ad248b1298d63e590d1d7e74f12 Mon Sep 17 00:00:00 2001
  2. From: Yangbo Lu <[email protected]>
  3. Date: Tue, 3 Jul 2018 11:06:47 +0800
  4. Subject: [PATCH] rcw: support byte swapping without tclsh tool
  5. Signed-off-by: Yangbo Lu <[email protected]>
  6. ---
  7. Makefile | 4 ----
  8. byte_swap.py | 32 ++++++++++++++++++++++++++++++++
  9. qspi_swap.sh | 2 +-
  10. 3 files changed, 33 insertions(+), 5 deletions(-)
  11. create mode 100755 byte_swap.py
  12. diff --git a/Makefile b/Makefile
  13. index 9f0587e..393bb2c 100644
  14. --- a/Makefile
  15. +++ b/Makefile
  16. @@ -13,10 +13,6 @@ TCLSH := $(shell command -v tclsh 2> /dev/null)
  17. VER = $(shell git describe --tags)
  18. all install clean:
  19. -ifndef TCLSH
  20. - $(error "tclsh is not available. please install it.")
  21. - exit 1
  22. -endif
  23. @for board in $(BOARDS); do \
  24. $(MAKE) -C $$board $@ DESTDIR=$(DESTDIR)/$$board; \
  25. done
  26. diff --git a/byte_swap.py b/byte_swap.py
  27. new file mode 100755
  28. index 0000000..386310e
  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 + '.swapped','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 + '.swapped')
  64. diff --git a/qspi_swap.sh b/qspi_swap.sh
  65. index 0b58e44..d23fd8b 100755
  66. --- a/qspi_swap.sh
  67. +++ b/qspi_swap.sh
  68. @@ -9,7 +9,7 @@ do
  69. if [ "$board_name" = "$current_dir" ]; then
  70. if [ -e $filename ]; then
  71. swapped_file="$filename.swapped"
  72. - tclsh ../tools/byte_swap.tcl $filename $swapped_file 8
  73. + ../byte_swap.py $filename 8
  74. fi
  75. fi
  76. done < $1
  77. --
  78. 1.7.1