ThibFrgsGmz / fprime-rtems-poc

F´ PoC on RTEMS LEON 3 w/ Renode
MIT License
0 stars 0 forks source link

Add queue component #4

Closed ThibFrgsGmz closed 1 year ago

ThibFrgsGmz commented 1 year ago

Add one queue component into the topology to test Queue RTEMS implementation within the OSAL.

ThibFrgsGmz commented 1 year ago

Issue when linking the executable:

[100%] Linking CXX executable bin/leon3-rtems5/App
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libFw_CompQueued.a(QueuedComponentBase.cpp.obj): in function `_ZN2Fw19QueuedComponentBaseC2EPKc':
/home/musubi/codelab/fprime-rtems-poc/fprime/Fw/Comp/QueuedComponentBase.cpp:10: undefined reference to `_ZN2Os5QueueC1Ev'
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libFw_CompQueued.a(QueuedComponentBase.cpp.obj): in function `_ZN2Fw19QueuedComponentBaseD2Ev':
/home/musubi/codelab/fprime-rtems-poc/fprime/Fw/Comp/QueuedComponentBase.cpp:14: undefined reference to `_ZN2Os5QueueD1Ev'
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libFw_CompQueued.a(ActiveComponentBase.cpp.obj): in function `_ZN2Fw19ActiveComponentBaseC2EPKc':
/home/musubi/codelab/fprime-rtems-poc/fprime/Fw/Comp/ActiveComponentBase.cpp:33: undefined reference to `_ZN2Os4TaskC1Ev'
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libFw_CompQueued.a(ActiveComponentBase.cpp.obj): in function `_ZN2Fw19ActiveComponentBaseD2Ev':
/home/musubi/codelab/fprime-rtems-poc/fprime/Fw/Comp/ActiveComponentBase.cpp:37: undefined reference to `_ZN2Os4TaskD1Ev'
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libFw_CompQueued.a(ActiveComponentBase.cpp.obj): in function `_ZN2Fw19ActiveComponentBase5startEjjjj':
/home/musubi/codelab/fprime-rtems-poc/fprime/Fw/Comp/ActiveComponentBase.cpp:77: undefined reference to `_ZN2Os4Task5startERKN2Fw10StringBaseEPFvPvES5_jjjj'
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libFw_CompQueued.a(ActiveComponentBase.cpp.obj): in function `_ZN2Fw19ActiveComponentBase4joinEPPv':
/home/musubi/codelab/fprime-rtems-poc/fprime/Fw/Comp/ActiveComponentBase.cpp:91: undefined reference to `_ZN2Os4Task4joinEPPv'
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: /home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: DWARF error: could not find variable specification at offset 66d
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: DWARF error: could not find variable specification at offset 67a
lib/leon3-rtems5/libOs.a(QueueCommon.cpp.obj): in function `_ZN2Os5Queue4sendERKN2Fw19SerializeBufferBaseEiNS0_13QueueBlockingE':
/home/musubi/codelab/fprime-rtems-poc/fprime/Os/QueueCommon.cpp:18: undefined reference to `_ZN2Os5Queue4sendEPKhiiNS0_13QueueBlockingE'
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libOs.a(QueueCommon.cpp.obj): in function `_ZN2Os5Queue7receiveERN2Fw19SerializeBufferBaseERiNS0_13QueueBlockingE':
/home/musubi/codelab/fprime-rtems-poc/fprime/Os/QueueCommon.cpp:28: undefined reference to `_ZN2Os5Queue7receiveEPhiRiS2_NS0_13QueueBlockingE'
/home/musubi/rcc-1.3.0-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libOs.a(QueueCommon.cpp.obj): in function `_ZN2Os5Queue6createERKN2Fw10StringBaseEii':
/home/musubi/codelab/fprime-rtems-poc/fprime/Os/QueueCommon.cpp:44: undefined reference to `_ZN2Os5Queue14createInternalERKN2Fw10StringBaseEii'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/App.dir/build.make:112: bin/leon3-rtems5/App] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:1860: CMakeFiles/App.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:1867: CMakeFiles/App.dir/rule] Error 2
gmake: *** [Makefile:196: App] Error 2
[ERROR] CMake erred with return code 2
ThibFrgsGmz commented 1 year ago

CMakelists.txt of OSAL-RTEMS:

https://github.com/ThibFrgsGmz/fprime-rtems-poc/blob/feat/add-active-component/fprime-rtems/rtems/CMakeLists.txt#L23-L28

RTEMS queue implementation:

https://github.com/ThibFrgsGmz/fprime-rtems-poc/blob/feat/add-active-component/fprime-rtems/rtems/Queue.cpp

ThibFrgsGmz commented 1 year ago

Hey @LeStarch, I'm having trouble porting the framework to RTEMS...

Can you give me a hint please? I have link problems (see errors above).

LeStarch commented 1 year ago

When you call the following register line: https://github.com/ThibFrgsGmz/fprime-rtems-poc/blob/8b9dda730f24032615f1636ba74255b2ee387b2c/fprime-rtems/rtems/CMakeLists.txt#L44

Instead call: register_fprime_module(Os)

The Os library, however you config it must be called Os

LeStarch commented 1 year ago

At the current time you must also include in your source the following:

https://github.com/nasa/fprime/blob/91c578ee37c01ba92e556dbca0287d82f9f18b95/Os/CMakeLists.txt#L18-L30

As these are the common across all implementation implementations.

ThibFrgsGmz commented 1 year ago

Awesome, thanks a lot for the feedback!

Arf, if I add register_fprime_module(Os) I cannot generate the cache anymore:

CMake Error at /home/musubi/codelab/fprime-rtems-poc/fprime/cmake/module.cmake:31 (add_library):
  add_library cannot create target "Os" because another target with the same
  name already exists.  The existing target is a static library created in
  source directory "/home/musubi/codelab/fprime-rtems-poc/fprime/Os".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  /home/musubi/codelab/fprime-rtems-poc/fprime/cmake/module.cmake:80 (generate_base_module_properties)
  /home/musubi/codelab/fprime-rtems-poc/fprime/cmake/API.cmake:163 (generate_library)
  /home/musubi/codelab/fprime-rtems-poc/fprime-rtems/rtems/CMakeLists.txt:62 (register_fprime_module)

CMake Error at /home/musubi/codelab/fprime-rtems-poc/fprime/cmake/prescan.cmake:127 (message):
-- Including library /home/musubi/codelab/fprime-rtems-poc/fprime-rtems with manifests fprime-rtems.cmake
-- Performing CMake source prescan
-- Configuring incomplete, errors occurred!
  Failed to run prescan, cannot continue.
See also "/home/musubi/codelab/fprime-rtems-poc/App/build-fprime-automatic-leon3-rtems5/CMakeFiles/CMakeOutput.log".
Call Stack (most recent call first):
  /home/musubi/codelab/fprime-rtems-poc/fprime/cmake/FPrime.cmake:64 (perform_prescan)
  CMakeLists.txt:13 (include)

I don't see register_fprime_module(Os) in the other OSAL nodes (VxWorks, ThreadX, or FreeRTOS) - this seems odd to me.

ThibFrgsGmz commented 1 year ago

Instead, if I write register_fprime_module(fprime-rtems_rtems), and then I write in Top/CMakeLists.txt:

set(MOD_DEPS
  fprime-rtems/rtems
  Os
)

It goes further!

sobkulir commented 1 year ago

From ThreadX port, I'm not sure about the details, but it so far worked for me in the Zephyr port:

cmake_policy(SET CMP0079 NEW)

####
# Dependency Melding:
#
# In short, this Os layer depends on the framework's Os layer and vise-versa. Effectively it is one
# library built in two halves, the framework base, and this add on. Here we make the link pointers
# depend on one another forming a (weak) circular dependency. This is allowed in CMake 3.13 and
# newer.
####
if (${CMAKE_SYSTEM_NAME} STREQUAL "Nucleo-ThreadX")
    add_dependencies(Os fprime-nucleo_NucleoOs)
    target_link_libraries(Os PRIVATE fprime-nucleo_NucleoOs)
    target_link_libraries(fprime-nucleo_NucleoOs PRIVATE Os)
endif()

Source: https://github.com/fprime-community/fprime-azure-threadx/blob/fprime-azure-threadx-cmjl-14-01-2022-v00/fprime-nucleo/NucleoOs/CMakeLists.txt#L62

Maybe it would make sense to replace it with a linker group, but since it worked I didn't go into detail, I'm just trying to hack my way and later make it more robust. See: https://stackoverflow.com/questions/9380363/resolving-circular-dependencies-by-linking-the-same-library-twice

timcanham commented 1 year ago

What is your latest error log from this build? It would be really good to see this one work.

ThibFrgsGmz commented 1 year ago

@timcanham As I remember, I always had the same problems with the linker. Rereading this error message reminds me of my weekends stuck on it, brrr I had nightmares about it ahah.

This error is my best friend I would say, I had the same one when I tried to port FPrime to FreeRTOS on RISCV (Polarfire SoC) and Renode. If we solve the error together on RTEMS/LEON3/RENODE and I get the error right, I might resume porting from FreeRTOS/RISCV/RENODE.

I'll try to find a night within the week to get my environment back up and running. Otherwise, I'll probably have some time this weekend.

ThibFrgsGmz commented 1 year ago

@sobkulir Thanks!

I think I tried to solve the circularity dependencies with the link group, but that may have been part of another project I was doing on the side.

I also remember using LINK_GROUP:RESCAN to avoid having to write --start-group/--end-group and abstract the toolchain (incidentally, I had to abandon it because it wasn't well supported, I reckon).

ThibFrgsGmz commented 1 year ago

I tried to add the "Dependency Melding" in CMake: https://github.com/ThibFrgsGmz/fprime-rtems-poc/blob/43226d51206e8c80f71bc9b230e0ed49233e139e/fprime-rtems/rtems/CMakeLists.txt#L43-L47

I have this error at the end:

-- Adding Deployment: App
-- Configuring done (9.6s)
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
  "Os" of type STATIC_LIBRARY
    depends on "fprime-rtems_rtems" (weak)
    depends on "fprime-rtems_rtems" (strong)
  "fprime-rtems_rtems" of type STATIC_LIBRARY
    depends on "Os" (weak)
    depends on "Os" (strong)
The component contains at least one cycle consisting of strong dependencies (created by add_dependencies) that cannot be broken.
CMake Generate step failed.  Build files cannot be regenerated correctly.
[ERROR] CMake erred with return code 1. Partial build cache remains. Run purge to clean-up.

If I put it in comment and just keep the register_fprime_module(fprime-rtems_rtems), I have the error:

Completed generating HTML event tables...
[ 96%] Building CXX object App/Top/CMakeFiles/App_Top.dir/App.cpp.obj
[ 96%] Building CXX object App/Top/CMakeFiles/App_Top.dir/AppTopologyAc.cpp.obj
[ 96%] Building CXX object App/Top/CMakeFiles/App_Top.dir/FppConstantsAc.cpp.obj
[100%] Linking CXX static library ../../lib/leon3-rtems5/libApp_Top.a
[100%] Built target App_Top
[100%] Building CXX object CMakeFiles/App.dir/Main.cpp.obj
[100%] Linking CXX executable bin/leon3-rtems5/App
/home/life/rcc-1.3.1-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libFw_CompQueued.a(QueuedComponentBase.cpp.obj): in function `_ZN2Fw19QueuedComponentBaseC2EPKc':
/home/life/dev/fprime-rtems-poc/fprime/Fw/Comp/QueuedComponentBase.cpp:10: undefined reference to `_ZN2Os5QueueC1Ev'
/home/life/rcc-1.3.1-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libFw_CompQueued.a(QueuedComponentBase.cpp.obj): in function `_ZN2Fw19QueuedComponentBaseD2Ev':
/home/life/dev/fprime-rtems-poc/fprime/Fw/Comp/QueuedComponentBase.cpp:14: undefined reference to `_ZN2Os5QueueD1Ev'
/home/life/rcc-1.3.1-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: /home/life/rcc-1.3.1-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: DWARF error: could not find variable specification at offset 66d
/home/life/rcc-1.3.1-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: DWARF error: could not find variable specification at offset 67a
lib/leon3-rtems5/libOs.a(QueueCommon.cpp.obj): in function `_ZN2Os5Queue4sendERKN2Fw19SerializeBufferBaseEiNS0_13QueueBlockingE':
/home/life/dev/fprime-rtems-poc/fprime/Os/QueueCommon.cpp:18: undefined reference to `_ZN2Os5Queue4sendEPKhiiNS0_13QueueBlockingE'
/home/life/rcc-1.3.1-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libOs.a(QueueCommon.cpp.obj): in function `_ZN2Os5Queue7receiveERN2Fw19SerializeBufferBaseERiNS0_13QueueBlockingE':
/home/life/dev/fprime-rtems-poc/fprime/Os/QueueCommon.cpp:28: undefined reference to `_ZN2Os5Queue7receiveEPhiRiS2_NS0_13QueueBlockingE'
/home/life/rcc-1.3.1-gcc/bin/../lib/gcc/sparc-gaisler-rtems5/10.2.0/../../../../sparc-gaisler-rtems5/bin/ld: lib/leon3-rtems5/libOs.a(QueueCommon.cpp.obj): in function `_ZN2Os5Queue6createERKN2Fw10StringBaseEii':
/home/life/dev/fprime-rtems-poc/fprime/Os/QueueCommon.cpp:44: undefined reference to `_ZN2Os5Queue14createInternalERKN2Fw10StringBaseEii'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/App.dir/build.make:113: bin/leon3-rtems5/App] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:1861: CMakeFiles/App.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:1868: CMakeFiles/App.dir/rule] Error 2
gmake: *** [Makefile:196: App] Error 2
[ERROR] CMake erred with return code 2
ThibFrgsGmz commented 1 year ago

@LeStarch @timcanham @sobkulir issue solved. See my PR https://github.com/ThibFrgsGmz/fprime-rtems-poc/pull/8

The problem was that when I added Michael's suggestion by copy and paste, this code rewrote the SOURCE_FILES list. As a result, I no longer had my RTEMS-specific files (Tasks,Queue, etc).

Adding the following lines solved the problem:

register_fprime_module(fprime_rtems)
target_link_libraries(Os PRIVATE fprime_rtems)

Currently my RTEMS implementation doesn't seem to be working. The async port of the Queue component is not triggered when I connect it. Next step, add the last missing component type, an Active component.