打印
[RISC-V MCU 应用开发]

全志V853 RISC-V内核E907 核心固件加载

[复制链接]
2417|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 神棍地海棠 于 2022-12-5 10:22 编辑

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

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

作用:
  • 从文件系统加载固件
  • 准备远程处理器所需资源
  • 注册一个 rpmsg virtio 设备
  • 提供对要提供对远程处理器的生命周期进行管理
所以固件的加载流程大致如下:
<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. 加载固件
   1. 调用 firmware 接口获取文件系统中的固件
   2. 解析固件的 resource_table 段,该段有如下内容
      1. 声明需要的内存(Linux 为其分配)
      2. 声明使用的 vdev(固定为一个)
      3. 声明使用的 vring(固定为两个)
   3. 将固件加载到指定地址
2. 注册 rpmsg virtio 设备
   1. 提供 vdev->ops(基于 virtio 接口实现的)
   2. 与 rpmsg_bus 驱动匹配,完成 rpmsg 初始化
3. 启动小核
   1. 调用 rproc->ops->start</span>

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

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

    vdev0vring0: vdev0vring0@47040000 {
        reg = <0x0 0x47040000 0x0 0x20000>;
        no-map;
    };

    vdev0vring1: vdev0vring1@47060000 {
        reg = <0x0 0x47060000 0x0 0x20000>;
        no-map;
    };
};

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

    memory-mappings =
        /* DA              len         PA */
        /* DDR for e907  */
        < 0x48000000 0x00400000 0x48000000 >;
    core-name = "sun8iw21p1-e907";
    firmware-name = "melis-elf";
    status = "okay";
};

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

rpbuf_sample: rpbuf_sample@0 {
    compatible = "allwinner,rpbuf-sample";
    rpbuf = <&rpbuf_controller0>;
    status = "okay";
};



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


并勾选以下驱动:
Device Drivers  --->
  Remoteproc drivers  --->
    <*> SUNXI remote processor support
  Rpmsg drivers  --->
    <*> allwinnertech rpmsg driver for v853-e907
    <*> allwinnertech rpmsg hearbeat driver
    <*> Virtio RPMSG bus driver
    <*> sunxi rpmsg ctrl driver
  [*] Mailbox Hardware Support  --->
    <*>   sunxi Mailbox
    <*>   sunxi rv32 standby driver


我们可以使用 cat 命令检查小核目前的状况
cat /sys/kernel/debug/remoteproc/remoteproc0/state

可以看到目前是 offline 的。可以尝试使用 echo 启动小核
>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


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

然后我们将固件名称置于 firmware 节点内,并启动固件。
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


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

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-18-26-16-image.png (72.37 KB )

2022-07-19-18-26-16-image.png

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

194

主题

202

帖子

0

粉丝