-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
build: Add rules in Makefile.gen to generate a hex file #1447
Conversation
I tried to apply this to #1378 using the patch below. Nothing is generated, what am I doing wrong? Generally, this patch uses permutations of the same name with one-char difference: generate_inc_file, generate_inc_files, generated_inc_files, so it's hard to even spot if there can be a typo.
|
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.
Prefer to have this tool in python, this way we minimise dependency on host compilers
I forgot one line you need to add to your src/Makefile, put that after setting generate_inc_file variable. include $(ZEPHYR_BASE)/samples/net/common/Makefile.common |
If you look the stdin2hex.c file, it is very minimalistic ANSI-C code which should compile everywhere. |
Thats not the point, it still requires a host compiler, something we are trying to avoid, especially on windows |
There was such a line - in the very beginning of src/Makefile (as can be seen at the diff above). And expectedly, I added new content at the very end of it. It worked after I moved "generate_inc_file +=" stanza above the include, thanks. But all in all, it's pretty confusing, and I'd recommend describing that requirement explicitly in the commit message. |
I'd personally want to merge this asap, but as @nashif raises an issue requiring refactoring anyway, can we also avoid black magicity like:
The canonical way (as in: I kinda never saw it done differently) to do that is: an include file to contain only numeric initializer list, to be used as:
|
And, @jukkar, did you really consider other options to have it done? Are we really can't have it e.g. like: src/Makefile:
? |
What python version we need, 3 or 2? |
I tried that but did not manage it to work, perhaps with some makefile woodoo magic or something it could be done. |
Sure, we can do it like that too. That is actually better as then application can define the variable name/type itself. |
Also, commit message "samples: net: common: Add rules to generate a header file" doesn't do good to describe what actually happens here, and chance the "convert binary" key phrase can be fitted in there? |
Yep, also easier for a reader, as one can grep where the variable is defined easily. Thanks. |
python 3 |
187fa89
to
75dd24d
Compare
Sent a new version. I removed dependency to net subsystem as this can be made more generic. Also replaced the binary by python3 script that generates the hex value list. |
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 is definitely a good improvement over the initial version. Tested against #1378, works well. Thanks!
I think this can be simplified even further. I will send a new version. |
75dd24d
to
2dc9295
Compare
@nashif Are you ok with this PR? |
move Makefile.gen to scripts/ and move the sample to tests/application_developments, not sure why this is under lib/, otherwise ok. |
This commit is useful if there is a need to generate a file that can be included into the application at build time. The file can also be compressed automatically when embedding it. Files to be generated are listed in generate_inc_file generate_inc_gz_file variables. How to use this commit in your application: 1. Add this to your application Makefile SRC = $(ZEPHYR_BASE)/<your-app-dir>/src include $(ZEPHYR_BASE)/scripts/Makefile.gen 2. Add needed binary/other embedded files into src/Makefile to "generate_inc_file" or "generate_inc_gz_file" variables: # List of files that are used to generate a file that can be # included into .c file. generate_inc_file += \ echo-apps-cert.der \ echo-apps-key.der \ file.bin generate_inc_gz_file += \ index.html include $(ZEPHYR_BASE)/scripts/Makefile.gen 3. In the application, do something with the embedded file static const unsigned char inc_file[] = { #include "file.bin.inc" }; static const unsigned char gz_inc_file[] = { #include "index.html.gz.inc" }; The generated files in ${SRC}/*.inc are automatically removed when you do "make pristine" Signed-off-by: Jukka Rissanen <[email protected]>
Add a simple test which generates a file that can be included into a .c file. Then verify in zephyr that the file contains the same bytes as the original file. Signed-off-by: Jukka Rissanen <[email protected]>
2dc9295
to
9107261
Compare
New version changed according to comment and uploaded for review. |
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.
Retested with #1378
This commit is useful if there is a need to generate a file that can be included into the application at build time.
The file can also be compressed automatically when embedding it.
Files to be generated are listed in generate_inc_file and generate_inc_gz_file variables.
How to use this commit in your application:
to "generate_inc_file" or "generate_inc_gz_file" variables:
The generated files in src/*.inc are automatically removed when you do "make pristine"