Skip to contentSkip to conversation

Improve handosff prepare on SoCFPGA

PATCH Superseded Brian Sune 2 participants 6 messages Apr 20 – Apr 21

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Brian Sune

author
#0 lore raw

PATCH v3 1/1 Improve handosff prepare on SoCFPGA

There are some cases that the Python scripts
are run and the qts files are not replaced.
Make sure qts folder h files are removed before
handoff script runs.

---
 arch/arm/mach-socfpga/config.mk | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
arch/arm/mach-socfpga/config.mk +26 -3
index 1ca1d33cb16..5a75b773474 100644
@@ -8,6 +8,8 @@ else ifeq ($(CONFIG_ARCH_SOCFPGA_ARRIA5),y)
 archprepare: socfpga_g5_handoff_prepare
 endif
 
+HANDOFF_KEEP ?= 0
+
 socfpga_g5_handoff_prepare:
 	@SOCFAMILY="$(SOCFAMILY)"; \
 		if [ -z "$$SOCFAMILY" ]; then \
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
 			exit 0; \
 		fi; \
 		echo "[INFO] Found hiof file: $$HIOF_FILE"; \
-		echo "[INFO] Running BSP generator..."; \
-		python3 $(srctree)/tools/cv_bsp_generator/cv_bsp_generator.py -i "$$HANDOFF_PATH" -o "$$BOARD_DIR/qts" || echo "[WARN] BSP generator failed, continuing..."; \
-		echo "[DONE] SoCFPGA QTS handoff conversion complete."
+		echo "[INFO] Try BSP generator..."; \
+		TEMP_DIR=$$(mktemp -dp "$$BOARD_DIR/"); \
+		if python3 $(srctree)/tools/cv_bsp_generator/cv_bsp_generator.py -i "$$HANDOFF_PATH" -o "$$TEMP_DIR"; then \
+			if [ -n "$$HANDOFF_KEEP" ]; then \
+				echo "[INFO] Preserving old BSP files..."; \
+				TIMESTAMP=$$(date +%Y%m%d_%H%M%S); \
+				for f in "$$BOARD_DIR"/qts/*.h; do \
+					[ -e "$$f" ] || continue; \
+					echo "[INFO] $$f -> $${f%.h}.h.handoff_backup.$$TIMESTAMP"; \
+					mv "$$f" "$${f%.h}.h.handoff_backup.$$TIMESTAMP"; \
+				done; \
+			else \
+				echo "[INFO] Clean old BSP files..."; \
+				if ls "$$BOARD_DIR/qts"/*.h >/dev/null 2>&1; then \
+					rm "$$BOARD_DIR/qts"/*.h; \
+					echo "[INFO] Removed old BSP files..."; \
+				fi; \
+			fi; \
+			mv "$$TEMP_DIR"/*.h "$$BOARD_DIR"/qts; \
+			echo "[INFO] SoCFPGA QTS handoff conversion complete."; \
+		else \
+			echo "[WARN] BSP generator failed!"; \
+		fi; \
+		trap 'rm -rf "$$TEMP_DIR"' EXIT;
Signature · 1 line
2.34.1
#1 lore raw

Hi Brian,

Quoted 11 lines · Brian Sune

Improve handosff prepare on SoCFPGA

There are some cases that the Python scripts
are run and the qts files are not replaced.
Make sure qts folder h files are removed before
handoff script runs.

arch/arm/mach-socfpga/config.mk | 29 ++++++++++++++++++++++++++---

 1 file changed, 26 insertions(+), 3 deletions(-)

Typo in commit message: "handosff" should be "handoff".

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 7 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -8,6 +8,8 @@ else ifeq ($(CONFIG_ARCH_SOCFPGA_ARRIA5),y)
+HANDOFF_KEEP ?= 0
 
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             if [ -n "$$HANDOFF_KEEP" ]; then \

HANDOFF_KEEP defaults to "0", so -n "0" is always true. I suspect you want:

    if [ "$$HANDOFF_KEEP" != "0" ]; then \

Otherwise the 'preserve' path is always taken and the 'clean' path is dead code.

You could also have an empty variable meaning don't keep.

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             trap 'rm -rf "$$TEMP_DIR"' EXIT;

The trap is set after TEMP_DIR has already been used. If the python script or mv fails partway through, the temporary directory won't be cleaned up. You could move the trap to immediately after mktemp

Regards,
Simon

author
#2 lore raw
Quoted 11 lines · Simon Glass

Hi Brian,

Quoted 7 lines · Brian Sune

Improve handosff prepare on SoCFPGA

There are some cases that the Python scripts
are run and the qts files are not replaced.
Make sure qts folder h files are removed before
handoff script runs.

Quoted 6 lines
Quoted 4 lines

arch/arm/mach-socfpga/config.mk | 29 ++++++++++++++++++++++++++---

 1 file changed, 26 insertions(+), 3 deletions(-)

Typo in commit message: "handosff" should be "handoff".

Got it.

Quoted 9 lines

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 8 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -8,6 +8,8 @@ else ifeq ($(CONFIG_ARCH_SOCFPGA_ARRIA5),y)
+HANDOFF_KEEP ?= 0
 
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             if [ -n "$$HANDOFF_KEEP" ]; then \

Hi Simon,

Thanks for the feedback.

Before the patch was pushed I personally tested all these cases and found no issue.
make w/o HANDOFF_KEEP=1 will link to clean vice versa. You can use make HANDOFF_KEEP without =1 it will report No rule to make target 'HANDOFF_KEEP'
Sorry, cannot see issue on this section.
Maybe you can try and test if it is the case.
Pure "brain processes code" sometimes is a bit tricky.

Quoted 8 lines

HANDOFF_KEEP defaults to "0", so -n "0" is always true. I suspect you want:

    if [ "$$HANDOFF_KEEP" != "0" ]; then \

Otherwise the 'preserve' path is always taken and the 'clean' path is dead code.

You could also have an empty variable meaning don't keep.

Quoted 7 lines

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             trap 'rm -rf "$$TEMP_DIR"' EXIT;

The trap is set after TEMP_DIR has already been used. If the python script or mv fails partway through, the temporary directory won't be cleaned up. You could move the trap to immediately after mktemp

Sorry, again during the test I did not see any issue what you described. The temp dir cleaned up w/o any issues.
Both condition branches keep and clean.
mv or python script will not break like exit 1

QUOTE --->
[INFO] Try BSP generator...
./board/altera/cyclone5-socdk/tmp.Z11PmKjAMg
Generating file: ./board/altera/cyclone5-socdk/tmp.Z11PmKjAMg/sdram_config.h... Generating file: ./board/altera/cyclone5-socdk/tmp.Z11PmKjAMg/pinmux_config.h... Generating file: ./board/altera/cyclone5-socdk/tmp.Z11PmKjAMg/pll_config.h
***Error: We don't handle more than one .hiof file yet
Only the last .hiof file in the list will be converted
hiof files found:
/media/sf_shared/loader/hps_isw_handoff/pcie_rp_ed_5csxfc6_hps_0/pcie_rp_ed_5csxfc6_hps_0
(copy).hiof

              /media/sf_shared/loader/hps_isw_handoff/pcie_rp_ed_5csxfc6_hps_0/pcie_rp_ed_5csxfc6_hps_0.hiof

Reading file: /media/sf_shared/loader/hps_isw_handoff/pcie_rp_ed_5csxfc6_hps_0/pcie_rp_ed_5csxfc6_hps_0 (copy).hiof...
Generating file: ./board/altera/cyclone5-socdk/tmp.Z11PmKjAMg/iocsr_config.h... Traceback (most recent call last):
File "/home/intel/u-boot_C5PRJ/./tools/cv_bsp_generator/cv_bsp_generator.py",
line 100, in <module>
iocsr = iocsr.IOCSRGrokker(hps.getDeviceFamily(), inputDir,
outputDir, hiof_file)
AttributeError: 'IOCSRGrokker' object has no attribute 'IOCSRGrokker'
[WARN] BSP generator failed!

ll ./board/altera/cyclone5-socdk/tmp.Z11PmKjAMg
ls: cannot access './board/altera/cyclone5-socdk/tmp.Z11PmKjAMg': No such file or directory
<--- END QUOTE

QUOTE--->
UPD include/generated/timestamp_autogenerated.h
[INFO] Using manually specified handoff folder:
/media/sf_shared/loader/hps_isw_handoff/pcie_rp_ed_5csxfc6_hps_0
[INFO] Found hiof file:
/media/sf_shared/loader/hps_isw_handoff/pcie_rp_ed_5csxfc6_hps_0/pcie_rp_ed_5csxfc6_hps_0.hiof [INFO] Try BSP generator...
Generating file: ./board/altera/cyclone5-socdk/tmp.TvQv88TcsZ/sdram_config.h...
Generating file: ./board/altera/cyclone5-socdk/tmp.TvQv88TcsZ/pinmux_config.h...
Generating file: ./board/altera/cyclone5-socdk/tmp.TvQv88TcsZ/pll_config.h
Reading file: /media/sf_shared/loader/hps_isw_handoff/pcie_rp_ed_5csxfc6_hps_0/pcie_rp_ed_5csxfc6_hps_0.hiof... Generating file: ./board/altera/cyclone5-socdk/tmp.TvQv88TcsZ/iocsr_config.h...
[INFO] Clean old BSP files...
mv: target './board/altera/cyclone5-socdk/qts' is not a directory
[INFO] SoCFPGA QTS handoff conversion complete.

ll ./board/altera/cyclone5-socdk/tmp.TvQv88TcsZ
ls: cannot access './board/altera/cyclone5-socdk/tmp.TvQv88TcsZ': No such file or directory
<--- END QUOTE

Thanks,
Brian

Quoted 3 lines

Regards,
Simon

author
#3 lore raw
In reply to Simon Glass
Quoted 22 lines · Simon Glass

Hi Brian,

Quoted 11 lines · Brian Sune

Improve handosff prepare on SoCFPGA

There are some cases that the Python scripts
are run and the qts files are not replaced.
Make sure qts folder h files are removed before
handoff script runs.

arch/arm/mach-socfpga/config.mk | 29 ++++++++++++++++++++++++++---

 1 file changed, 26 insertions(+), 3 deletions(-)

Typo in commit message: "handosff" should be "handoff".

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -8,6 +8,8 @@ else ifeq ($(CONFIG_ARCH_SOCFPGA_ARRIA5),y)
+HANDOFF_KEEP ?= 0
Quoted 7 lines

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             if [ -n "$$HANDOFF_KEEP" ]; then \

HANDOFF_KEEP defaults to "0", so -n "0" is always true. I suspect you want:

    if [ "$$HANDOFF_KEEP" != "0" ]; then \

Hi Simon,

I think this is a misunderstanding.
My original idea is to use the HANDOFF_KEEP=(whatever is mistyped) to run the keep branch.

While the absence of HANDOFF_KEEP(anything) will not keep. But simply HANDOFF_KEEP will not work and need HANDOFF_KEEP=xxx.

Because the command >
"make prepare HANDOFF_KEEP=xxx" is very distinctly long HANDOFF_KEEP=xxx so it must keep my thingy. Even if I mistyped =0 etc.

And during the absence of HANDOFF_KEEP=xxxx
"make prepare " immediately, see ok clean so it will not keep good.

That's my original thought.
I think I should changed to:
if [ -n "$${HANDOFF_KEEP+x}" ]; then \

Need your comments on this.

Thanks,
Brian

Quoted 15 lines

Otherwise the 'preserve' path is always taken and the 'clean' path is dead code.

You could also have an empty variable meaning don't keep.

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             trap 'rm -rf "$$TEMP_DIR"' EXIT;

The trap is set after TEMP_DIR has already been used. If the python script or mv fails partway through, the temporary directory won't be cleaned up. You could move the trap to immediately after mktemp

Regards,
Simon

#4 lore raw

Hi Brian,

Quoted 32 lines · Sune Brian
Quoted 22 lines · Simon Glass

Hi Brian,

Quoted 11 lines · Brian Sune

Improve handosff prepare on SoCFPGA

There are some cases that the Python scripts
are run and the qts files are not replaced.
Make sure qts folder h files are removed before
handoff script runs.

arch/arm/mach-socfpga/config.mk | 29 ++++++++++++++++++++++++++---

 1 file changed, 26 insertions(+), 3 deletions(-)

Typo in commit message: "handosff" should be "handoff".

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -8,6 +8,8 @@ else ifeq ($(CONFIG_ARCH_SOCFPGA_ARRIA5),y)
+HANDOFF_KEEP ?= 0
Quoted 7 lines

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             if [ -n "$$HANDOFF_KEEP" ]; then \

HANDOFF_KEEP defaults to "0", so -n "0" is always true. I suspect you want:

    if [ "$$HANDOFF_KEEP" != "0" ]; then \
Quoted 8 lines

Hi Simon,

I think this is a misunderstanding.
My original idea is to use the HANDOFF_KEEP=(whatever is mistyped) to run the keep branch.

While the absence of HANDOFF_KEEP(anything) will not keep. But simply HANDOFF_KEEP will not work and need HANDOFF_KEEP=xxx.

I'd suggest either dropping the assignment to '0', since someone reading the Makefile will reasonably expect the shell to see it as 'off'.

In any case, how about a comment above to explain what the argument is for and what it does?

Quoted 14 lines

Because the command >
"make prepare HANDOFF_KEEP=xxx" is very distinctly long HANDOFF_KEEP=xxx so it must keep my thingy. Even if I mistyped =0 etc.

And during the absence of HANDOFF_KEEP=xxxx
"make prepare " immediately, see ok clean so it will not keep good.

That's my original thought.
I think I should changed to:
if [ -n "$${HANDOFF_KEEP+x}" ]; then \

Quoted 17 lines

Need your comments on this.

Thanks,
Brian

Quoted 12 lines

Otherwise the 'preserve' path is always taken and the 'clean' path is dead code.

You could also have an empty variable meaning don't keep.

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             trap 'rm -rf "$$TEMP_DIR"' EXIT;

The trap is set after TEMP_DIR has already been used. If the python script or mv fails partway through, the temporary directory won't be cleaned up. You could move the trap to immediately after mktemp

OK I had that wrong. If someone presses Ctrl-C while Python is running it would not clean up, but that's a minor issue...

Please note that you should add a change log for version 2, 3, etc. - see here for details:

https://docs.u-boot.org/en/latest/develop/sending_patches.html

Regards,
Simon

author
#5 lore raw
Quoted 45 lines · Simon Glass

Hi Brian,

Quoted 40 lines · Sune Brian
Quoted 22 lines · Simon Glass

Hi Brian,

Quoted 11 lines · Brian Sune

Improve handosff prepare on SoCFPGA

There are some cases that the Python scripts
are run and the qts files are not replaced.
Make sure qts folder h files are removed before
handoff script runs.

arch/arm/mach-socfpga/config.mk | 29 ++++++++++++++++++++++++++---

 1 file changed, 26 insertions(+), 3 deletions(-)

Typo in commit message: "handosff" should be "handoff".

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -8,6 +8,8 @@ else ifeq ($(CONFIG_ARCH_SOCFPGA_ARRIA5),y)
+HANDOFF_KEEP ?= 0
Quoted 7 lines

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             if [ -n "$$HANDOFF_KEEP" ]; then \

HANDOFF_KEEP defaults to "0", so -n "0" is always true. I suspect you want:

    if [ "$$HANDOFF_KEEP" != "0" ]; then \

Hi Simon,

I think this is a misunderstanding.
My original idea is to use the HANDOFF_KEEP=(whatever is mistyped) to run the keep branch.

While the absence of HANDOFF_KEEP(anything) will not keep. But simply HANDOFF_KEEP will not work and need HANDOFF_KEEP=xxx.

Hi Simon,

Quoted 4 lines

I'd suggest either dropping the assignment to '0', since someone reading the Makefile will reasonably expect the shell to see it as 'off'.

Yes indeed so I had pushed patch v4 and fixed what you suggested with my inheritance idea.

Quoted 2 lines

In any case, how about a comment above to explain what the argument is for and what it does?

I guess patch v4 has no issue self explaining the check condition has undergone those expected logic cases and exists HANDOFF_KEEP.

So v4 simply:
HANDOFF_KEEP= <- keep
HANDOFF_KEEP=0 <- no keep
HANDOFF_KEEP=1 <- keep
HANDOFF_KEEP='0' <- no keep
HANDOFF_KEEP='1' <- keep
etc.

Thanks,
Brian

Quoted 43 lines
Quoted 15 lines

Because the command >
"make prepare HANDOFF_KEEP=xxx" is very distinctly long HANDOFF_KEEP=xxx so it must keep my thingy. Even if I mistyped =0 etc.

And during the absence of HANDOFF_KEEP=xxxx
"make prepare " immediately, see ok clean so it will not keep good.

That's my original thought.
I think I should changed to:
if [ -n "$${HANDOFF_KEEP+x}" ]; then \

Quoted 17 lines

Need your comments on this.

Thanks,
Brian

Quoted 12 lines

Otherwise the 'preserve' path is always taken and the 'clean' path is dead code.

You could also have an empty variable meaning don't keep.

arch/arm/mach-socfpga/config.mk socfpga_g5_handoff_prepare: · line 45

Quoted 3 lines
arch/arm/mach-socfpga/config.mk +1 -0
@@ -43,6 +45,27 @@ socfpga_g5_handoff_prepare:
+             trap 'rm -rf "$$TEMP_DIR"' EXIT;

The trap is set after TEMP_DIR has already been used. If the python script or mv fails partway through, the temporary directory won't be cleaned up. You could move the trap to immediately after mktemp

OK I had that wrong. If someone presses Ctrl-C while Python is running it would not clean up, but that's a minor issue...

Please note that you should add a change log for version 2, 3, etc. - see here for details:

https://docs.u-boot.org/en/latest/develop/sending_patches.html

Regards,
Simon