mynewt(一) 环境配置

从Nimble了解到Apache的物联网操作系统mynewt,就想把玩一下,不过光是设置一个环境就非常的不容易,到处是坑儿,又找不到地方发问,感觉mynewt在国内根本没有机会。不像rt-thread,既有社区bbs,又有QQ群、微信群,问问题方便的很。

按照安装步骤一步一步操作,到目前还没build pass,先把遇到的问题整理下。

1.提示xcode太旧了,装不了。那我就update下呗,结果在AppStore下载不了,提示说空间不够,但我有40个G的可用空间呀,我就干脆直接删掉xcode,只装个命令行。

1
2
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select —install

2.接着装mynewt。

1
2
$ brew tap JuulLabs-OSS/mynewt
Error: Refusing to untap runtimeco/mynewt because it contains the following installed formulae or casks:mynewt-newt

解决方法:brew untap —force runtimeco/mynewt就可以了

3.update下brew

1
2
3
4
5
Mac01:~ wnnwoo$ brew update
Error: Fetching /usr/local/Homebrew failed!
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
Fetching /usr/local/Homebrew/Library/Taps/juullabs-oss/homebrew-mynewt failed!
Fetching /usr/local/Homebrew/Library/Taps/px4/homebrew-px4 failed!

试验了半天,才搞明白因为开启了VPN,不知道跟brew哪根筋冲突了,关掉VPN就OK

4.升级下mynewt的newt

1
2
3
4
5
$ brew upgrade mynewt-newt
.....
fatal: not a git repository (or any of the parent directories): .git
Building newt. This may take a minute...
go: github.com/NickBall/go-aes-key-wrap@v0.0.0-20170929221519-1c3aa3e4dfc5: Get "https://proxy.golang.org/github.com/%21nick%21ball/go-aes-key-wrap/@v/v0.0.0-20170929221519-1c3aa3e4dfc5.mod": dial tcp 172.217.160.113:443: i/o timeout

百度下有网友说是GO被长城给block了,要把GO的代理设置到国内.

go env -w GOPROXY=https://goproxy.cn

但我这里还是不行,看来不是这个问题,来来回回折腾来很久
最后找到个合适的,比较快的VPN,算是解决了这个问题。

1
2
3
4
$ which newt
/usr/local/bin/newt
$ newt version
Apache Newt version: 1.5.0

5.接着装newtmgr。

1
2
3
4
5
Mac01:~ wnnwoo$ brew install mynewt-newtmgr
Updating Homebrew...
Error: Formulae found in multiple taps:
* juullabs-oss/mynewt/mynewt-newtmgr
* runtimeco/mynewt/mynewt-newtmgr

那就去掉一个,用 Mac01:~ wnnwoo$ brew untap runtimeco/mynewt
然后再来一次

1
2
3
4
Mac01:~ wnnwoo$ brew install mynewt-newtmgr
Warning: juullabs-oss/mynewt/mynewt-newtmgr 1.7.0 is already installed, it's just not linked.
To link this version, run:
brew link mynewt-newtmgr

看来已经装上了,只欠link,那就按照提示继续。

1
2
3
4
5
6
7
8
9
Mac01:~ wnnwoo$ brew link mynewt-newtmgr

Linking /usr/local/Cellar/mynewt-newtmgr/1.7.0... 1 symlinks created.
Mac01:~ wnnwoo$ newtmgr

Mac01:~ wnnwoo$ which newtmgr
/usr/local/bin/newtmgr
Mac01:~ wnnwoo$ newtmgr version
Apache Newtmgr 1.7.0

终于搞定了。

6.接着创建project,在当前目录下command newt upgrade,这个project相关的最基础所有软件包都会被拉下来,然后按照文档指示跑下测项。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 Mac01:~ wnnwoo$ newt test @apache-mynewt-core/sys/config

...
"_close$UNIX2003", referenced from:
_flash_native_file_open in @apache-mynewt-core_hw_mcu_native.a(hal_flash.o)
_native_sock_close in @apache-mynewt-core_net_ip_native_sockets.a(native_sock.o)
_uart_pty in @apache-mynewt-core_hw_mcu_native.a(hal_uart.o)
_uart_open_dev in @apache-mynewt-core_hw_mcu_native.a(hal_uart.o)
_hal_uart_close in @apache-mynewt-core_hw_mcu_native.a(hal_uart.o)
"_getifaddrs", referenced from:
_native_sock_itf_getnext in @apache-mynewt-core_net_ip_native_sockets.a(native_itf.o)
_native_sock_itf_addr in @apache-mynewt-core_net_ip_native_sockets.a(native_itf.o)
_native_sock_itf_addr_getnext in @apache-mynewt-core_net_ip_native_sockets.a(native_itf.o)
"_poll$UNIX2003", referenced from:
_socket_task in @apache-mynewt-core_net_ip_native_sockets.a(native_sock.o)
"___bzero", referenced from:
_TEST_CASE_config_test_custom_compress in @apache-mynewt-core_sys_config_selftest-fcb2.a(config_test_custom_compress.o)
"___stack_chk_fail", referenced from:
_ctest_handle_export in @apache-mynewt-core_sys_config_selftest-fcb2.a(conf_test_fcb2.o)
_c2_handle_export in @apache-mynewt-core_sys_config_selftest-fcb2.a(conf_test_fcb2.o)
_c3_handle_export in @apache-mynewt-core_sys_config_selftest-fcb2.a(conf_test_fcb2.o)
_conf_get_stored_value in @apache-mynewt-core_sys_config.a(config_store.o)
_conf_set_value in @apache-mynewt-core_sys_config.a(config.o)
_conf_get_value in @apache-mynewt-core_sys_config.a(config.o)
_conf_commit in @apache-mynewt-core_sys_config.a(config.o)
...
"___stdoutp", referenced from:
_tu_pass_cb_self in @apache-mynewt-core_test_testutil.a(testutil.o)
_tu_fail_cb_self in @apache-mynewt-core_test_testutil.a(testutil.o)
"_openpty", referenced from:
_uart_pty in @apache-mynewt-core_hw_mcu_native.a(hal_uart.o)
"_recvfrom$UNIX2003", referenced from:
_native_sock_recvfrom in @apache-mynewt-core_net_ip_native_sockets.a(native_sock.o)
"___strncpy_chk", referenced from:
_c2_handle_get in @apache-mynewt-core_sys_config_selftest-fcb2.a(conf_test_fcb2.o)
_c2_handle_set in @apache-mynewt-core_sys_config_selftest-fcb2.a(conf_test_fcb2.o)
_conf_get_value_cb in @apache-mynewt-core_sys_config.a(config_store.o)
_native_sock_addr_to_mn_addr in @apache-mynewt-core_net_ip_native_sockets.a(native_sock.o)
_native_sock_itf_getnext in @apache-mynewt-core_net_ip_native_sockets.a(native_itf.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: Test failure(s):
Passed tests: []

看文档介绍号称mynewt支持gcc5,于是在/repos/apache-mynewt-core/compiler/sim/compiler.yml中config成gcc5, 看到明显不对,最基本的头文件都找不到。

1
2
3
4
5
6
7
8
9
10
11
 Mac01:~ wnnwoo$ newt test @apache-mynewt-core/sys/config
......
Testing package @apache-mynewt-core/sys/config/selftest-nffs
Compiling repos/apache-mynewt-core/crypto/tinycrypt/src/aes_decrypt.c
Compiling repos/apache-mynewt-mcumgr/cborattr/src/cborattr.c
In file included from /usr/local/Cellar/gcc@5/5.5.0_6/lib/gcc/5/gcc/x86_64-apple-darwin17.7.0/5.5.0/include/stdint.h:9:0,
from repos/apache-mynewt-core/crypto/tinycrypt/include/tinycrypt/aes.h:52,
from repos/apache-mynewt-core/crypto/tinycrypt/src/aes_decrypt.c:33:
/usr/local/Cellar/gcc@5/5.5.0_6/lib/gcc/5/gcc/x86_64-apple-darwin17.7.0/5.5.0/include-fixed/stdint.h:27:32: fatal error: sys/_types/_int8_t.h: No such file or directory
compilation terminated.
Error: Test failure(s):

compiler.yml中再config成gcc6,依然是一堆error,还是很多基本的API 都link不到。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Mac01:~ wnnwoo$ newt test @apache-mynewt-core/sys/config
....
ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
ld: warning: ignoring file /usr/local/Cellar/gcc@6/6.5.0_7/lib/gcc/6/libgcc_ext.10.5.dylib, missing required architecture i386 in file /usr/local/Cellar/gcc@6/6.5.0_7/lib/gcc/6/libgcc_ext.10.5.dylib (1 slices)
ld: warning: ignoring file /usr/local/Cellar/gcc@6/6.5.0_7/lib/gcc/6/gcc/x86_64-apple-darwin20.3.0/6.5.0/libgcc.a, building for macOS-i386 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, missing required architecture i386 in file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd (3 slices)
Undefined symbols for architecture i386:
"_ioctl", referenced from:
_native_sock_bind in @apache-mynewt-core_net_ip_native_sockets.a(native_sock.o)
(maybe you meant: _hal_flash_ioctl)
"_fcntl$UNIX2003", referenced from:
_native_sock_set_nonblocking in @apache-mynewt-core_net_ip_native_sockets.a(native_sock.o)
_set_nonblock in @apache-mynewt-core_hw_mcu_native.a(hal_uart.o)
"___stdoutp", referenced from:
_tu_pass_cb_self in @apache-mynewt-core_test_testutil.a(testutil.o)
_tu_fail_cb_self in @apache-mynewt-core_test_testutil.a(testutil.o)
"_fflush", referenced from:
_tu_pass_cb_self in @apache-mynewt-core_test_testutil.a(testutil.o)
_tu_fail_cb_self in @apache-mynewt-core_test_testutil.a(testutil.o)
"_strtoul", referenced from:
_c2_var_find in @apache-mynewt-core_sys_config_selftest-fcb.a(conf_test_fcb.o)
"_openpty", referenced from:
_uart_pty in @apache-mynewt-core_hw_mcu_native.a(hal_uart.o)
"_recvfrom$UNIX2003", referenced from:
_native_sock_recvfrom in @apache-mynewt-core_net_ip_native_sockets.a(native_sock.o)
"___strncpy_chk", referenced from:
_c2_handle_get in @apache-mynewt-core_sys_config_selftest-fcb.a(conf_test_fcb.o)
_c2_handle_set in @apache-mynewt-core_sys_config_selftest-fcb.a(conf_test_fcb.o)
_conf_get_value_cb in @apache-mynewt-core_sys_config.a(config_store.o)
_native_sock_addr_to_mn_addr in @apache-mynewt-core_net_ip_native_sockets.a(native_sock.o)
_native_sock_itf_getnext in @apache-mynewt-core_net_ip_native_sockets.a(native_itf.o)
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status
Error: Test failure(s):
Passed tests: []
Failed tests: [sys/config/selftest-fcb2 sys/config/selftest-nffs sys/config/selftest-fcb]

看起来是跟64位的兼容性问题,查来查去,查到Xcode的Release notes,看起来要安装旧的Xcode 9.4才行。

1
The macOS 10.14 SDK no longer contains support for compiling 32-bit applications. If developers need to compile for i386, Xcode 9.4 or earlier is required. (39858111)

后续再build下开发版上的binary试下,问题应该少些才对。
待续……