[RISC-V MCU 应用开发] 全志V853 RISC-V内核E907 核心固件加载

[复制链接]
2750|0
 楼主| 神棍地海棠 发表于 2022-12-5 10:18 | 显示全部楼层 |阅读模式
本帖最后由 神棍地海棠 于 2022-12-5 10:22 编辑

在调试阶段,需要经常修改 E907 的代码。而为了调试代码多次刷写系统非常麻烦。其实 E907 核心的固件可以在 Linux 系统内加载,本文将描述如何在 Linux 系统内启动 E907 核心、加载 E907 固件、关闭 E907 核心。

如何加载
从上一篇文章可以知道,这里使用 remoteproc 管理小核的生命周期。
remoteproc 框架抽象出硬件差异,允许不同的平台/架构来控制(开机、加载固件、关机)这些远程处理器,此外,还为支持这种通信的远程处理器添加了 rpmsg virtio 设备。这样,特定平台的 remoteproc 驱动程序只需要提供一些低级处理程序,然后所有 rpmsg 驱动程序就可以正常工作。

作用:
  • 从文件系统加载固件
  • 准备远程处理器所需资源
  • 注册一个 rpmsg virtio 设备
  • 提供对要提供对远程处理器的生命周期进行管理
2022-07-19-15-33-28-image.png
所以固件的加载流程大致如下:
  1. <span style="color: rgb(54, 70, 78); font-family: _, SFMono-Regular, Consolas, Menlo, monospace; font-size: 13.6px; white-space: pre; background-color: rgb(245, 245, 245);">1. 加载固件
  2.    1. 调用 firmware 接口获取文件系统中的固件
  3.    2. 解析固件的 resource_table 段,该段有如下内容
  4.       1. 声明需要的内存(Linux 为其分配)
  5.       2. 声明使用的 vdev(固定为一个)
  6.       3. 声明使用的 vring(固定为两个)
  7.    3. 将固件加载到指定地址
  8. 2. 注册 rpmsg virtio 设备
  9.    1. 提供 vdev->ops(基于 virtio 接口实现的)
  10.    2. 与 rpmsg_bus 驱动匹配,完成 rpmsg 初始化
  11. 3. 启动小核
  12.    1. 调用 rproc->ops->start</span>

Kernel 的配置
首先需要配置设备树,预留 E907 核心内存,buffer 内存,vring 内存等。并正确配置 rproc 与 rpbuf,也不要忘记配置 firmware-name,下面的配置示例为测试固件所使用的地址。不同的固件地址可能不同。
  1. reserved-memory {
  2.     e907_dram: riscv_memserve {
  3.         reg = <0x0 0x48000000 0x0 0x00400000>;
  4.         no-map;
  5.     };

  6.     vdev0buffer: vdev0buffer@47000000 {
  7.         /* 256k reserved for shared mem pool */
  8.         compatible = "shared-dma-pool";
  9.         reg = <0x0 0x47000000 0x0 0x40000>;
  10.         no-map;
  11.     };

  12.     vdev0vring0: vdev0vring0@47040000 {
  13.         reg = <0x0 0x47040000 0x0 0x20000>;
  14.         no-map;
  15.     };

  16.     vdev0vring1: vdev0vring1@47060000 {
  17.         reg = <0x0 0x47060000 0x0 0x20000>;
  18.         no-map;
  19.     };
  20. };

  21. e907_rproc: e907_rproc[url=home.php?mod=space&uid=2514928]@0[/url] {
  22.     compatible = "allwinner,sun8iw21p1-e907-rproc";
  23.     clock-frequency = <600000000>;
  24.     memory-region = <&e907_dram>, <&vdev0buffer>,
  25.                     <&vdev0vring0>, <&vdev0vring1>;
  26.     mboxes = <&msgbox 0>;
  27.     mbox-names = "mbox-chan";
  28.     iommus = <&mmu_aw 5 1>;

  29.     memory-mappings =
  30.         /* DA              len         PA */
  31.         /* DDR for e907  */
  32.         < 0x48000000 0x00400000 0x48000000 >;
  33.     core-name = "sun8iw21p1-e907";
  34.     firmware-name = "melis-elf";
  35.     status = "okay";
  36. };

  37. rpbuf_controller0: rpbuf_controller@0 {
  38.     compatible = "allwinner,rpbuf-controller";
  39.     remoteproc = <&e907_rproc>;
  40.     ctrl_id = <0>;    /* index of /dev/rpbuf_ctrl */
  41.     iommus = <&mmu_aw 5 1>;
  42.     status = "okay";
  43. };

  44. rpbuf_sample: rpbuf_sample@0 {
  45.     compatible = "allwinner,rpbuf-sample";
  46.     rpbuf = <&rpbuf_controller0>;
  47.     status = "okay";
  48. };



接下来需要配置 kernel 选项,配置驱动。
  1. make kernel_menuconfig


并勾选以下驱动:
  1. Device Drivers  --->
  2.   Remoteproc drivers  --->
  3.     <*> SUNXI remote processor support
  4.   Rpmsg drivers  --->
  5.     <*> allwinnertech rpmsg driver for v853-e907
  6.     <*> allwinnertech rpmsg hearbeat driver
  7.     <*> Virtio RPMSG bus driver
  8.     <*> sunxi rpmsg ctrl driver
  9.   [*] Mailbox Hardware Support  --->
  10.     <*>   sunxi Mailbox
  11.     <*>   sunxi rv32 standby driver

2022-07-19-15-58-51-image.png

我们可以使用 cat 命令检查小核目前的状况
  1. cat /sys/kernel/debug/remoteproc/remoteproc0/state
2022-07-19-16-04-59-image.png

可以看到目前是 offline 的。可以尝试使用 echo 启动小核
  1. >echo start <font color="rgb(154, 110, 58)">></font> <font color="rgb(154, 110, 58)">/</font>sys<font color="rgb(154, 110, 58)">/</font>kernel<font color="rgb(154, 110, 58)">/</font>debug<font color="rgb(154, 110, 58)">/</font>remoteproc<font color="rgb(154, 110, 58)">/</font>remoteproc0<font color="rgb(154, 110, 58)">/</font>state

2022-07-19-16-07-40-image.png

可以看到,由于我们没有加载固件,小核启动失败。此时我们需要把准备好的固件放置到开发板的 lib/firmware 文件夹内。这里我们使用 adb 上传小核固件。
2022-07-19-16-17-14-image.png

然后我们将固件名称置于 firmware 节点内,并启动固件。
  1. echo e907_test<font color="rgb(153, 153, 153)">.</font>elf <font color="rgb(154, 110, 58)">></font> <font color="rgb(154, 110, 58)">/</font>sys<font color="rgb(154, 110, 58)">/</font>kernel<font color="rgb(154, 110, 58)">/</font>debug<font color="rgb(154, 110, 58)">/</font>remoteproc<font color="rgb(154, 110, 58)">/</font>remoteproc0<font color="rgb(154, 110, 58)">/</font>firmwareecho start <font color="rgb(154, 110, 58)">></font> <font color="rgb(154, 110, 58)">/</font>sys<font color="rgb(154, 110, 58)">/</font>kernel<font color="rgb(154, 110, 58)">/</font>debug<font color="rgb(154, 110, 58)">/</font>remoteproc<font color="rgb(154, 110, 58)">/</font>remoteproc0<font color="rgb(154, 110, 58)">/</font>state

此时可以看到 remote processor e907_rproc is now up,同时查看状态也显示了 running

2022-07-19-16-46-33-image.png

此时也可以用 stop 命令停止小核运行

  1. cecho stop <font color="rgb(154, 110, 58)">></font> <font color="rgb(154, 110, 58)">/</font>sys<font color="rgb(154, 110, 58)">/</font>kernel<font color="rgb(154, 110, 58)">/</font>debug<font color="rgb(154, 110, 58)">/</font>remoteproc<font color="rgb(154, 110, 58)">/</font>remoteproc0<font color="rgb(154, 110, 58)">/</font>state

2022-07-19-16-49-24-image.png



2022-07-19-18-26-16-image.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则

284

主题

292

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部