Skip to content

Commit 876aa36

Browse files
committed
zephyr: Build MicroPython as a cmake target.
Refactors the zephyr build infrastructure to build MicroPython as a cmake target, using the recently introduced core cmake rules. This change makes it possible to build the zephyr port like most other zephyr applications using west or cmake directly. It simplifies building with extra cmake arguments, such as specifying an alternate conf file or adding an Arduino shield. It also enables building the zephyr port anywhere in the host file system, which will allow regressing across multiple boards with the zephyr sanitycheck script. Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
1 parent 262d425 commit 876aa36

File tree

7 files changed

+200
-186
lines changed

7 files changed

+200
-186
lines changed

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
-v "$(pwd)":/micropython
5151
-e ZEPHYR_SDK_INSTALL_DIR=/opt/sdk/zephyr-sdk-0.11.3
5252
-e ZEPHYR_TOOLCHAIN_VARIANT=zephyr
53+
-e ZEPHYR_BASE=/zephyrproject/zephyr
5354
-w /micropython/ports/zephyr
5455
zephyrprojectrtos/ci:v0.11.8
5556
- docker ps -a
@@ -58,12 +59,12 @@ jobs:
5859
- docker exec -w /zephyrproject zephyr-ci west update
5960
- docker exec -w /zephyrproject zephyr-ci west zephyr-export
6061
script:
61-
- docker exec zephyr-ci bash -c "make clean; ./make-minimal ${MAKEOPTS}"
62-
- docker exec zephyr-ci bash -c "make clean; ./make-minimal ${MAKEOPTS} BOARD=frdm_k64f"
63-
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS}"
64-
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=frdm_k64f"
65-
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=mimxrt1050_evk"
66-
- docker exec zephyr-ci bash -c "make clean; make ${MAKEOPTS} BOARD=reel_board"
62+
- docker exec zephyr-ci west build -b qemu_x86 -- -DCONF_FILE=prj_minimal.conf
63+
- docker exec zephyr-ci west build -b frdm_k64f -- -DCONF_FILE=prj_minimal.conf
64+
- docker exec zephyr-ci west build -b qemu_x86
65+
- docker exec zephyr-ci west build -b frdm_k64f
66+
- docker exec zephyr-ci west build -b mimxrt1050_evk
67+
- docker exec zephyr-ci west build -b reel_board
6768

6869
# unix port on OSX (first in list because the build VM takes a long time to start)
6970
- stage: test

ports/zephyr/CMakeLists.txt

Lines changed: 113 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,117 @@
1+
# This file is part of the MicroPython project, http://micropython.org/
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright 2020 NXP
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
125
cmake_minimum_required(VERSION 3.13.1)
226

327
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
4-
project(NONE)
5-
6-
target_sources(app PRIVATE src/zephyr_start.c src/zephyr_getchar.c)
7-
8-
add_library(libmicropython STATIC IMPORTED)
9-
set_target_properties(libmicropython PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libmicropython.a)
10-
target_link_libraries(app PUBLIC libmicropython)
11-
12-
zephyr_get_include_directories_for_lang_as_string(C includes)
13-
zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
14-
zephyr_get_compile_definitions_for_lang_as_string(C definitions)
15-
zephyr_get_compile_options_for_lang_as_string(C options)
16-
17-
add_custom_target(
18-
outputexports
19-
COMMAND echo CC="${CMAKE_C_COMPILER}"
20-
COMMAND echo AR="${CMAKE_AR}"
21-
COMMAND echo Z_CFLAGS=${system_includes} ${includes} ${definitions} ${options}
22-
VERBATIM
23-
USES_TERMINAL
28+
project(micropython)
29+
30+
set(MICROPY_PORT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
31+
set(MICROPY_DIR ${MICROPY_PORT_DIR}/../..)
32+
set(MICROPY_TARGET micropython)
33+
34+
include(${MICROPY_DIR}/py/py.cmake)
35+
include(${MICROPY_DIR}/extmod/extmod.cmake)
36+
37+
set(MICROPY_SOURCE_PORT
38+
main.c
39+
help.c
40+
machine_i2c.c
41+
machine_pin.c
42+
modmachine.c
43+
moduos.c
44+
modusocket.c
45+
modutime.c
46+
modzephyr.c
47+
modzsensor.c
48+
uart_core.c
49+
zephyr_storage.c
50+
)
51+
list(TRANSFORM MICROPY_SOURCE_PORT PREPEND ${MICROPY_PORT_DIR}/)
52+
53+
set(MICROPY_SOURCE_LIB
54+
timeutils/timeutils.c
55+
utils/mpirq.c
56+
utils/stdout_helpers.c
57+
utils/printf.c
58+
utils/pyexec.c
59+
utils/interrupt_char.c
60+
mp-readline/readline.c
61+
oofatfs/ff.c
62+
oofatfs/ffunicode.c
63+
littlefs/lfs1.c
64+
littlefs/lfs1_util.c
65+
littlefs/lfs2.c
66+
littlefs/lfs2_util.c
2467
)
68+
list(TRANSFORM MICROPY_SOURCE_LIB PREPEND ${MICROPY_DIR}/lib/)
69+
70+
set(MICROPY_SOURCE_QSTR
71+
${MICROPY_SOURCE_PY}
72+
${MICROPY_SOURCE_EXTMOD}
73+
${MICROPY_SOURCE_LIB}
74+
${MICROPY_SOURCE_PORT}
75+
)
76+
77+
zephyr_get_include_directories_for_lang(C includes)
78+
zephyr_get_system_include_directories_for_lang(C system_includes)
79+
zephyr_get_compile_definitions_for_lang(C definitions)
80+
zephyr_get_compile_options_for_lang(C options)
81+
82+
set(MICROPY_CPP_FLAGS_EXTRA ${includes} ${system_includes} ${definitions} ${options})
83+
84+
zephyr_library_named(${MICROPY_TARGET})
85+
86+
zephyr_library_include_directories(
87+
${MICROPY_DIR}
88+
${MICROPY_PORT_DIR}
89+
${CMAKE_CURRENT_BINARY_DIR}
90+
)
91+
92+
zephyr_library_compile_options(
93+
-std=gnu99 -fomit-frame-pointer
94+
)
95+
96+
zephyr_library_compile_definitions(
97+
NDEBUG
98+
MP_CONFIGFILE=<${CONFIG_MICROPY_CONFIGFILE}>
99+
MICROPY_HEAP_SIZE=${CONFIG_MICROPY_HEAP_SIZE}
100+
FFCONF_H=\"${OOFATFS_DIR}/ffconf.h\"
101+
MICROPY_VFS_FAT=$<BOOL:${CONFIG_MICROPY_VFS_FAT}>
102+
MICROPY_VFS_LFS1=$<BOOL:${CONFIG_MICROPY_VFS_LFS1}>
103+
MICROPY_VFS_LFS2=$<BOOL:${CONFIG_MICROPY_VFS_LFS2}>
104+
)
105+
106+
zephyr_library_sources(${MICROPY_SOURCE_QSTR})
107+
108+
add_dependencies(${MICROPY_TARGET} zephyr_generated_headers)
109+
110+
include(${MICROPY_DIR}/py/mkrules.cmake)
111+
112+
target_sources(app PRIVATE
113+
src/zephyr_start.c
114+
src/zephyr_getchar.c
115+
)
116+
117+
target_link_libraries(app PRIVATE ${MICROPY_TARGET})

ports/zephyr/Kconfig

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This file is part of the MicroPython project, http://micropython.org/
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright 2020 NXP
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
menu "MicroPython Options"
26+
27+
config MICROPY_CONFIGFILE
28+
string "Configuration file"
29+
default "mpconfigport_minimal.h"
30+
31+
config MICROPY_HEAP_SIZE
32+
int "Heap size"
33+
default 16384
34+
35+
config MICROPY_VFS_FAT
36+
bool "FatFS file system"
37+
38+
config MICROPY_VFS_LFS1
39+
bool "LittleFs version 1 file system"
40+
41+
config MICROPY_VFS_LFS2
42+
bool "LittleFs version 2 file system"
43+
44+
endmenu # MicroPython Options
45+
46+
source "Kconfig.zephyr"

ports/zephyr/Makefile

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy