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

Zephyr federated support #232

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

siljesu
Copy link
Contributor

@siljesu siljesu commented Jun 2, 2023

To be able to run federates on Zephyr, the following changes must be made to reactor-c. Notice that #220 has been merged into this PR as well. This is because Zephyr does not offer support for the obsolete gethostbyname(). So, if #220 is not approved, then this PR must add a macro separating the two implementations.

In the Zephyr platform-specific functions, macros are added to allow for static thread stack definition for federated execution.

Additionally, the regex library is not supported by Zephyr.

Copy link
Collaborator

@erlingrj erlingrj left a comment

Choose a reason for hiding this comment

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

Looks good, but can we find a better way of dealing with the regex functionality? If I understand correctly, it is used in validate_host and validate_user. Silje, you want to remove these functions from the Zephyr port, why arent they needed for Zephyr?

Also, are you sure that the regex library isn't available for Zephyr? Some googling indicates that it is available in Newlib (the C library implementation we use on Zephyr)

core/federated/net_util.c Outdated Show resolved Hide resolved
@siljesu
Copy link
Contributor Author

siljesu commented Jun 3, 2023

Good points. I think you are right; the regex library should be included in Newlib.

However, I am getting linker errors when using the regex functions:

.../zephyr-sdk-0.15.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.bfd: core/libcore.a(net_util.c.obj): in function `extract_rti_addr_info':
.../src-gen/federate__unitB/core/federated/net_util.c:698: undefined reference to `regcomp'
.../zephyr-sdk-0.15.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.bfd: 
.../src-gen/federate__unitB/core/federated/net_util.c:703: undefined reference to `regexec'
.../zephyr-sdk-0.15.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.bfd: 
.../src-gen/federate__unitB/core/federated/net_util.c:716: undefined reference to `regfree'
collect2: error: ld returned 1 exit status

Any ideas? It is similar to zephyrproject-rtos/zephyr#8502 - could it be a bug in Zephyr? Or maybe some configuration option I have missed?

@erlingrj
Copy link
Collaborator

erlingrj commented Jun 3, 2023

Could be a configuration issue. How can I reproduce it here?

@siljesu
Copy link
Contributor Author

siljesu commented Jun 3, 2023

Try to build any zephyr program with -b mimxrt1170_evk_cm7 and the option CONFIG_NEWLIB_LIBC=y. This should not be able to compile, since regcomp takes parameters. With this program I am not getting a linker error, but another error in regex.h. So it seems the linker error was my fault. But still I am getting the error shown below.

#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <regex.h>

void main(void)
{
	regcomp();
}
zephyr-sdk-0.15.2/arm-zephyr-eabi/arm-zephyr-eabi/sys-include/regex.h:43:9: error: unknown type name 'off_t'
   43 | typedef off_t regoff_t;

EDIT: it seems like the error above comes from that regex.h depends on sys/types.h. When I add both in net_util.h, I am getting still getting linker errors in net_util.c.

@erlingrj
Copy link
Collaborator

erlingrj commented Jun 5, 2023

Did you resolve it?

@siljesu
Copy link
Contributor Author

siljesu commented Jun 5, 2023

No, I am still getting a linker issue, even if the correct library files are included. It could be related to linker flags, maybe. I guess you should be able to reproduce it properly now, with the new pull request in lf-west-template.

@erlingrj
Copy link
Collaborator

erlingrj commented Jun 8, 2023

The problem is resolved by using picolibc rather than newlibc. But I remember picking newlibc because I had problems with the other C library options. But you could try changing form newlibc to picolibc in the prj.conf file that is in the lingua-franca repository. It is somewhere under resources/platform/zephyr I think

@erlingrj
Copy link
Collaborator

@siljesu What is the status on this? Will you have time to finalize it?

@erlingrj
Copy link
Collaborator

To get this merged we need to do the following:

@lhstrh
Copy link
Member

lhstrh commented Sep 13, 2023

@erlingrj would you be able to turn this into a brief project description for the embedded systems class? We could add it here.

@erlingrj
Copy link
Collaborator

Could be a nice project. I have seen that Zephyr supports Sockets over USB, so it should, in theory, be possible to run federated LF programs spanning a Pico and a Linux PC connected by USB. The Pico would be a better example platform for Federated Embedded LF as it is more common. The boards Silje were using are more rare, and in general, ethernet on microcontroller boards is not that common. By what time should I propose a project?

@lhstrh
Copy link
Member

lhstrh commented Sep 13, 2023

No hurry with this, but what you describe sounds great. I think students will figure out their project sometime next month...

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.

3 participants