Skip to content

Commit 37b2fe6

Browse files
authored
Added compile support for NuttX system. (#31236)
This is a basic version of compile support and only x86 simulator lightning-app is supported now The compilation method is shown below: ./scripts/build/build_examples.py --target nuttx-x64-light build and compiled binaries are in the out/nuttx-x64-light directory. Detailed introduction about NuttX system can refer to this link: https://github.com/apache/nuttx Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
1 parent 3f9bac2 commit 37b2fe6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+12740
-9
lines changed

.github/.wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ NTP
965965
nullable
966966
nullptr
967967
NUM
968+
NuttX
968969
NVM
969970
NVS
970971
nwdiag

.github/workflows/examples-nuttx.yaml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Build example - NuttX
16+
17+
on:
18+
push:
19+
pull_request:
20+
merge_group:
21+
workflow_dispatch:
22+
23+
concurrency:
24+
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
25+
cancel-in-progress: true
26+
27+
env:
28+
CHIP_NO_LOG_TIMESTAMPS: true
29+
30+
jobs:
31+
nuttx:
32+
name: NuttX
33+
34+
runs-on: ubuntu-latest
35+
if: github.actor != 'restyled-io[bot]'
36+
37+
container:
38+
image: ghcr.io/project-chip/chip-build-nuttx:51
39+
volumes:
40+
- "/tmp/bloat_reports:/tmp/bloat_reports"
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
- name: Checkout submodules & Bootstrap
45+
uses: ./.github/actions/checkout-submodules-and-bootstrap
46+
with:
47+
platform: nuttx
48+
extra-submodule-parameters: " --recursive"
49+
- name: Build example simulator NuttX Lighting App
50+
run: |
51+
./scripts/run_in_build_env.sh \
52+
"./scripts/build/build_examples.py \
53+
--target nuttx-x64-light \
54+
build \
55+
"

.github/workflows/lint.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ jobs:
9090
--skip-dir platform/webos \
9191
--skip-dir platform/Zephyr \
9292
--skip-dir test_driver \
93+
--skip-dir platform/NuttX \
9394
--known-failure app/app-platform/ContentApp.cpp \
9495
--known-failure app/app-platform/ContentApp.h \
9596
--known-failure app/app-platform/ContentAppPlatform.cpp \
@@ -205,7 +206,7 @@ jobs:
205206
# TODO: TLVDebug should ideally not be excluded here.
206207
# TODO: protocol_decoder.cpp should ideally not be excluded here.
207208
# TODO: PersistentStorageMacros.h should ideally not be excluded here.
208-
git grep -I -n "PRI.64" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)examples/chip-tool' ':(exclude)examples/tv-casting-app' ':(exclude)src/app/MessageDef/MessageDefHelper.cpp' ':(exclude)src/app/tests/integration/chip_im_initiator.cpp' ':(exclude)src/lib/core/TLVDebug.cpp' ':(exclude)src/lib/dnssd/tests/TestTxtFields.cpp' ':(exclude)src/lib/format/protocol_decoder.cpp' ':(exclude)src/lib/support/PersistentStorageMacros.h' ':(exclude)src/messaging/tests/echo/echo_requester.cpp' ':(exclude)src/platform/Linux' ':(exclude)src/platform/Ameba' ':(exclude)src/platform/ESP32' ':(exclude)src/platform/Darwin' ':(exclude)src/darwin' ':(exclude)src/platform/webos' ':(exclude)zzz_generated/chip-tool' ':(exclude)src/tools/chip-cert/Cmd_PrintCert.cpp' && exit 1 || exit 0
209+
git grep -I -n "PRI.64" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)examples/chip-tool' ':(exclude)examples/tv-casting-app' ':(exclude)src/app/MessageDef/MessageDefHelper.cpp' ':(exclude)src/app/tests/integration/chip_im_initiator.cpp' ':(exclude)src/lib/core/TLVDebug.cpp' ':(exclude)src/lib/dnssd/tests/TestTxtFields.cpp' ':(exclude)src/lib/format/protocol_decoder.cpp' ':(exclude)src/lib/support/PersistentStorageMacros.h' ':(exclude)src/messaging/tests/echo/echo_requester.cpp' ':(exclude)src/platform/Linux' ':(exclude)src/platform/Ameba' ':(exclude)src/platform/ESP32' ':(exclude)src/platform/Darwin' ':(exclude)src/darwin' ':(exclude)src/platform/webos' ':(exclude)zzz_generated/chip-tool' ':(exclude)src/tools/chip-cert/Cmd_PrintCert.cpp' ':(exclude)src/platform/NuttX' && exit 1 || exit 0
209210
210211
# git grep exits with 0 if it finds a match, but we want
211212
# to fail (exit nonzero) on match. And we want to exclude this file,

build/config/compiler/BUILD.gn

+5
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ config("strict_warnings") {
271271

272272
cflags_cc = [ "-Wnon-virtual-dtor" ]
273273

274+
if (current_os == "nuttx") {
275+
cflags -= [ "-Wshadow" ]
276+
cflags_cc -= [ "-Wnon-virtual-dtor" ]
277+
}
278+
274279
configs = []
275280
ldflags = []
276281

config/nuttx/chip-gn/.gn

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
import("//build_overrides/chip.gni")
17+
18+
# The location of the build configuration file.
19+
buildconfig = "${build_root}/config/BUILDCONFIG.gn"
20+
21+
# CHIP uses angle bracket includes.
22+
check_system_includes = true
23+
24+
default_args = {
25+
target_cpu = ""
26+
target_os = "nuttx"
27+
28+
import("${chip_root}/config/nuttx/chip-gn/args.gni")
29+
}

config/nuttx/chip-gn/BUILD.gn

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
import("//build_overrides/chip.gni")
17+
18+
import("${chip_root}/build/chip/tests.gni")
19+
20+
assert(current_os == "nuttx")
21+
22+
declare_args() {
23+
chip_build_example_providers = false
24+
chip_example_lighting = false
25+
}
26+
27+
static_library("nuttx") {
28+
output_name = "libchipnuttx"
29+
30+
public_deps = [
31+
"${chip_root}/examples/platform/linux:app-main",
32+
"${chip_root}/src/lib",
33+
]
34+
35+
if (chip_build_tests) {
36+
public_deps += [ "${chip_root}/src:tests" ]
37+
}
38+
39+
if (chip_build_example_providers) {
40+
public_deps += [ "${chip_root}/examples/providers:device_info_provider" ]
41+
}
42+
43+
if (chip_example_lighting) {
44+
public_deps += [
45+
"${chip_root}/examples/lighting-app/lighting-common",
46+
"${chip_root}/examples/lighting-app/lighting-common:lighting-manager",
47+
]
48+
}
49+
50+
output_dir = "${root_out_dir}/lib"
51+
52+
complete_static_lib = true
53+
}
54+
55+
group("default") {
56+
deps = [ ":nuttx" ]
57+
}

config/nuttx/chip-gn/args.gni

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
17+
import("${chip_root}/src/crypto/crypto.gni")
18+
19+
chip_device_platform = "nuttx"
20+
21+
chip_build_tests = false
22+
23+
chip_project_config_include = ""
24+
chip_system_project_config_include = ""
25+
chip_ble_project_config_include = ""
26+
27+
chip_crypto = "mbedtls"
28+
chip_external_mbedtls = true
29+
30+
custom_toolchain = "${chip_root}/config/nuttx/chip-gn/toolchain:nuttx"
31+
32+
pw_build_PIP_CONSTRAINTS = [ "${chip_root}/scripts/setup/constraints.txt" ]
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build/toolchain/gcc_toolchain.gni")
16+
import("//build_overrides/build.gni")
17+
18+
declare_args() {
19+
nuttx_ar = ""
20+
nuttx_cc = ""
21+
nuttx_cxx = ""
22+
}
23+
24+
gcc_toolchain("nuttx") {
25+
ar = nuttx_ar
26+
cc = nuttx_cc
27+
cxx = nuttx_cxx
28+
29+
toolchain_args = {
30+
current_os = "nuttx"
31+
is_clang = false
32+
}
33+
}

examples/lighting-app/linux/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void ApplicationShutdown()
9595
}
9696
}
9797

98-
int main(int argc, char * argv[])
98+
extern "C" int main(int argc, char * argv[])
9999
{
100100
if (ChipLinuxAppInit(argc, argv) != 0)
101101
{

scripts/build/build/targets.py

+18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from builders.mbed import MbedApp, MbedBoard, MbedBuilder, MbedProfile
2828
from builders.mw320 import MW320App, MW320Builder
2929
from builders.nrf import NrfApp, NrfBoard, NrfConnectBuilder
30+
from builders.nuttx import NuttXApp, NuttXBoard, NuttXBuilder
3031
from builders.nxp import NxpApp, NxpBoard, NxpBuilder
3132
from builders.openiotsdk import OpenIotSdkApp, OpenIotSdkBuilder, OpenIotSdkCryptoBackend
3233
from builders.qpg import QpgApp, QpgBoard, QpgBuilder
@@ -324,6 +325,22 @@ def BuildNrfTarget():
324325
return target
325326

326327

328+
def BuildNuttXTarget():
329+
target = BuildTarget('nuttx', NuttXBuilder)
330+
331+
# Boards
332+
target.AppendFixedTargets([
333+
TargetPart('x64', board=NuttXBoard.SIM),
334+
])
335+
336+
# Apps
337+
target.AppendFixedTargets([
338+
TargetPart('light', app=NuttXApp.LIGHT),
339+
])
340+
341+
return target
342+
343+
327344
def BuildAndroidTarget():
328345
target = BuildTarget('android', AndroidBuilder)
329346

@@ -795,6 +812,7 @@ def BuildOpenIotSdkTargets():
795812
BuildMW320Target(),
796813
BuildNrfTarget(),
797814
BuildNrfNativeTarget(),
815+
BuildNuttXTarget(),
798816
BuildQorvoTarget(),
799817
BuildStm32Target(),
800818
BuildTizenTarget(),

scripts/build/builders/nuttx.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import logging
16+
import os
17+
from enum import Enum, auto
18+
19+
from .gn import Builder
20+
21+
22+
class NuttXApp(Enum):
23+
LIGHT = auto()
24+
25+
def ExampleName(self):
26+
if self == NuttXApp.LIGHT:
27+
return 'lighting-app'
28+
else:
29+
raise Exception('Unknown app type: %r' % self)
30+
31+
def AppNamePrefix(self, chip_name):
32+
if self == NuttXApp.LIGHT:
33+
return ('chip-%s-lighting-example' % chip_name)
34+
else:
35+
raise Exception('Unknown app type: %r' % self)
36+
37+
38+
class NuttXBoard(Enum):
39+
SIM = auto()
40+
41+
42+
def NuttXTarget(board, app):
43+
if board == NuttXBoard.SIM:
44+
if app == NuttXApp.LIGHT:
45+
return 'sim:matter'
46+
return 'none'
47+
48+
49+
class NuttXBuilder(Builder):
50+
51+
def __init__(self,
52+
root,
53+
runner,
54+
app: NuttXApp = NuttXApp.LIGHT,
55+
board: NuttXBoard = NuttXBoard.SIM,
56+
):
57+
58+
nuttx_chip = 'nuttx'
59+
60+
super(NuttXBuilder, self).__init__(
61+
root=os.path.join(root, 'examples',
62+
app.ExampleName(), nuttx_chip),
63+
runner=runner
64+
)
65+
66+
self.chip_name = nuttx_chip
67+
self.app = app
68+
self.board = board
69+
70+
def generate(self):
71+
self._Execute(['mkdir', '-p', self.output_dir],
72+
title='Generating ' + self.identifier)
73+
74+
def _build(self):
75+
logging.info('Compiling NuttX %s at %s, ',
76+
NuttXTarget(self.board, self.app), self.output_dir)
77+
nuttx_dir = os.path.join(os.sep, 'opt', 'nuttx', 'nuttx')
78+
79+
self._Execute(['cmake', '-S', nuttx_dir, '-B', self.output_dir, '-DCHIP_ROOT=' + os.getenv('PW_PROJECT_ROOT'),
80+
'-DBOARD_CONFIG=' + NuttXTarget(self.board, self.app),
81+
'-DCMAKE_C_COMPILER=/opt/nuttx/gcc-13/bin/gcc',
82+
'-DCMAKE_CXX_COMPILER=/opt/nuttx/gcc-13/bin/g++',
83+
'-GNinja'],
84+
title='Building ' + self.identifier)
85+
self._Execute(['cmake', '--build', self.output_dir])
86+
87+
def build_outputs(self):
88+
logging.info('Compiling outputs NuttX at %s', self.output_dir)
89+
items = {
90+
'%s.out' % self.app.AppNamePrefix(self.chip_name):
91+
os.path.join(self.output_dir, '%s.out' %
92+
self.app.AppNamePrefix(self.chip_name)),
93+
'%s.out.map' % self.app.AppNamePrefix(self.chip_name):
94+
os.path.join(self.output_dir,
95+
'%s.out.map' % self.app.AppNamePrefix(self.chip_name)),
96+
}
97+
98+
return items

0 commit comments

Comments
 (0)