nasa / cFS

The Core Flight System (cFS)
Apache License 2.0
727 stars 218 forks source link

Build cFS for Raspberry Pi 4 #383

Open sticky-tea opened 2 years ago

sticky-tea commented 2 years ago

I'm trying to build cfs for Raspberry Pi using cross-compiler in Ubuntu 18.04. I installed gcc-arm-linux-gnueabihf and g++-arm-linux-gnueabihf, setup cmake toolchain file as follows:

set(CMAKE_SYSTEM_NAME       Linux)
set(CMAKE_SYSTEM_PROCESSOR  arm)
set(CMAKE_SYSTEM_VERSION    1)

SET(CMAKE_C_COMPILER            "arm-linux-gnueabihf-gcc")
SET(CMAKE_CXX_COMPILER          "arm-linux-gnueabihf-g++")

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM   NEVER)

SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY   ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE   ONLY)

SET(CFE_SYSTEM_PSPNAME      "pc-linux")
SET(OSAL_SYSTEM_BSPNAME     "pc-linux")
SET(OSAL_SYSTEM_OSTYPE      "posix")

And then:

make SIMULATION=arm-raspberrypi O=build-raspberry prep  
make SIMULATION=arm-raspberrypi O=build-raspberry

There is core-cpu1 in build-raspberry/arm-raspberrypi/default_cpu1/cpu1. But on Raspberry it crashes with error:

OS_Posix_GetSchedulerParams():190:Policy 1: available, min-max: 1-99
OS_Posix_GetSchedulerParams():190:Policy 2: available, min-max: 1-99
OS_Posix_TaskAPI_Impl_Init():376:Selected policy 2 for RT tasks, root task = 99
OS_Posix_TaskAPI_Impl_Init():392:Could not setschedparam in main thread: Operation not permitted (1)
OS_API_Init():151:OS_API_Impl_Init(0x1) failed to initialize: -1
OS_API_Init():231:Warning: Microsecs per sec value of 0 does not equal 1000000 (MicroSecPerTick: 0   TicksPerSecond: 0)
OS_printf():300:BUG: OS_printf() called when OSAL not initialized: CFE_PSP_Panic Called with error code = 0x%08X. Exiting.
OS_printf():300:BUG: OS_printf() called when OSAL not initialized: The cFE could not start.

What am I doing wrong?

sticky-tea commented 2 years ago

Well, the solution is to execute core-cpu1 as root

sticky-tea commented 2 years ago

Actually there is another problem. My build/exe/cpu2 folder looks like this

.
├── cf
│   ├── arducam.so
│   ├── cfe_es_startup.scr
│   ├── cfs_lib.so
│   ├── ci.so
│   ├── clyde_eps.so
│   ├── generic_reaction_wheel.so
│   ├── hk_cpy_tbl.tbl
│   ├── hk.so
│   ├── hs_amt.tbl
│   ├── hs_emt.tbl
│   ├── hs_mat.tbl
│   ├── hs.so
│   ├── hs_xct.tbl
│   ├── hwlib.so
│   ├── io_lib.so
│   ├── lc_def_adt.tbl
│   ├── lc_def_wdt.tbl
│   ├── lc.so
│   ├── novatel_oem615.so
│   ├── sample.so
│   ├── sch_def_msgtbl.tbl
│   ├── sch_def_schtbl.tbl
│   ├── sch.so
│   ├── sc.so
│   ├── to_config.tbl
│   └── to.so
└── core-cpu2

but core-cpu2 can't load libs:

EVS Port1 42/2/TO 2: Application initialized
1980-012-14:03:20.27358 ES Startup: Loading file: /cf/cs.so, APP: CS
1980-012-14:03:20.27368 ES Startup: Could not load cFE application file:/cf/cs.so. EC = 0xFFFFFFFF
1980-012-14:03:20.27528 ES Startup: Loading file: /cf/ds.so, APP: DS
1980-012-14:03:20.27538 ES Startup: Could not load cFE application file:/cf/ds.so. EC = 0xFFFFFFFF
1980-012-14:03:20.27698 ES Startup: Loading file: /cf/fm.so, APP: FM
1980-012-14:03:20.27705 ES Startup: Could not load cFE application file:/cf/fm.so. EC = 0xFFFFFFFF
1980-012-14:03:20.27867 ES Startup: Loading file: /cf/lc.so, APP: LC
...

1980-012-14:03:20.29084 ES Startup: Loading file: /cf/sample.so, APP: SAMPLE
1980-012-14:03:20.29128 ES Startup: Could not load cFE application file:/cf/sample.so. EC = 0xFFFFFFFF
1980-012-14:03:20.29289 ES Startup: Loading file: /cf/arducam.so, APP: CAM
1980-012-14:03:20.29328 ES Startup: Could not load cFE application file:/cf/arducam.so. EC = 0xFFFFFFFF
1980-012-14:03:20.29489 ES Startup: Loading file: /cf/clyde_eps.so, APP: EPS
1980-012-14:03:20.29524 ES Startup: Could not load cFE application file:/cf/clyde_eps.so. EC = 0xFFFFFFFF
1980-012-14:03:20.29685 ES Startup: Loading file: /cf/novatel_oem615.so, APP: NAV
1980-012-14:03:20.29727 ES Startup: Could not load cFE application file:/cf/novatel_oem615.so. EC = 0xFFFFFFFF
1980-012-14:03:20.29887 ES Startup: Loading file: /cf/generic_reaction_wheel.so, APP: RW
1980-012-14:03:20.29931 ES Startup: Could not load cFE application file:/cf/generic_reaction_wheel.so. EC = 0xFFFFFFFF

What is wrong?

sticky-tea commented 2 years ago

Also there are some other errors:

1980-012-14:03:20.26948 ES Startup: CI loaded and created
EVS Port1 42/2/CI 7: IO_TransUDP Error: bind socket failed. errno:98
EVS Port1 42/2/CI 6: CI - Custom Init failed.
1980-012-14:03:20.26989 CI - Application failed to initialize
1980-012-14:03:20.26991 Application CI called CFE_ES_ExitApp
...
1980-012-14:03:21.25838 CFE_ES_GetTaskInfo: Task ID Not Valid: 7
1980-012-14:03:21.25847 CFE_ES_GetTaskInfo: Task ID Not Valid: 7
EVS Port1 42/2/CFE_ES 14: Exit Application CI on Error Completed.
jphickey commented 2 years ago

Two comments I'd suggest:

  1. Check the sample file native_osconfig.cmake - this defines a couple options to make it easier to run CFS in a debug environment. You'll typically want to enable both of these when debugging. You can either just make an "arm-raspberrypi_osconfig.cmake" or you can simply change the options in your default_osconfig.cmake to make them always set. Also make sure OSAL_CONFIG_DEBUG_PRINTF is set to true somewhere in there, too.

  2. It looks like the module loading is simply because the apps were not built for CPU2. Were they listed in targets.cmake?

As for the socket bind issue, you'll have to look up what errno 98 means (its system-specific).

sticky-tea commented 2 years ago

Well, we defined OS_DEBUG_PRINTF and it shows that hwlib can't load because of undefined spi_unselect_chip, so we just delete all code with it. Idk why, but now it works Errno 98 is "Port in use", but where can I change the port in cFS configs?

sticky-tea commented 2 years ago

I just hardcoded the port

int32 IO_TransUdpBindSocket(IO_TransUdp_t * udp)
{
    if (udp == NULL)
    {
        CFE_EVS_SendEvent(IO_LIB_TRANS_UDP_EID,CFE_EVS_ERROR,
                          "IO_TransUDP Error: Null input argument. ");
        return IO_TRANS_UDP_BAD_INPUT_ERROR;
    }

    udp->sockAddr.sin_port = 1337;

    /* Bind socket to port */
    if ((bind(udp->sockId, (struct sockaddr*)&udp->sockAddr, 
              sizeof(struct sockaddr)) < 0))
    {
        CFE_EVS_SendEvent(IO_LIB_TRANS_UDP_EID, CFE_EVS_ERROR,
                          "IO_TransUDP Error: bind socket failed. errno:%d, port:%d", 
                          errno, udp->sockAddr.sin_port);
        return IO_TRANS_UDP_SOCKETBIND_ERROR; 
    }

    return IO_TRANS_UDP_NO_ERROR;
}

and it does not work, errno 98

mprather commented 2 years ago

Something worth considering -- just build natively. I understand that folks consider native compilation slow but the fact remains it's the easiest and least error prone. Further, we minimize the time cost by integrating our cFS build into our Azure Devops pipelines on a self-hosted RPi 3B+ agent. Much easier than futzing around with cross-compilations and we get the benefits of ci/cd, artifacts, etc.

Jkillelea commented 2 years ago

I've been fighting this same problem for ages. I'm trying to run cFS on a Raspberry Pi Zero, so the build times are quite long. The problem isn't limited to cFS, Cross-compiling any shared object with arm-linux-gnueabi-gcc -o [libname] [source.c] -shared seem to have this issue. This minimal example demonstrates the issue. The code fails with ./libshared.so: cannot open shared object file: No such file or directory.

sticky-tea commented 1 year ago

I've been fighting this same problem for ages. I'm trying to run cFS on a Raspberry Pi Zero, so the build times are quite long. The problem isn't limited to cFS, Cross-compiling any shared object with arm-linux-gnueabi-gcc -o [libname] [source.c] -shared seem to have this issue. This minimal example demonstrates the issue. The code fails with ./libshared.so: cannot open shared object file: No such file or directory.

Have you found any solution?