schnitzeltony / meta-microcontroller

OE layer for tools to work with microcontrollers and electronics
MIT License
4 stars 9 forks source link

`avr-libc` not present during recipe `do_compile` #2

Open mdtusz opened 2 years ago

mdtusz commented 2 years ago

I'm trying to create a recipe for a non-avr target that includes an mcu binary, but am running into issues compiling the binary. avr-gcc is present and available in the compilation step, however there are issues with missing avr-libc components which I can't seem to find in the build-time sysroot. In the recipe, I have

DEPENDS += " \
  avr-libc \
  avg-gcc-native \
"

however I'm wondering if there is some additional yocto magic required, or if avr-libc is being added somewhere else (it isn't present in ${libdir} when inspecting during the do_compile step).

@schnitzeltony do you have any public recipes which do a similar thing that I could take a look at? The main issue seems to just be the presence of avr-libc in the sysroot while compiling.

schnitzeltony commented 2 years ago

From what I understand: You want to compile avr sources with avr-gcc-native at build time - right?

@schnitzeltony do you have any public recipes which do a similar thing that I could take a look at? The main issue seems to just be the presence of avr-libc in the sysroot while compiling.

All code I have is in here. There are some very old avr-projects I did decades ago in https://github.com/schnitzeltony/old-avr-projects

Did that help?

mdtusz commented 2 years ago

You want to compile avr sources with avr-gcc-native at build time - right?

Yep! I'm trying to create the AVR binary (.hex file in my case) at build time so that it can be copied into the yocto system image (i.e. an image that runs on single-board-computer and needs to be able to flash an atmega board with the AVR firmware binary).

I'm not super well versed in yocto yet and suspect I may just be missing something from the recipe or am looking in the wrong places for the avr-libc headers during the do_compile build step. I had expected that by adding avr-libc to the recipe DEPENDS, it would be present during the build step, but this doesn't seem to be the case.

The repo linked seems to be AVR source rather than bitbake recipe examples that cross-compile during build time. No worries at all if you don't have anything available though or don't have a solution off the top of your head!

Feel free to close this issue too - just wanted to check before I dive in too deep.

schnitzeltony commented 2 years ago

When making the recipes for AVR toolchain I thought: Would be a nice feature to compile AVR sources during build time. Have prepared a bbclass for this here but that was never tested. Now you come up with same idea.

So: Cannot promise a schedule - made this layer just for fun - but I would like to make this work (my old sources as test case) - just because it's cool

Feel free to close this issue too - just wanted to check before I dive in too deep.

Challenge - No reason to close this issue at all!

schnitzeltony commented 2 years ago

Update:

I pushed avr-toolchain.bbclass (haven't tested nothing - just guesswork).

Currently my free time is very limited. Maybe you want to give it a try by inheriting it and let me know - or send some PR...

mdtusz commented 2 years ago

I'll give it a look and test it out! I'm still new to yocto and figuring things out but I'll definitely open a PR if changes are needed and I can make it work!

schnitzeltony commented 2 years ago

Spent some cyles on this one an can now compile AVR sources during YOCTO build. It is not not done yet:

You asked for a recipe: https://github.com/schnitzeltony/meta-microcontroller/blob/master/recipes-avr/avr-projects/old-avr-projects.bb

Ahh and: Had to do some adjustments on the project Makefiles (use += instead of = for flags). Makefiles were made manually and I wonder if other projects - with auto generated Makefiles - build either. So: Are your AVR sources non-secret so I can use them for test?

mdtusz commented 2 years ago

Thank you so much for this! The new avr-toolchain class in the master branch seems to resolve the issues that I was facing and the header sources are now available - it would be awesome to get that merged into the named release branch.

For future readers, the key parts of the recipe files when trying to cross-build for AVR seem to be:

The key part that was causing issue for me was the missing avr-libc header files, but the avr-toolchain class now fixes this. Depending on how your Makefile is written, you may need to modify or patch it for these - specifically CFLAGS and LDFLAGS.

Again, thanks a ton @schnitzeltony!

lgrosz commented 1 year ago

I was able to make similar changes off the zeus branch which worked great!