Modify zephyr's Driver with out of tree procedure

Hi

I have been using my out of tree driver for my BG95 module, which I have copy pasted from the zephyr's quectel_bg9x driver (drivers/modem/quectel-bg9x) and its required files into respective folders and renamed as quectel-bg95cd and made a few additions to the code. Following is my folder structure

boards
└── ...

drivers
└── modem
    ├── CMakeLists
    ├── Kconfig
    ├── Kconfig.quectel-bg95cd
    ├── modem_context.c
    ├── modem_cmd_handler.c
    ├── modem_iface_uart_async.c
    ├── modem_iface_uart_interrupt.c
    ├── modem_socket.c
    └──quectel_bg95cd.c
└── zephyr
    └── module.yml

dts
└── bindings
    └── modem
        └── quectel,bg95cd.yaml

include
└── app
    └── drivers
        └── modem
            ├── quectel-bg95cd.h
            ├── modem_socket.h
            ├── modem_context.h
            ├── modem_cmd_handler.h
            └── modem_iface_uartt.h

I set the following in my main CMakeLists

  list(APPEND ZEPHYR_EXTRA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/drivers)
  zephyr_include_directories(include/app/drivers)

I need the "quectel-bg95cd.h" to be included in my main.c file, that's why I have placed them in include/app/drivers/modem folder, so I can have access to my added functions and also to strcut's like sockaddr, modem_cmd from my main.c file

I have changed my #include "quectel-bg9x.h" into <quectel-bg95cd.h> in quectel-bg95cd.c file, and also able to include it in main.c as #include <modem/quectel-bg95cd.h>

It builds and works fine till ncs v2.5.2, when I upgraded to ncs v2.6.0, I face the following error

/include/app/drivers/modem/modem_socket.h:20:10: fatal error: sockets_internal.h: No such file or directory

I could able to see a change in the CMakeLists in zephyr's drivers/modem/CMakeLists , is that the reason I'm unable to build?? or am I doing it wrong??

For reference ,I attach my drivers/modem/CMakeLists.txt (I have tried many cmds trying to resolve but didn't help)

# SPDX-License-Identifier: Apache-2.0

zephyr_library()

#zephyr_library_sources_ifdef(CONFIG_MODEM_RECEIVER modem_receiver.c)
#zephyr_library_sources_ifdef(CONFIG_MODEM_SHELL modem_shell.c)

#zephyr_library_sources_ifdef(CONFIG_MODEM_CONTEXT modem_context.c)

#zephyr_library_sources_ifdef(CONFIG_MODEM_IFACE_UART_INTERRUPT modem_iface_uart_interrupt.c)
#zephyr_library_sources_ifdef(CONFIG_MODEM_IFACE_UART_ASYNC modem_iface_uart_async.c)
#zephyr_library_sources_ifdef(CONFIG_MODEM_CMD_HANDLER modem_cmd_handler.c)
#zephyr_library_sources_ifdef(CONFIG_MODEM_SOCKET modem_socket.c)

zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/ip)
zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/lib/sockets)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers/modem)
zephyr_library_include_directories(${APPLICATION_BASE}/include/app/drivers/modem)

zephyr_library_include_directories(.)
# zephyr_syscall_header(${APPLICATION_BASE}/include/app/drivers/modem/modem_test.h)
zephyr_syscall_header(${ZEPHYR_BASE}/drivers/modem/modem_context.h)
zephyr_syscall_header(${ZEPHYR_BASE}/drivers/modem/modem_socket.h)
zephyr_syscall_header(${ZEPHYR_BASE}/drivers/modem/modem_cmd_handler.h)
zephyr_syscall_header(${ZEPHYR_BASE}/drivers/modem/modem_iface_uart.h)

if(CONFIG_MODEM_QUECTEL_BG95CD)
	zephyr_library_sources(quectel-bg95cd.c)
endif()

Kindly guide me with this. Thanks.

Parents
  • I had a similar issue (difficulties making a custom modem driver work), and I finally got it working so I thought I would share my key findings here to help the next poor soul to stumble here while working on a similar problem.

    As mentioned above, when building your code with your custom driver amendment, you need to have list(APPEND ZEPHYR_EXTRA_MODULES path_to/my_module but a key detail that is easy to miss is that it needs to be BEFORE the step where you call find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}). This is probably the main thing that tripped me up for a long time.

    # - this 'append extra modules' step must be prior to the 'find package zephyr' step!
    list(APPEND ZEPHYR_EXTRA_MODULES ${MAIN_REPO_DIRECTORY}/custom_driver_module)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    
    project(app)

    Use zephyr_library_amend() as mentioned above, to specify how the driver is to be built as an addition to an existing driver library. Don't include duplicates of the existing source files from the driver library you're trying to add to or you'll you'll get 'multiple definitions' conflicts, keep it to just your new functions etc. Duplicate + modified Kconfig files don't seem to be an issue. Based on this, having files like modem_context.c in your custom driver will cause conflicts, unless your copy only adds new function names.


    The general folder structure shown in the original post should work. You need the dts/bindings/my_module/company,thing.yml file so that you can specify your thing in the devicetree files in the 'compatible' property. I didn't find that I needed the include/app/drivers/ portion, I just put my quectel-bg95cd.h equivalent into the drivers/modem folder.

    This was my folder structure which worked for me:

    boards
    └── ...
    
    custom_driver_module
    ├── drivers
    |   ├── modem
    |   |   ├── CMakeLists
    |   |   ├── Kconfig
    |   |   ├── Kconfig.quectel-bg95cd
    |   |   ├── quectel_bg95cd.c
    |   |   └── quectel_bg95cd.h
    |   ├── CMakeLists.txt
    |   └── Kconfig
    ├── dts
    |   └── bindings
    |       └── modem
    |           └── quectel,bg95cd.yaml
    ├── zephyr
    |   └── module.yml
    ├── CMakeLists.txt
    └── Kconfig
    
    app
    ├── boards
    |   └── ...
    ├── src
    |   └── ...
    └── CMakeLists.txt

    I hope this helps someone.

Reply
  • I had a similar issue (difficulties making a custom modem driver work), and I finally got it working so I thought I would share my key findings here to help the next poor soul to stumble here while working on a similar problem.

    As mentioned above, when building your code with your custom driver amendment, you need to have list(APPEND ZEPHYR_EXTRA_MODULES path_to/my_module but a key detail that is easy to miss is that it needs to be BEFORE the step where you call find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}). This is probably the main thing that tripped me up for a long time.

    # - this 'append extra modules' step must be prior to the 'find package zephyr' step!
    list(APPEND ZEPHYR_EXTRA_MODULES ${MAIN_REPO_DIRECTORY}/custom_driver_module)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    
    project(app)

    Use zephyr_library_amend() as mentioned above, to specify how the driver is to be built as an addition to an existing driver library. Don't include duplicates of the existing source files from the driver library you're trying to add to or you'll you'll get 'multiple definitions' conflicts, keep it to just your new functions etc. Duplicate + modified Kconfig files don't seem to be an issue. Based on this, having files like modem_context.c in your custom driver will cause conflicts, unless your copy only adds new function names.


    The general folder structure shown in the original post should work. You need the dts/bindings/my_module/company,thing.yml file so that you can specify your thing in the devicetree files in the 'compatible' property. I didn't find that I needed the include/app/drivers/ portion, I just put my quectel-bg95cd.h equivalent into the drivers/modem folder.

    This was my folder structure which worked for me:

    boards
    └── ...
    
    custom_driver_module
    ├── drivers
    |   ├── modem
    |   |   ├── CMakeLists
    |   |   ├── Kconfig
    |   |   ├── Kconfig.quectel-bg95cd
    |   |   ├── quectel_bg95cd.c
    |   |   └── quectel_bg95cd.h
    |   ├── CMakeLists.txt
    |   └── Kconfig
    ├── dts
    |   └── bindings
    |       └── modem
    |           └── quectel,bg95cd.yaml
    ├── zephyr
    |   └── module.yml
    ├── CMakeLists.txt
    └── Kconfig
    
    app
    ├── boards
    |   └── ...
    ├── src
    |   └── ...
    └── CMakeLists.txt

    I hope this helps someone.

Children
No Data
Related