Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

deebot
Copy link
Contributor

@deebot deebot commented Aug 28, 2020

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

@deebot deebot changed the title New Makefile to ease the loading of PRU firmware Makefile update to ease the loading of PRU firmware Aug 28, 2020
Copy link
Owner

@dinuxbg dinuxbg left a 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.

@@ -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
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay updating this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as asked

PRU1 :=/sys/class/remoteproc/remoteproc2
STATESRUNNING :=running
STATESSTOPED :=offline
CURRENTSTATE0:=$(shell cat $(PRU0)/state)
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@@ -92,6 +100,70 @@ $(ELF1): $(SRC1) $(HEADERS) | $(OUT)
clean:
$(RM) -fr $(ELF0) $(ELF1) $(OUT)

install_PRU0:
@echo 'Installation Process Initiated'
ifeq ($(CURRENTSTATE0),$(STATESRUNNING))
Copy link
Owner

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 []

Copy link
Contributor Author

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

@echo 'PRU0 Already in the stopped state. execute start_PRU0 to start '
endif

start_PRU0:
Copy link
Owner

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.

Copy link
Contributor Author

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

@deebot
Copy link
Contributor Author

deebot commented Sep 1, 2020

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.

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.

@dinuxbg
Copy link
Owner

dinuxbg commented Sep 2, 2020

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.

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
Copy link
Owner

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)
Copy link
Owner

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\
Copy link
Owner

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.

Copy link
Contributor Author

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"

https://pastebin.com/mcDgiwFw

But still if you would me to do it as you suggested. I would change and update the code. :)

Copy link
Owner

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.

Copy link
Contributor Author

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

Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants