summaryrefslogtreecommitdiffstats
path: root/patches/01_firmware-crc-sh.patch
blob: bdadbce0cb9fdfbd9971951890eaedca03cf478b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Author: "P. J. McDermott" <pj@pehjota.net>
Subject: Replace target_firmware/firmware-crc.pl with a shell script

diff -Naur src.orig/target_firmware/CMakeLists.txt src/target_firmware/CMakeLists.txt
--- src.orig/target_firmware/CMakeLists.txt	2014-09-11 14:35:37.000000000 -0400
+++ src/target_firmware/CMakeLists.txt	2014-10-23 13:45:37.456405846 -0400
@@ -119,6 +119,6 @@
 ADD_CUSTOM_COMMAND(
 	OUTPUT ${FIRMWARE_NAME}
 	DEPENDS fw.bin
-	COMMAND ${CMAKE_SOURCE_DIR}/firmware-crc.pl < fw.bin > ${FIRMWARE_NAME}
+	COMMAND ${CMAKE_SOURCE_DIR}/firmware-crc.sh < fw.bin > ${FIRMWARE_NAME}
 )
 ADD_CUSTOM_TARGET(gen-firmware ALL DEPENDS ${FIRMWARE_NAME})
diff -Naur src/target_firmware.orig/firmware-crc.sh src/target_firmware/firmware-crc.sh
--- src.orig/target_firmware/firmware-crc.sh	1969-12-31 19:00:00.000000000 -0500
+++ src/target_firmware/firmware-crc.sh	2014-10-23 13:21:56.080985994 -0400
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+crc=0
+while read b1 b2 b3 b4; do
+	v=$(( ($b1 << 24) | ($b2 << 16) | ($b3 << 8) | ($b4 << 0) ))
+	crc=$(( $crc ^ $v ))
+	b1=$(( ($v & 0xFF000000) >> 24 ))
+	b2=$(( ($v & 0x00FF0000) >> 16 ))
+	b3=$(( ($v & 0x0000FF00) >>  8 ))
+	b4=$(( ($v & 0x000000FF) >>  0 ))
+	printf "\\$(printf '%03o' "${b1}")"
+	printf "\\$(printf '%03o' "${b2}")"
+	printf "\\$(printf '%03o' "${b3}")"
+	printf "\\$(printf '%03o' "${b4}")"
+done <<-EOF
+	$(od -An -tu1 -v -w4 -)
+	EOF
+
+b1=$(( ($crc & 0xFF000000) >> 24 ))
+b2=$(( ($crc & 0x00FF0000) >> 16 ))
+b3=$(( ($crc & 0x0000FF00) >>  8 ))
+b4=$(( ($crc & 0x000000FF) >>  0 ))
+printf "\\$(printf '%03o' "${b1}")"
+printf "\\$(printf '%03o' "${b2}")"
+printf "\\$(printf '%03o' "${b3}")"
+printf "\\$(printf '%03o' "${b4}")"