目次: Zephyr
Zephyr 2.3.0にバージョンアップしたところ、またHogeボードのビルドが通らなくなりました。
一点目はUARTドライバのCMakeListsです。zephyr_library_sources_if_kconfig() がなくなったため、書き方が変わりました。
commit 244f826e3c7333bb92fb53a65c50ee5cbd8a2ea0 Author: Carles Cufi <carles.cufi@nordicsemi.no> Date: Fri Jul 31 13:52:40 2020 +0200 cmake: remove _if_kconfig() functions This set of functions seem to be there just because of historical reasons, stemming from Kbuild. They are non-obvious and prone to errors, so remove them in favor of the `_ifdef()` ones with an explicit `CONFIG_` condition. Script used: git grep -l _if_kconfig | xargs sed -E -i "s/_if_kconfig\(\s*(\w*)/_ifdef(CONFIG_\U\1\E \1/g" Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
# drivers/serial/CMakeLists.txt
zephyr_library_sources_if_kconfig(uart_spike.c)
下記に変更
zephyr_library_sources_ifdef(CONFIG_UART_SPIKE uart_spike.c)
二点目は整数型です。Zephyrはu8_t, u16_t, u32_tのような独自の整数型を持っていましたが、C99の型に置き換えられました。drivers/serial/uart_spike.cの実装を書き換える必要があります。
commit a1b77fd589dbe7284c17b029f251426a724abd47 Author: Kumar Gala <kumar.gala@linaro.org> Date: Wed May 27 11:26:57 2020 -0500 zephyr: replace zephyr integer types with C99 types git grep -l 'u\(8\|16\|32\|64\)_t' | \ xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g" git grep -l 's\(8\|16\|32\|64\)_t' | \ xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g" Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
三点目はDT_INST_0_SPIKE_UART_SPIKE_LABELマクロです。こいつは元々、訳のわからない名前で直しようがないので、SiFiveのシリアルドライバの履歴を参考に直します。履歴を見ると2回ほど変わっています。
マクロ名のルールはDT_INST_<INSTANCE>_<COMPAT>_<PROP> だったみたいです。今初めて知りました。やっぱりこの書き方は意味不明と思ったのか、DT_INST_PROP(0, label) という形式になりました。さらに今はDT_INST_LABEL(0) という形式に落ち着いています。
★★DT_INST_PROP(0, label) になったコミット commit 8f84520130a346957ac2e2bdff1d6a51bca13af0 Author: Kumar Gala <kumar.gala@linaro.org> Date: Tue Mar 10 17:24:43 2020 -0500 drivers: serial: uart_sifive: convert to new DT API Use the new devicetree.h API instead of the legacy macros. Signed-off-by: Kumar Gala <kumar.gala@linaro.org> ★★DT_INST_LABEL(0) になったコミット commit 74d459fb66b10a5a0614a582fb0375d8b4a78c9e Author: Kumar Gala <kumar.gala@linaro.org> Date: Thu Apr 2 13:13:47 2020 -0500 drivers: serial: sifive: use DT_INST_LABEL macro Replace a few cases that should have been DT_INST_LABEL instead. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
このマクロの罠はそれだけに留まらず、ソースコードの先頭に下記マクロを定義する必要があります。依然として訳がわかりません。ZephyrはDviceTree周りの仕様が不安定です。
// zephyr/drivers/serial/uart_spike.c
#define DT_DRV_COMPAT spike_uart_spike
最後はリンカーです。これは元々のコードのコンフィグが間違っていたことに起因します。ROM領域がないのにCONFIG_XIPが有効になっていました。
$ ninja ... x-tools/riscv64-zephyr-elf/lib/gcc/riscv64-zephyr-elf/8.3.0/../../../../riscv64-zephyr-elf/bin/ld: invalid origin for memory region ROM collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.
エラーメッセージからは何が原因か読み取れないですね。こういうときはビルドディレクトリのリンカースクリプト(zephyr/linker.cmd)をうまく行く場合と、うまく行かない場合で見比べます。
/* zephyr/build/zephyr/linker.cmd */
OUTPUT_ARCH("riscv")
OUTPUT_FORMAT("elf32-littleriscv")
MEMORY
{
ROM (rx) : ORIGIN = 541065216, LENGTH = 12582912
RAM (rwx) : ORIGIN = 0x80000000, LENGTH = ((16) << 10)
IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K
}
/* zephyr/build/zephyr/linker.cmd */
OUTPUT_ARCH("riscv")
OUTPUT_FORMAT("elf32-littleriscv")
MEMORY
{
ROM (rx) : ORIGIN = ROM_BASE, LENGTH = ROM_SIZE /* ★★ここがおかしい★★ */
RAM (rwx) : ORIGIN = 0x80000000, LENGTH = ((32) << 10)
IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K
}
このスクリプトは下記のファイルから生成されているようです。HogeボードはROM領域を使う前提ではないので、領域そのものが要りません。ROM領域を葬るにはCONFIG_XIPをnにすれば良さそうです。ファイルはboards/riscv/hoge/hoge_defconfigです。
// include/arch/riscv/common/linker.ld
MEMORY
{
#ifdef CONFIG_XIP
#if DT_NODE_HAS_COMPAT_STATUS(DT_CHOSEN(zephyr_flash), soc_nv_flash, okay)
#define ROM_BASE DT_REG_ADDR(DT_CHOSEN(zephyr_flash))
#define ROM_SIZE DT_REG_SIZE(DT_CHOSEN(zephyr_flash))
#elif DT_NODE_HAS_COMPAT_STATUS(DT_CHOSEN(zephyr_flash), jedec_spi_nor, okay)
/* For jedec,spi-nor we expect the spi controller to memory map the flash
* and for that mapping to be the second register property of the spi
* controller.
*/
#define SPI_CTRL DT_PARENT(DT_CHOSEN(zephyr_flash))
#define ROM_BASE DT_REG_ADDR_BY_IDX(SPI_CTRL, 1)
#define ROM_SIZE DT_REG_SIZE_BY_IDX(SPI_CTRL, 1)
#endif
ROM (rx) : ORIGIN = ROM_BASE, LENGTH = ROM_SIZE /* ★★CONFIG_XIPが無効ならこの行ごと消える★★ */
#endif
RAM (rwx) : ORIGIN = CONFIG_SRAM_BASE_ADDRESS, LENGTH = KB(CONFIG_SRAM_SIZE)
/* Used by and documented in include/linker/intlist.ld */
IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K
}
以上の修正を入れて動かします。
$ qemu-system-riscv32 -nographic -machine spike -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel zephyr/zephyr.elf -bios none *** Booting Zephyr OS build zephyr-v2.3.0-2349-g0769bb760b2a *** Hello World! hoge
やっと動きました。良かった良かった。
< | 2020 | > | ||||
<< | < | 09 | > | >> | ||
日 | 月 | 火 | 水 | 木 | 金 | 土 |
- | - | 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 | - | - | - |
合計:
本日:
管理者: Katsuhiro Suzuki(katsuhiro( a t )katsuster.net)
This is Simple Diary 1.0
Copyright(C) Katsuhiro Suzuki 2006-2023.
Powered by PHP 8.2.15.
using GD bundled (2.1.0 compatible)(png support.)