-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Makefile update to ease the loading of PRU firmware #13
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was difficult to copy the code first to lib/firmware and then to go in /sys/class/remoteproc and echo the state to start and stop
Could you elaborate why it is difficult? I did not expect copy-pasting a few commands to be a hurdle.
hc-sr04-range-sensor/Makefile
Outdated
@@ -61,6 +61,14 @@ OUT := out | |||
ELF0 := $(OUT)/pru-halt.elf | |||
ELF1 := $(OUT)/hc-sr04-range-sensor.elf | |||
|
|||
#Installation, start stop related variable | |||
PRU0 :=/sys/class/remoteproc/remoteproc1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename to RPROC_PRU0. Otherwise it could easily be confused with ELF0 output binary for PRU0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay updating this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated as asked
hc-sr04-range-sensor/Makefile
Outdated
PRU1 :=/sys/class/remoteproc/remoteproc2 | ||
STATESRUNNING :=running | ||
STATESSTOPED :=offline | ||
CURRENTSTATE0:=$(shell cat $(PRU0)/state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break building firmware on a PC host.
I don't want sysfs to be poked when I'm building firmware.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok good point. I will add code to check if the make file is being run on Arm or on PC host.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a architecture check and when on ARM only then the sysfs is pocked
hc-sr04-range-sensor/Makefile
Outdated
@@ -92,6 +100,70 @@ $(ELF1): $(SRC1) $(HEADERS) | $(OUT) | |||
clean: | |||
$(RM) -fr $(ELF0) $(ELF1) $(OUT) | |||
|
|||
install_PRU0: | |||
@echo 'Installation Process Initiated' | |||
ifeq ($(CURRENTSTATE0),$(STATESRUNNING)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use shell commands to achive conditional logic. Build rule lines are not restricted to simple tool invocation. You can use shell's || or && or []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added nested conditions using shell commands
hc-sr04-range-sensor/Makefile
Outdated
@echo 'PRU0 Already in the stopped state. execute start_PRU0 to start ' | ||
endif | ||
|
||
start_PRU0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adhere to the existing convention in the Makefile all rules to be only lower case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rules converted to lower case
So when sombody just wants to run already written code , it is just copy- pasting once. But when i was doing development and trying to write and debug new code, every time i make some changes to the code and want to try out i had to run the commands again and again. In such a case it becomes tedious to copy and paste everytime to /lib/firmware then start from remotroc directory. Also after reboot the history is gone. So just doing make install would be simpler. |
Please include such justification in the commit message and address the rest of the comments. Thanks. |
…and starting of PRU cores - These new targets will be specially helpful during development when one needs to make new changes to firmware and load new firmware start ,stop PRU multiple times.
@@ -28,7 +31,7 @@ | |||
|
|||
# Very simple makefile to cross-compile for PRU | |||
|
|||
|
|||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for shebang here. Please remove.
@@ -61,6 +64,18 @@ OUT := out | |||
ELF0 := $(OUT)/pru-halt.elf | |||
ELF1 := $(OUT)/hc-sr04-range-sensor.elf | |||
|
|||
#Installation, start stop related variable | |||
ARCHT :=$(shell uname -m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Macros and $(shell) invocations should be avoided. Especially if you are writing example code. See below for suggestion how to remove this line.
@@ -92,6 +107,98 @@ $(ELF1): $(SRC1) $(HEADERS) | $(OUT) | |||
clean: | |||
$(RM) -fr $(ELF0) $(ELF1) $(OUT) | |||
|
|||
stop_pru0: | |||
@if [ $(ARCHT) = $(ARM) ]; then\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do "make stop_pru0" on x86 it will do nothing but will declare success. That is misleading. I would instead suggest you to do the following:
HOST_CHECK_CMD:=[ `uname -m` = armv7l ] || { echo "ERROR: Host is not a BeagleBone board! Cannot install PRU firmware. Bailing out."; false; }
stop_pru0:
@$(HOST_CHECK_CMD)
@echo "Do some work here."
@echo "Next command."
IMHO it is more clear to read, and will fail if unable to service the requested action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When i ran "make stop_pru0" on x86 i got the message. "Architecture doesnot support functionality. Run on Beaglebone"
But still if you would me to do it as you suggested. I would change and update the code. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry, your version would also print error message. But you see, that's why long macros are bad - they are hard to read. I missed the error message at the end. Readability is even more important for example code.
I think that regular Makefile commands are much more readable, as I suggested above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to make changes as you suggested and since the last 1 hour i am stuck with a error. It should have been straight forward. Can you please look at this snippet from my make file and help me resolve the error.
https://pastebin.com/00BRQnHx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deebot , I cannot open the link you have provided.The snippet I provided works - I tested it on beaglebone and x86_64 host.
The existing makefile only compile the code. It was difficult to copy the code first to lib/firmware and then to go in /sys/class/remoteproc and echo the state to start and stop. The new Makefile makes it easier. Now the user just need to do make install_PRU0 after running make and the PRU is loaded with the new firmware. Also there are situations when the firmware is already in place and only a starting or stopping of PRU core is required. In such a case start_PRU0 and stop_PRU0 can be used. For PRU 1 just change the number to 1. Hope this will be of help to other users