Skip to content

Commit

Permalink
make platform zephyr stand alone (#19504)
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-telecom authored and pull[bot] committed Aug 19, 2022
1 parent b447066 commit 3188616
Show file tree
Hide file tree
Showing 36 changed files with 1,828 additions and 6 deletions.
15 changes: 15 additions & 0 deletions build_overrides/zephyr.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# place holder
10 changes: 10 additions & 0 deletions config/zephyr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Zephyr build and configuration files

This directory contains build scripts and common configuration files used by
CHIP Zephyr applications. It is structured as follows:

| File/Folder | Contents |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| chip-gn | GN project used to build selected CHIP libraries with the _Zephyr_ platform integration layer |
| chip-module | CMake wrapper for the GN project defined in `chip-gn` directory, and other components that allow one to use CHIP as a Zephyr module |
| app | Common and optional Kconfig configuration files that can be used in Zephyr applications |
25 changes: 25 additions & 0 deletions config/zephyr/app/copy-flashbundle-firmware.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Copyright (c) 2022 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Copy the merged.hex file if it exists, otherwise copy zephyr.hex

set(HEX_NAME merged.hex)

if(EXISTS "zephyr/${HEX_NAME}")
configure_file("zephyr/${HEX_NAME}" "${FLASHBUNDLE_FIRMWARE}" COPYONLY)
else()
configure_file("zephyr/${KERNEL_HEX_NAME}" "${FLASHBUNDLE_FIRMWARE}" COPYONLY)
endif()
6 changes: 6 additions & 0 deletions config/zephyr/app/enable-gnu-std.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_library(gnu17 INTERFACE)
target_compile_options(gnu17
INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++17>
-D_SYS__PTHREADTYPES_H_)
target_link_libraries(app PRIVATE gnu17)
55 changes: 55 additions & 0 deletions config/zephyr/app/flashing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Copyright (c) 2021 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Adds rules to generate a flashing wrapper script for an nrfconnect firmware.

set(FLASHBUNDLE_FLASHER_COMMON ${CMAKE_PROJECT_NAME}/firmware_utils.py)
set(FLASHBUNDLE_FLASHER_PLATFORM ${CMAKE_PROJECT_NAME}/nrfconnect_firmware_utils.py)
set(FLASHBUNDLE_FLASHER_WRAPPER ${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.flash.py)
set(FLASHBUNDLE_FIRMWARE ${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.hex)
set(FLASHBUNDLE_FILES ${FLASHBUNDLE_FLASHER_COMMON} ${FLASHBUNDLE_FLASHER_PLATFORM} ${FLASHBUNDLE_FLASHER_WRAPPER} ${FLASHBUNDLE_FIRMWARE})

get_filename_component(FLASHBUNDLE_FIRMWARE_BASENAME ${FLASHBUNDLE_FIRMWARE} NAME)

list(JOIN FLASHBUNDLE_FILES "\n" FLASHBUNDLE_MANIFEST)

file(GENERATE
OUTPUT ${CMAKE_PROJECT_NAME}.flashbundle.txt
CONTENT "${FLASHBUNDLE_MANIFEST}\n"
)

add_custom_command(OUTPUT "${FLASHBUNDLE_FLASHER_COMMON}"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${PROJECT_SOURCE_DIR}/third_party/connectedhomeip/scripts/flashing/firmware_utils.py" "${FLASHBUNDLE_FLASHER_COMMON}"
VERBATIM)

add_custom_command(OUTPUT "${FLASHBUNDLE_FLASHER_PLATFORM}"
COMMAND ${CMAKE_COMMAND} ARGS -E copy "${PROJECT_SOURCE_DIR}/third_party/connectedhomeip/scripts/flashing/nrfconnect_firmware_utils.py" "${FLASHBUNDLE_FLASHER_PLATFORM}"
VERBATIM)

add_custom_command(OUTPUT "${FLASHBUNDLE_FIRMWARE}"
DEPENDS zephyr/${KERNEL_HEX_NAME}
COMMAND ${CMAKE_COMMAND} ARGS -DFLASHBUNDLE_FIRMWARE=${FLASHBUNDLE_FIRMWARE} -DKERNEL_HEX_NAME=${KERNEL_HEX_NAME} -P "${CHIP_ROOT}/config/nrfconnect/app/copy-flashbundle-firmware.cmake"
VERBATIM)

add_custom_command(OUTPUT "${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.flash.py"
COMMAND ${python}
"${PROJECT_SOURCE_DIR}/third_party/connectedhomeip/scripts/flashing/gen_flashing_script.py" nrfconnect
--output "${FLASHBUNDLE_FLASHER_WRAPPER}"
--application "${FLASHBUNDLE_FIRMWARE_BASENAME}"
COMMENT "To flash ${FLASHBUNDLE_FIRMWARE_BASENAME} run ${FLASHBUNDLE_FLASHER_WRAPPER}"
VERBATIM)

add_custom_target(flashing_script DEPENDS ${FLASHBUNDLE_FILES})
24 changes: 24 additions & 0 deletions config/zephyr/app/overlay-usb_support.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

CONFIG_GPIO=y

CONFIG_USB=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_UART_CONSOLE=y

CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y
29 changes: 29 additions & 0 deletions config/zephyr/chip-gn/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
target_cpu = ""
target_os = "zephyr"

import("${chip_root}/config/zephyr/chip-gn/args.gni")
}
40 changes: 40 additions & 0 deletions config/zephyr/chip-gn/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("${chip_root}/build/chip/tests.gni")

assert(current_os == "zephyr")

declare_args() {
chip_build_example_providers = false
}

group("zephyr") {
deps = [ "${chip_root}/src/lib" ]

if (chip_build_tests) {
deps += [ "${chip_root}/src:tests" ]
}

if (chip_build_example_providers) {
deps += [ "${chip_root}/examples/providers:device_info_provider" ]
}
}

group("default") {
deps = [ ":zephyr" ]
}
27 changes: 27 additions & 0 deletions config/zephyr/chip-gn/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")

chip_device_platform = "zephyr"

chip_build_tests = false

chip_project_config_include = ""
chip_system_project_config_include = ""
chip_ble_project_config_include = ""

custom_toolchain = "${chip_root}/config/zephyr/chip-gn/toolchain:zephyr"

pw_build_PIP_CONSTRAINTS = [ "${chip_root}/scripts/constraints.txt" ]
33 changes: 33 additions & 0 deletions config/zephyr/chip-gn/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/toolchain/gcc_toolchain.gni")
import("//build_overrides/build.gni")

declare_args() {
zephyr_ar = ""
zephyr_cc = ""
zephyr_cxx = ""
}

gcc_toolchain("zephyr") {
ar = zephyr_ar
cc = zephyr_cc
cxx = zephyr_cxx

toolchain_args = {
current_os = "zephyr"
is_clang = false
}
}
Loading

0 comments on commit 3188616

Please sign in to comment.