Skip to contentSkip to conversation

qts-filter.sh: strip DOS line endings and handle continuation lines

PATCH New Bill Randle 2 participants 3 messages Nov 18, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qts-filter.sh: strip DOS line endings and handle continuation lines

Some Altera Quartus generated files have long lines that are split with a '\' at the end of the line. It also writes files in DOS format, which can confuse some of the processing scripts in this file. This patch solves both issues.

---
 arch/arm/mach-socfpga/qts-filter.sh | 52 +++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 19 deletions(-)
arch/arm/mach-socfpga/qts-filter.sh +33 -19
index 050d6ba..43b2e8f 100755
@@ -26,15 +26,19 @@ process_iocsr_config() {
 
 EOF
 
-	# Retrieve the scan chain lengths
-	grep 'CONFIG_HPS_IOCSR_SCANCHAIN[0-9]\+_LENGTH'			\
-		${in_bsp_dir}/generated/iocsr_config_${soc}.h | tr -d "()"
+	# Retrieve the scan chain lengths,
+	# converting DOS line endings and deal with lines ending in '\'
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
+		${in_bsp_dir}/generated/iocsr_config_${soc}.h |
+	grep 'CONFIG_HPS_IOCSR_SCANCHAIN[0-9]\+_LENGTH'	| tr -d "()"
 
 	echo ""
 
-	# Retrieve the scan chain config and zap the ad-hoc length encoding
-	sed -n '/^const/ !b; :next {/^const/ s/(.*)//;p;n;b next}'	\
-		${in_bsp_dir}/generated/iocsr_config_${soc}.c
+	# Retrieve the scan chain config and zap the ad-hoc length encoding,
+	# converting DOS line endings and deal with lines ending in '\'
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
+		${in_bsp_dir}/generated/iocsr_config_${soc}.c |
+	sed -n '/^const/ !b; :next {/^const/ s/(.*)//;p;n;b next}'
 
 	cat << EOF
 
@@ -68,9 +72,11 @@ process_pinmux_config() {
 
 EOF
 
-	# Retrieve the pinmux config and zap the ad-hoc length encoding
-	sed -n '/^unsigned/ !b; :next {/^unsigned/ {s/\[.*\]/[]/;s/unsigned long/const u8/};p;n;b next}' \
-		${in_bsp_dir}/generated/pinmux_config_${soc}.c
+	# Retrieve the pinmux config and zap the ad-hoc length encoding,
+	# converting DOS line endings and deal with lines ending in '\'
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
+		${in_bsp_dir}/generated/pinmux_config_${soc}.c |
+	sed -n '/^unsigned/ !b; :next {/^unsigned/ {s/\[.*\]/[]/;s/unsigned long/const u8/};p;n;b next}'
 
 	cat << EOF
 
@@ -104,9 +110,11 @@ process_pll_config() {
 
 EOF
 
-	# Retrieve the pll config and zap parenthesis
-	sed -n '/CONFIG_HPS/ !b; :next {/CONFIG_HPS/ s/[()]//g;/endif/ b;p;n;b next}' \
-		${in_bsp_dir}/generated/pll_config.h
+	# Retrieve the pll config and zap parenthesis,
+	# converting DOS line endings and deal with lines ending in '\'
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
+		${in_bsp_dir}/generated/pll_config.h |
+	sed -n '/CONFIG_HPS/ !b; :next {/CONFIG_HPS/ s/[()]//g;/endif/ b;p;n;b next}'
 
 	cat << EOF
 
@@ -148,33 +156,39 @@ process_sdram_config() {
 EOF
 
 	echo "/* SDRAM configuration */"
+	# Convert DOS line endings and deal with lines ending in '\'
 	# Retrieve the sdram config, zap broken lines and zap parenthesis
-	sed -n "/\\\\$/ {N;s/ \\\\\n/\t/};p"		\
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
 		${in_bsp_dir}/generated/sdram/sdram_config.h |
+	sed -n "/\\\\$/ {N;s/ \\\\\n/\t/};p" |
 	sed -n '/CONFIG_HPS/ !b; :next {/CONFIG_HPS/ s/[()]//g;/endif/ b;p;n;b next}' |
 		sort -u | grep_sdram_config
 
 	echo ""
 	echo "/* Sequencer auto configuration */"
-	sed -n "/__RW_MGR/ {s/__//;s/ \+\([^ ]\+\)$/\t\1/p}"		\
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
 		${in_qts_dir}/hps_isw_handoff/*/sequencer_auto.h |
+	sed -n "/__RW_MGR/ {s/__//;s/ \+\([^ ]\+\)$/\t\1/p}" |
 		sort -u | grep_sdram_config
 
 	echo ""
 	echo "/* Sequencer defines configuration */"
-	sed -n "/^#define [^_]/ {s/__//;s/ \+\([^ ]\+\)$/\t\1/p}"	\
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
 		${in_qts_dir}/hps_isw_handoff/*/sequencer_defines.h |
+	sed -n "/^#define [^_]/ {s/__//;s/ \+\([^ ]\+\)$/\t\1/p}" |
 		sort -u | grep_sdram_config
 
 	echo ""
 	echo "/* Sequencer ac_rom_init configuration */"
-	sed -n '/^const.*\[/ !b; :next {/^const.*\[/ {N;s/\n//;s/alt_u32/u32/;s/\[.*\]/[]/};/endif/ b;p;n;b next}'\
-		${in_qts_dir}/hps_isw_handoff/*/sequencer_auto_ac_init.c
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
+		${in_qts_dir}/hps_isw_handoff/*/sequencer_auto_ac_init.c |
+	sed -n '/^const.*\[/ !b; :next {/^const.*\[/ {N;s/\n//;s/alt_u32/u32/;s/\[.*\]/[]/};/endif/ b;p;n;b next}'
 
 	echo ""
 	echo "/* Sequencer inst_rom_init configuration */"
-	sed -n '/^const.*\[/ !b; :next {/^const.*\[/ {N;s/\n//;s/alt_u32/u32/;s/\[.*\]/[]/};/endif/ b;p;n;b next}'\
-		${in_qts_dir}/hps_isw_handoff/*/sequencer_auto_inst_init.c
+	sed -n ':next;s/\r$//;/[^\\]\\$/ {N;s/\\\n//;b next};p' \
+		${in_qts_dir}/hps_isw_handoff/*/sequencer_auto_inst_init.c |
+	sed -n '/^const.*\[/ !b; :next {/^const.*\[/ {N;s/\n//;s/alt_u32/u32/;s/\[.*\]/[]/};/endif/ b;p;n;b next}'
 
 	cat << EOF
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 qts-filter.sh: strip DOS line endings and handle continuation lines

Quoted 8 lines · Bill Randle

Some Altera Quartus generated files have long lines that are split with a '\' at the end of the line. It also writes files in DOS format, which can confuse some of the processing scripts in this file. This patch solves both issues.

---
 arch/arm/mach-socfpga/qts-filter.sh | 52 +++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 19 deletions(-)

Wouldn't it make more sense to define shell function which would rectify the file content and call it from multiple places ? ie.

fix_newlines_in_macros() {
    sed "............."
}

- # Retrieve the pinmux config and zap the ad-hoc length encoding
- sed -n '/^unsigned/ !b; :next {/^unsigned/ {s/\[.*\]/[]/;s/unsigned
long/const u8/};p;n;b next}' \
- ${in_bsp_dir}/generated/pinmux_config_${soc}.c
+ # Retrieve the pinmux config and zap the ad-hoc length encoding,
+ # converting DOS line endings and deal with lines ending in '\'
+ fix_newlines_in_macros \
+ ${in_bsp_dir}/generated/pinmux_config_${soc}.c |
+ sed -n '/^unsigned/ !b; :next {/^unsigned/ {s/\[.*\]/[]/;s/unsigned
long/const u8/};p;n;b next}'

Signature · 2 lines
Best regards,
Marek Vasut
#2 lore raw

PATCH 1/1 qts-filter.sh: strip DOS line endings and handle continuation lines

Quoted 29 lines · Marek Vasut
Quoted 8 lines · Bill Randle

Some Altera Quartus generated files have long lines that are split with a '\' at the end of the line. It also writes files in DOS format, which can confuse some of the processing scripts in this file. This patch solves both issues.

---
 arch/arm/mach-socfpga/qts-filter.sh | 52 +++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 19 deletions(-)

Wouldn't it make more sense to define shell function which would rectify the file content and call it from multiple places ? ie.

fix_newlines_in_macros() {
    sed "............."
}
(quoted diff) +0 -2
-       # Retrieve the pinmux config and zap the ad-hoc length encoding
-       sed -n '/^unsigned/ !b; :next {/^unsigned/ {s/\[.*\]/[]/;s/unsigned

long/const u8/};p;n;b next}' \

arch/arm/mach-socfpga/qts-filter.sh +5 -1
-               ${in_bsp_dir}/generated/pinmux_config_${soc}.c
+       # Retrieve the pinmux config and zap the ad-hoc length encoding,
+       # converting DOS line endings and deal with lines ending in '\'
+       fix_newlines_in_macros \
+                   ${in_bsp_dir}/generated/pinmux_config_${soc}.c |
+       sed -n '/^unsigned/ !b; :next {/^unsigned/ {s/\[.*\]/[]/;s/unsigned

long/const u8/};p;n;b next}'

Quoted 3 lines

--
Best regards,
Marek Vasut

Probably a good idea. I'll do that and submit a V2 patch.

-Bill