Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openamp_rsc_table App in imx7d-pico (M4-Side name in Zephyr=pico_pi_m4) I cant see /dev/ttyRPMSG #69433

Closed
neuberfran opened this issue Feb 25, 2024 · 72 comments
Assignees
Labels
area: AMP Asymmetric Multi-processing (AMP) bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@neuberfran
Copy link

neuberfran commented Feb 25, 2024

Hi,

https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/ipc/openamp_rsc_table#id6

I stay trying this since last month in my imx7d-pico (m4 side) Zephyr upstream board is pico_pi_m4 using mailbox=mub

I can run Remoteproc and zephyr on this device but without resource table, vrings and RPMsg: https://www.youtube.com/watch?v=NFyEJXIpq4E

Now I stay trying openamp_rsc_table
based on this link below:
#60455

I can go up and run everything but the channel and /dev/ttyRPMSG are not created

cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories

Carveout memory entry:
	Name: vdev0vring0
	Virtual address: 7938acbc
	DMA address: 0x90000000
	Device address: 0x90000000
	Length: 0x8000 Bytes

Carveout memory entry:
	Name: vdev0vring1
	Virtual address: 3a612924
	DMA address: 0x90008000
	Device address: 0x90008000
	Length: 0x8000 Bytes

cat /sys/kernel/debug/remoteproc/remoteproc0/resource_table

Entry 0 is of type vdev
  ID 7
  Notify ID 0
  Device features 0x1
  Guest features 0x1
  Config length 0x0
  Status 0x7
  Number of vrings 2
  Reserved (should be zero) [0][0]

  Vring 0
    Device Address 0x90000000
    Alignment 16
    Number of buffers 8
    Notify ID 0
    Physical Address 0x0

  Vring 1
    Device Address 0x90008000
    Alignment 16
    Number of buffers 8
    Notify ID 1
    Physical Address 0x0

pico_pi_m4.overlay


/ {
	chosen {
		/*
		 * shared memory reserved for the inter-processor communication
		 */
		zephyr,ipc_shm = &ocramfake;
		zephyr,ipc = &mub;
	};

	ocramfake: memory@90000000  {
		compatible = "mmio-sram";
		reg = <0x90000000  0x110000>;
	};
};

&mub {
	status = "okay";
};

Screenshot from 2024-02-25 19-43-35

In linux Yocto A7 Side imx7d-pico-pi-qca-m4.dts (file):

/*
 * Copyright 2018 TechNexion Ltd.
 *
 * Author: Tapani Utriainen <[email protected]>
 *         Richard Hu <[email protected]>
 *         Ray Chang <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */

 #include "imx7d-pico-pi-qca.dts"

 / {
     memory {
         linux,usable-memory = <0x80000000 0x1ff00000>;
     };
 
     reserved-memory {
         #address-cells = <1>;
         #size-cells = <1>;
         ranges;
 
         //  mailbox_reserved: vrings0@30ab0000  {
        //    reg = <0x30ab0000 0x10000>;
        //    no-map;
        //  };

        m4_reserved: m4@90000000 {
           reg = <0x90000000 0x100000>;
           no-map;
         };        

        vdev0vring0: vdev0vring0@90000000 {
            compatible = "shared-dma-pool";
//            compatible = "shared-dma-pool";
            reg = <0x90000000  0x8000>;
            no-map;
        };

        vdev0vring1: vdev0vring1@90008000 {
            compatible = "shared-dma-pool";
//            compatible = "shared-dma-pool";
            reg = <0x90008000  0x8000>;
            no-map;
        };

        // rsc_table: rsc_table@900ff000 {
        //  reg = <0x900ff000  0x1000>;
        //  no-map;
        // };

        vdev0buffer: vdev0buffer@90010000 {
            compatible = "shared-dma-pool";
            reg = <0x90010000 0x80000>;
            no-map;
        };
 
        //  cm4tcmcode: cm4tcmcode@0x7f8000 {
        //      compatible = "shared-dma-pool";
        //      reg = <0x007f8000 0x8000>;
        //      no-map;
        //  };
 
        //  cm4sramcode: cm4sramcode@0x900000 {
        //      compatible = "shared-dma-pool";
        //      reg = <0x00900000 0x40000>;
        //      no-map;
        //  };
     };
 
     imx7d-cm4 {
         compatible = "fsl,imx7d-cm4";
         clocks = <&clks IMX7D_ARM_M4_ROOT_CLK>;
//         fsl,auto-boot;
         mbox-names = "tx0", "rx0", "rxdb0";
		 mboxes = <&mub 0 1
			  &mub 1 1
			  &mub 3 1>;
  //	     memory-region = <&rpmsg_vrings>, <&cm4tcmcode>, <&cm4sramcode>;
        memory-region = <&vdev0buffer>, <&vdev0vring0>, <&vdev0vring1>;
        //, <&cm4tcmcode>;
        fsl,rproc-auto-boot = <1>;
        fsl,rproc-fw-name="zephyr_openamp_rsc_table.elf";
        syscon = <&src>;
        status = "okay"; 
     };
 
     m4_tcm: tcml@007f8000 {
         compatible = "fsl, m4_tcml";
         reg = <0x007f8000 0x8000>;
     };
 
     gpio-leds {
         status = "disabled";
     };
 };
 
 &adc1 {
     status = "disabled";
 };
 
 &adc2 {
     status = "disabled";
 };
 
 &gpt3 {
     status = "disabled";
 };
 
 &gpt4 {
     status = "disabled";
 };
 
 &ocram {
     reg = <0x00901000 0xf000>;
 };
 
 &rpmsg{
     vdev-nums = <1>;
     memory-region = <&vdev0buffer>;
//     memory-region = <&vdev0vring0>, <&vdev0vring1>, <&vdevbuffer>, <&cm4tcmcode>, <&cm4sramcode>;
     reg = <0x9fff0000 0x10000>;
     status = "okay";   // Tava disabled
 };
 
 &uart6 {
     status = "disabled";
 };
 
 &mub {
     status = "okay";
 };
 
 &wdog3{
     status = "disabled";
 };

Why I can`t see vdev0buffer in result of the cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories And cat /sys/kernel/debug/remoteproc/remoteproc0/resource_table commands?

Why when I change MAX_RPMSG_NUM_BUFS and MAX_RPMSG_BUF_SIZE from 512 to 256 in virtio_rpmsg_bus.c (file in rpmsg/drivers in my linux kernel), nothing change in Number of buffers 8 in my resource_table?
Screenshot from 2024-02-25 19-56-19

Edited:

Change CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=8 to
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=512 in prj.conf. But not solved.

CONFIG_KERNEL_BIN_NAME="zephyr_openamp_rsc_table"
CONFIG_PRINTK=n
CONFIG_IPM=y
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_OPENAMP=y
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=32
CONFIG_OPENAMP_RSC_TABLE=y
CONFIG_OPENAMP_MASTER=n

Captura de tela de 2024-02-26 16-34-58

@neuberfran neuberfran added the bug The issue is a bug, or the PR is fixing a bug label Feb 25, 2024
@neuberfran neuberfran changed the title openamp_rsc_table App in imx7d-pico (Side-m4 pico_pi_m4) I cant see /dev/ttyRPMSG openamp_rsc_table App in imx7d-pico (M4-Side name in Zephyr=pico_pi_m4) I cant see /dev/ttyRPMSG Feb 25, 2024
@henrikbrixandersen henrikbrixandersen added the area: AMP Asymmetric Multi-processing (AMP) label Feb 26, 2024
@nashif nashif added the priority: low Low impact/importance bug label Feb 27, 2024
@jlh-makeen
Copy link
Contributor

jlh-makeen commented Mar 23, 2024

Hello,

I'm trying to acheive the same RPSMG communication on an CL-SOM-IMX7D.

Have you got any progress or success ?

I've seen a first thing is that we are missing the ressource table definition in the linker script of the imx7d soc.

Similar to the one on the imx8m m7 core:
https://github.com/zephyrproject-rtos/zephyr/blob/main/soc/nxp/imx/imx8m/m7/linker.ld

When you compile the openamp_rsc_table example, there should not be saying "orphaned section .ressource_table...".

add the linker section to a linker.ld file like on the imx8m/m7 example and change the linker script path in the imx7d soc
Cmakelist:

imx7/m4: Cmakelist.txt:

#
# Copyright (c) 2017, NXP
# Copyright (c) 2024, MAKEEN Energy A/S
#
# SPDX-License-Identifier: Apache-2.0
#

zephyr_sources(
  soc.c
  soc_clk_freq.c
  )

if(CONFIG_OPENAMP_RSC_TABLE)
  zephyr_linker_section(NAME .resource_table GROUP ROM_REGION NOINPUT)
  zephyr_linker_section_configure(SECTION .resource_table KEEP INPUT ".resource_table*")
endif()

set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "")

imx7/m4 linker.ld:

/*
 * Copyright (c) 2024, MAKEEN Energy A/S
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/arch/arm/cortex_m/scripts/linker.ld>

SECTIONS
     {
#ifdef CONFIG_OPENAMP_RSC_TABLE
        SECTION_PROLOGUE(.resource_table,, SUBALIGN(4))
        {
            KEEP(*(.resource_table*))
        } GROUP_LINK_IN(ROMABLE_REGION)
#endif
     }

I'm not upstreaming my changes for now since I'm still having issues with my linux kernel to get rpmsg to work.
But I've cooked some updates to the imx7d and prepared some driver updates that I'd like to upstream at some point.

@jlh-makeen
Copy link
Contributor

jlh-makeen commented Mar 23, 2024

BTW have you also compiled and inserted the drivers/rpmsg/imx_rpmsg_tty.c kernel module as mentionned by the sample ?

The Sample Docs

@neuberfran
Copy link
Author

neuberfran commented Mar 23, 2024

@jlh-makeen I'm glad you showed up about imx7 and remoteproc using resource table. I'm kinda alone in this (imx7d) for now

Captura de tela de 2024-03-23 18-17-53


echo start > /sys/class/remoteproc/remoteproc0/state
[  667.827358] remoteproc remoteproc0: powering up imx-rproc
[  667.833825] remoteproc remoteproc0: Booting fw image zephyr_openamp_rsc_table.elf, size 660180
[  667.842789]  remoteproc0#vdev0buffer: assigned reserved memory node vdev0buffer@00924000
[  667.851255] virtio_rpmsg_bus: probe of virtio1 failed with error -12
[  667.857725]  remoteproc0#vdev0buffer: registered virtio1 (type 7)
[  667.863868] remoteproc remoteproc0: remote processor imx-rproc is now up
root@scorpion:/lib/firmware# 

https://community.toradex.com/t/rpmsg-does-not-work-on-imx8m-plus/13740/92?page=4

-12 = missing memory

Every codes to github analyzer:
https://gist.github.com/neuberfran/ce6861c962e8c5fa361ff9453ce85a10

below = imx_rpmsg_tty.c

#define RPMSG_MAX_SIZE 64
`
below = imx_rpmsg.c
``
#define REMOTE_READY_WAIT_MAX_RETRIES 500

#define RPMSG_NUM_BUFS (128)
#define RPMSG_BUF_SIZE (128)
#define RPMSG_BUFS_SPACE (RPMSG_NUM_BUFS * RPMSG_BUF_SIZE)
#define RPMSG_VRING_ALIGN (1024)
#define RPMSG_RING_SIZE ((DIV_ROUND_UP(vring_size(RPMSG_NUM_BUFS / 2,
RPMSG_VRING_ALIGN), PAGE_SIZE)) * PAGE_SIZE)

#define to_imx_virdev(vd) container_of(vd, struct imx_virdev, vdev)

rpdev->ivdev[i]->vring[0] = start;
rpdev->ivdev[i]->vring[1] = start + 0x2000;
start += 0x4000;

**below = virtio_rpmsg_bus.c**

#define MAX_RPMSG_NUM_BUFS (128)
#define MAX_RPMSG_BUF_SIZE (128)

#define RPMSG_RESERVED_ADDRESSES (1024)

@neuberfran
Copy link
Author

BTW have you also compiled and inserted the drivers/rpmsg/imx_rpmsg_tty.c kernel module as mentionned by the sample ?

The Sample Docs

Yes

And

You said: I've seen a first thing is that we are missing the ressource table definition in the linker script of the imx7d soc.

I suggest you read and participate in this meeting
OpenAMP/open-amp#275 (comment)

@neuberfran
Copy link
Author

neuberfran commented Mar 23, 2024

my Kconfig.defconfig.mcimx7_m4 don`t have config IPM_IMX_REV2 Compared to mimx8mm6_m4


# iMX7 M4 core series

# Copyright (c) 2017, NXP
# SPDX-License-Identifier: Apache-2.0

if SOC_MCIMX7_M4

config SOC
	default "mcimx7d"

config SYS_CLOCK_HW_CYCLES_PER_SEC
	default 200000000

config GPIO
	default y

endif # SOC_MCIMX7_M4



@jlh-makeen
Copy link
Contributor

jlh-makeen commented Mar 24, 2024

You are using Yocto kirkstone with Linux kernel 5.15 right ?

A the moment I have a Kirkstone image with Linux 5.10.9 and a backport of the imx-rproc drivers from 5.15 and a hack to boot my image from OCRAM (our app program uses more than 32kB). Might be too outdated as mainline kernel imx-rproc driver for 5.10.9 has quite some differences from 5.15 driver.

image

As soon as I define the mailboxes in the A7 DT and start the M4, I get a seg fault. That might be our fault from missing something in the backport, but we are struggling with Compulab not having released a kernel and patches for newer than linux 5.10.9.

root@cl-som-imx7:/lib/firmware# ./boot_m4.sh zephyr_pnet_ipm.elf
./boot_m4.sh: line 1: echo: writeremoteproc remoteproc0: powering up imx-rproc
 error: Invalid argument
remoteproc remoteproc0: Booting fw image zephyr_pnet_ipm.elf, size 1629760
rproc_elf_load_segments: So... booting from OCRAM on IMX7 ??? Grabbing PC and SP for you...
rproc_elf_load_segments: SP: 0x20003348 PC: 0x00908205
rproc_elf_load_segments: APPLYING TEMPORARY HACK TO GET SP AND PC LOADED INTO M4 BOOT VECTOR
8<--- cut here ---
Unhandled fault: imprecise external abort (0x1c06) at 0xc0800000
pgd = da7dd62d
[c0800000] *pgd=885d2811, *pte=8854365f, *ppte=8854345f
Internal error: : 1c06 [#1] PREEMPT SMP ARM
Modules linked in: wl18xx evbug wlcore mousedev caam_jr caamkeyblob_desc caamhash_desc caamalg_desc crypto_engine wlcore_sdio imx_sdma caam secvio error pnet(O) fsl_ftm_ic(O)
CPU: 0 PID: 371 Comm: sh Tainted: G           O      5.10.9 #1
Hardware name: Freescale i.MX7 Dual (Device Tree)
PC is at imx_mu_xcr_rmw+0x0/0x70
LR is at imx_mu_generic_tx+0x8c/0xf8
pc : [<809266e0>]    lr : [<80926b10>]    psr: 600f0093
sp : 851e9c48  ip : 80dc7cb4  fp : b8144e00
r10: 00002000  r9 : b8144000  r8 : 00000000
r7 : f5ab0004  r6 : 00000000  r5 : 8409b040  r4 : 00000000
r3 : 00000016  r2 : 00000000  r1 : 00400000  r0 : 8409b040
Flags: nZCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none
Control: 10c5387d  Table: 8849006a  DAC: 00000051
Process sh (pid: 371, stack limit = 0xab2517e1)
Stack: (0x851e9c48 to 0x851ea000)
9c40:                   8409b128 600f0013 8409b1a0 851e9ca8 00000cc0 80925aac
9c60: 00000036 000007ff 86749260 6759df8c 851e9c78 8409b128 00000000 851e9ca8
9c80: 8409b1a0 80925c60 00000000 84290ae8 84ec0400 00000000 00000cc0 8092c494
9ca0: b8144e00 8092db84 00000000 6759df8c 00000001 885d3180 00000001 8092afd4
9cc0: 885d3180 8062e4ac 885d3100 8092de8c 00000035 00000000 00000000 80308de0
9ce0: 884119f8 81053348 00000000 bfdabd92 00000e00 00000200 00000000 8092e104
9d00: 8092d840 885d3180 885d3200 6759df8c 84ec0600 84ec0410 84ec0400 00000000
9d20: 8141ec14 00000001 00000000 00000001 00000000 8062e38c 84ec0410 00000000
9d40: 814971e4 84ec0410 00000000 814971e4 00000000 814971dc 8141ec14 00000021
9d60: 00000000 806ca270 00000000 84ec0410 8141ec14 806caa88 84ec0454 00000000
9d80: 00000000 814097c0 00000000 806ca930 00000000 851e9dc4 806caa88 806c833c
9da0: 00000000 8415d06c 8437f338 6759df8c 84ec0410 813fb0a0 00000001 806ca700
9dc0: 8106acd8 84ec0410 00000001 6759df8c 84ec0410 84ec0410 813fb0a0 84ec0410
9de0: 84ec1c20 806c93d4 84ec0410 00000000 814971b4 806c5240 813fb0a0 84ec0410
9e00: 84290800 80589940 84ec0400 6759df8c 84ec0400 8092aff8 813fb0a0 84ec0410
9e20: 84290800 84ec0400 88329a40 8062e018 00000000 84ec1c00 00000007 84ec1c20
9e40: 84290800 8092b60c 84ec1c04 84290a48 84290820 88329c80 84290820 88329c80
9e60: 88329a40 80c8876c 84290800 00000000 84290820 80c8897c 842909f8 84290800
9e80: 00000000 84290a04 84290820 80929658 88329c80 6759df8c 84290820 88329cc0
9ea0: 00000006 84290800 8504be90 00000051 00000000 8092ada4 00000006 8504be80
9ec0: 88329cc0 851e9f80 8504be90 8030b700 00000000 00000000 846f6900 846f6780
9ee0: 00000006 8030b608 02082100 851e9f80 851e8000 00000004 00000000 802718d8
9f00: 843f2000 6759df8c 00000001 00000800 84cc7240 00000001 00000000 00000001
9f20: 84cc7240 0000000a 84cc7240 80285660 ffffe000 84cc7240 0000000a 851e8000
9f40: 84cc7240 6759df8c 00000000 84cc7240 883c0a28 883c0800 00000000 6759df8c
9f60: 851e9fb0 846f6780 846f6780 00000000 00000000 80100264 851e8000 80271d80
9f80: 00000000 00000000 80100264 6759df8c 00000006 00000006 02082100 76fa65a0
9fa0: 00000004 80100240 00000006 02082100 00000001 02082100 00000006 00000000
9fc0: 00000006 02082100 76fa65a0 00000004 00000006 0058cc00 00000000 00000000
9fe0: 00000004 7e8729c8 76ec06e7 76e41ae6 40010030 00000001 00000000 00000000
[<809266e0>] (imx_mu_xcr_rmw) from [<000007ff>] (0x7ff)
Code: ebdfb925 e5845000 e3a00000 e8bd8070 (e92d47f0)
---[ end trace 15ec0de3866fc2d9 ]---
note: sh[371] exited with preempt_count 1
Segmentation fault

@neuberfran
Copy link
Author

neuberfran commented Mar 24, 2024

@jlh-makeen Yes I have Yocto Kirkstone. Linux Kernel version 5.15.52.

What about your device vendor? Do u have qspi (I dont have in my imx7d-pico by TechNexion)? Do u have debug port? (I dont have).

Why I can`t see vdev0buffer in result of the cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories And cat /sys/kernel/debug/remoteproc/remoteproc0/resource_table commands?
Captura de tela de 2024-03-24 17-04-05

M4 Side is not completely inert. Some main start-of-function messages are shown. But it never shows the hello-world from the imx_rpmsg_tty driver nor the messages from the rpmsg_client_sample driver
Captura de tela de 2024-03-24 17-07-29

What are you trying to do? Maybe like me I want to echo > test /dev/ttyRPMSG using Zephyr's openamp_rsc_table so we can work together on this

@jlh-makeen
Copy link
Contributor

We are trying to achieve the same goal which is have /dev/ttyRPMSG up in Linux to talk to the M4 chip.

We are using the Compulab vendor with their CL-SOM-IMX7. The module is a 1GB Ram variant.
We have placed the sh_men area at the end of the 1GB.

But their BSP is outdated and is using the linux kernel lf-5.10.y with vendor patches:
https://github.com/compulab-yokneam/meta-bsp-imx7/tree/kirkstone

We also have a custom carrier board with 4x RS485 ports used by the Cortex M and 1x UART for the Cortex A.

My kernel at the moment:

Linux cl-som-imx7 5.10.9 #1

As per my colleague who is responsible for the Linux yocto image, the generic ttyRPMSG driver, mentionned by the openamp_rsc_table sample was introduced in Linux 5.16 (CONFIG_TTY_RPMSG).

I'm using this Zephyr version, before the switch to v2 boards/soc directory structure.

*** Booting Zephyr OS build v3.6.0-294-gec089ac5c251 ***
-> My DT on zephyr side, we boot from OCRAM at 0x0901000
/ {
	model = "Compulab CL-SOM-IMX7d on Makeen Datagateway carrier";
	compatible = "nxp,mcimx7d_m4";

	chosen {
		zephyr,flash = &ocram_code_linux; /*&tcml_code;*/
		zephyr,sram = &tcmu_sys;
		zephyr,console = &uart2;
		zephyr,shell-uart = &uart2;
		zephyr,ipc_shm = &ddr_shm;
		zephyr,ipc = &mub;
	};

	ddr_shm: memory1@bff00000 {
		compatible = "mmio-sram";
		/* use DDR_SYS area as mmio, 0xbff00000 0x100000 */
		reg = <0xbff00000 0x100000>;
		status = "okay";
	};
	
	...
        soc {
              ocram_code_linux: code@901000 {
	              compatible = "nxp,imx-code-bus";
	              reg = <0x00901000 DT_SIZE_K(124)>;
              };
        };

Regarding the A7 device tree:

       	mu@30aa0000 {
		compatible = "fsl,imx7d-mu\0fsl,imx6sx-mu";
		reg = <0x30aa0000 0x10000>;
		interrupts = <0x00 0x58 0x04>;
		clocks = <0x01 0x1b1>;
		clock-names = "mu";
		#mbox-cells = <0x02>;
		phandle = <0x4a>;
	};


	mu@30ab0000 {
		compatible = "fsl,imx7d-mu\0fsl,imx6sx-mu";
		reg = <0x30ab0000 0x10000>;
		interrupts = <0x00 0x61 0x04>;
		clocks = <0x01 0x1b1>;
		clock-names = "mu";
		#mbox-cells = <0x02>;
		phandle = <0x60>;
	};
       ...
       rpmsg {
              compatible = "fsl,imx7d-rpmsg";
              mbox-names = "tx\0rx\0rxdb";
              mboxes = <0x4a 0x00 0x01 0x4a 0x01 0x01 0x4a 0x03 0x01>;
              status = "okay";
      };
      ...
	reserved-memory {
		#address-cells = <0x01>;
		#size-cells = <0x01>;
		ranges;

		cm4tcmcode@7f8000 {
			compatible = "shared-dma-pool";
			reg = <0x7f8000 0x8000>;
			no-map;
			phandle = <0x57>;
		};

		cm4sramcode@901000 {
			compatible = "shared-dma-pool";
			reg = <0x901000 0x40000>;
			no-map;
			phandle = <0x58>;
		};

		vdev0vring0@bff00000 {
			compatible = "shared-dma-pool";
			reg = <0xbff00000 0x1000>;
			no-map;
			phandle = <0x61>;
		};

		vdev0vring1@bff01000 {
			compatible = "shared-dma-pool";
			reg = <0xbff01000 0x1000>;
			no-map;
			phandle = <0x62>;
		};

		vdev0buffer@bff02000 {
			compatible = "shared-dma-pool";
			reg = <0xbff02000 0xfe000>;
			no-map;
			phandle = <0x56>;
		};
	};

	imx7d-cm4 {
		compatible = "fsl,imx7d-cm4";
	    mbox-names = "tx", "rx", "rxdb";
		mboxes = <0x60 0x00 0x01 0x60 0x01 0x01 0x60 0x03 0x01>;
		memory-region = <0x56 0x61 0x62 0x57 0x58>;
		syscon = <0x23>;
		clocks = <0x01 0x42>;
	};

And the carveout/ressource tables outputs:

root@cl-som-imx7:/# cat /sys/kernel/debug/remoteproc/remoteproc0/resource_table
Entry 0 is of type vdev
  ID 7
  Notify ID 0
  Device features 0x1
  Guest features 0x1
  Config length 0x0
  Status 0x7
  Number of vrings 2
  Reserved (should be zero) [0][0]

  Vring 0
    Device Address 0xbff00000
    Alignment 16
    Number of buffers 8
    Notify ID 0
    Physical Address 0x0

  Vring 1
    Device Address 0xbff01000
    Alignment 16
    Number of buffers 8
    Notify ID 1
    Physical Address 0x0

root@cl-som-imx7:/# cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories
Carveout memory entry:
        Name: vdev0buffer
        Virtual address: dd5cdfbe
        DMA address: 0xbff02000
        Device address: 0xbff02000
        Length: 0xfe000 Bytes

Carveout memory entry:
        Name: vdev0vring0
        Virtual address: 473e2d00
        DMA address: 0xbff00000
        Device address: 0xbff00000
        Length: 0x1000 Bytes

Carveout memory entry:
        Name: vdev0vring1
        Virtual address: 8d625bae
        DMA address: 0xbff01000
        Device address: 0xbff01000
        Length: 0x1000 Bytes

Carveout memory entry:
        Name: cm4tcmcode
        Virtual address: 02e0dcc6
        DMA address: 0x007f8000
        Device address: 0x7f8000
        Length: 0x8000 Bytes

Carveout memory entry:
        Name: cm4sramcode
        Virtual address: 3ecff66e
        DMA address: 0x00901000
        Device address: 0x901000
        Length: 0x40000 Bytes

@neuberfran
Copy link
Author

@jlh-makeen

You said: "As per my colleague who is responsible for the Linux yocto image, the generic ttyRPMSG driver, mentionned by the openamp_rsc_table sample was introduced in Linux 5.16 (CONFIG_TTY_RPMSG)."

I never knew anything about it. If you could provide more details, I would appreciate it.

@jlh-makeen
Copy link
Contributor

@neuberfran

I managed to fix my driver crashing and can now start my M4 processor correctly and have rproc probe the core and kick the MU.

root@cl-som-imx7:/lib/firmware# ./boot_m4.sh zephyr_pnet_ipm.elf
./boot_m4.sh: line 1: echo: writeremoteproc remoteproc0: powering up imx-rproc
 error: Invalid argument
remoteproc remoteproc0: Booting fw image zephyr_pnet_ipm.elf, size 1638784
rproc_elf_load_segments: So... booting from OCRAM on IMX7 ??? Grabbing PC and SP for you...
rproc_elf_load_segments: SP: 0x20003348 PC: 0x009086a1
rproc_elf_load_segments: APPLYING TEMPORARY HACK TO GET SP AND PC LOADED INTO M4 BOOT VECTOR
 remoteproc0#vdev0buffer: vdev 0 buffer already mapped
virtio_rpmsg_bus virtio0: rpmsg host is online
 remoteproc0#vdev0buffer: registered virtio0 (type 7)
remoteproc remoteproc0: remote processor imx-rproc is now up

root@cl-som-imx7:/lib/firmware# cat /sys/kernel/debug/remoteproc/remoteproc0/resource_table
Entry 0 is of type vdev
  ID 7
  Notify ID 0
  Device features 0x1
  Guest features 0x1
  Config length 0x0
  Status 0x7
  Number of vrings 2
  Reserved (should be zero) [0][0]

  Vring 0
    Device Address 0xbff00000
    Alignment 16
    Number of buffers 64
    Notify ID 0
    Physical Address 0x0

  Vring 1
    Device Address 0xbff01000
    Alignment 16
    Number of buffers 64
    Notify ID 1
    Physical Address 0x0

root@cl-som-imx7:/lib/firmware# cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories
Carveout memory entry:
        Name: vdev0buffer
        Virtual address: 34229b00
        DMA address: 0xbff02000
        Device address: 0xbff02000
        Length: 0xfe000 Bytes

Carveout memory entry:
        Name: vdev0vring0
        Virtual address: 9abcaa63
        DMA address: 0xbff00000
        Device address: 0xbff00000
        Length: 0x1000 Bytes

Carveout memory entry:
        Name: vdev0vring1
        Virtual address: bc7cb9f6
        DMA address: 0xbff01000
        Device address: 0xbff01000
        Length: 0x1000 Bytes

Carveout memory entry:
        Name: cm4tcmcode
        Virtual address: 5f71bfd0
        DMA address: 0x007f8000
        Device address: 0x7f8000
        Length: 0x8000 Bytes

Carveout memory entry:
        Name: cm4sramcode
        Virtual address: 9f061b54
        DMA address: 0x00901000
        Device address: 0x901000
        Length: 0x40000 Bytes


Yes, up until 5.15 we had the imx_rpmsg_tty driver but there was introduced a new more generic one as rpmsg_tty from 5.16. Not sure it has more feature though.

Check out the nxp/linux-imx repo, latest revision:
https://github.com/nxp-imx/linux-imx/blob/lf-6.6.y/drivers/tty/rpmsg_tty.c

Which is different from:
https://github.com/nxp-imx/linux-imx/blob/lf-6.6.y/drivers/rpmsg/imx_rpmsg_tty.c

It is now part of the imx_v8_defconfig file:
https://github.com/nxp-imx/linux-imx/blob/lf-6.6.y/arch/arm64/configs/imx_v8_defconfig#L959

I'm also suspecting that something is missing in about the NS annoucement in the RPMSG on Linux.
because the Zephyr side sends some NS annoucements for RPMSG_TTY and RPMSG_CLIENT_SAMPLE endpoints.
Therefore my guess is that these should wakeup the right driver that should get probed and mounted by the system.

/* from zephyrproject/lib/open-amp/lib/rpmsg/rpmsg.c */

int rpmsg_create_ept(struct rpmsg_endpoint *ept, struct rpmsg_device *rdev,
		     const char *name, uint32_t src, uint32_t dest,
		     rpmsg_ept_cb cb, rpmsg_ns_unbind_cb unbind_cb)
{
	int status = RPMSG_SUCCESS;
	uint32_t addr = src;
	...
	/* Send NS announcement to remote processor */
	if (ept->name[0] && rdev->support_ns &&
	    ept->dest_addr == RPMSG_ADDR_ANY)
		status = rpmsg_send_ns_message(ept, RPMSG_NS_CREATE);
       ...
}

Here is an associated driver source that listens to annoucements:
https://github.com/nxp-imx/linux-imx/blob/lf-6.6.y/drivers/rpmsg/rpmsg_ns.c

@jlh-makeen
Copy link
Contributor

Here is a hint that may indicate that I'm right about the NS annoucement thing:

Linux lf 6.6.y:
image
image

The tty_rpmsg and imx_rpmsg_tty don't use the same annoucement id's.

And guess what, the Zephyr implementation uses the "rpmsg-tty" channel id:
image

@neuberfran
Copy link
Author

neuberfran commented Mar 25, 2024

@jlh-makeen

You have a lot of useful knowledge.

Please help me more on my imx7d-pico (Remoteproc and echo test > /dev/ttyRPMSG regarding mounting the DT and the zephyr overlay file:
https://docs.zephyrproject.org/latest/boards/technexion/pico_pi/doc/index.html
https://gist.github.com/neuberfran/389a5eb620ccad6e5694816d3ba43de8
https://www.nxp.com/docs/en/application-note/AN5317.pdf
Captura de tela de 2024-03-25 14-16-25
There is this undefined question about less to m4:
https://community.toradex.com/t/is-it-possible-to-increase-the-m4-memory-in-the-vf61/5591/6
And about why it starts at 0x1ff00000 and not 0x20000000:
https://community.nxp.com/t5/Other-NXP-Products/RPMsg-in-imx7d-Why-0x1FF00000-and-Not-0x10000000-in-linux-usable/m-p/1805773#M21111

As you will see below, I am now focusing on using OCRAM (0X00901000 using F000) and not 9FF00000 in Remoteproc. Is it right?
My last DT on A7-M4-Linux Kirkstone Side is this (I have rpmsg_ctrl0 and rpmsg_ctrl1, but I never have /dev/ttyRPMSG):


/*
 * Copyright 2018 TechNexion Ltd.
 *
 * Author: Tapani Utriainen <[email protected]>
 *         Richard Hu <[email protected]>
 *         Ray Chang <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */

 #include "imx7d-pico-pi-qca.dts"

 / {
     memory {
         linux,usable-memory = <0x80000000 0x1ff00000>;
     };
 
     reserved-memory {
         #address-cells = <1>;
         #size-cells = <1>;
         ranges;
 
         //  mailbox_reserved: vrings0@30ab0000  {
        //    reg = <0x30ab0000 0x10000>;
        //    no-map;
        //  };

        // m4_reserved: m4@8ff00000 {
        //    reg = <0x8ff00000 0x100000>;
        //    no-map;
        //  };        

         vdev0vring0: vdev0vring0@00902000 {
            compatible = "shared-dma-pool";
//            compatible = "shared-dma-pool";
//            reg = <0x9ff00000  0x8000>;
            reg = <0x00902000 0x2000>;
            no-map;
        };

        vdev0vring1: vdev0vring1@00904000 {
            compatible = "shared-dma-pool";
//            compatible = "shared-dma-pool";
//            reg = <0x9ff08000  0x8000>;
            reg = <0x00904000 0x2000>;
            no-map;
        };

        // rsc_table: rsc_table@900ff000 {
        //  reg = <0x900ff000  0x1000>;
        //  no-map;
        // };

        vdev0buffer: vdev0buffer@00906000 {
            compatible = "shared-dma-pool";
//            reg = <0x9ff10000 0x80000>;
              reg = <0x00906000 0x9C40>;
            no-map;
        };

//         vdev0vring0: vdev0vring0@8ff00000 {
//             compatible = "shared-dma-pool";
// //            compatible = "shared-dma-pool";
//             reg = <0x8ff00000  0x8000>;
//             no-map;
//         };

//         vdev0vring1: vdev0vring1@8ff08000 {
//             compatible = "shared-dma-pool";
// //            compatible = "shared-dma-pool";
//             reg = <0x8ff08000  0x8000>;
//             no-map;
//         };

//         // rsc_table: rsc_table@900ff000 {
//         //  reg = <0x900ff000  0x1000>;
//         //  no-map;
//         // };

//         vdev0buffer: vdev0buffer@8ff10000 {
//             compatible = "shared-dma-pool";
//             reg = <0x8ff10000 0x80000>;
//             no-map;
//         };
 
         cm4tcmcode: cm4tcmcode@0x7f8000 {
             compatible = "shared-dma-pool";
             reg = <0x007f8000 0x8000>;
             no-map;
         };
 
        //  cm4sramcode: cm4sramcode@0x900000 {
        //      compatible = "shared-dma-pool";
        //      reg = <0x00900000 0x40000>;
        //      no-map;
        //  };
     };
 
     imx7d-cm4 {
         compatible = "fsl,imx7d-cm4";
         clocks = <&clks IMX7D_ARM_M4_ROOT_CLK>;
//         fsl,auto-boot;
         mbox-names = "tx0", "rx0", "rxdb0";
		 mboxes = <&mub 0 1
			  &mub 1 1
			  &mub 3 1>;
  //	     memory-region = <&rpmsg_vrings>, <&cm4tcmcode>, <&cm4sramcode>;
        memory-region = <&vdev0buffer>, <&vdev0vring0>, <&vdev0vring1>; 
        fsl,rproc-auto-boot = <1>;
        fsl,rproc-fw-name="zephyr_openamp_rsc_table.elf";
        syscon = <&src>;
        status = "okay"; 
     };
 
     m4_tcm: tcml@007f8000 {
         compatible = "fsl, m4_tcml";
         reg = <0x007f8000 0x8000>;
     };
 
     gpio-leds {
         status = "disabled";
     };
 };
 
 &adc1 {
     status = "disabled";
 };
 
 &adc2 {
     status = "disabled";
 };
 
 &gpt3 {
     status = "disabled";
 };
 
 &gpt4 {
     status = "disabled";
 };
 
 &ocram {
     reg = <0x00901000 0xf000>;
 };
 
 &rpmsg{
     vdev-nums = <1>;
//     memory-region = <&vdev0buffer>;
//     memory-region = <&vdev0vring0>, <&vdev0vring1>, <&vdevbuffer>, <&cm4tcmcode>, <&cm4sramcode>;
     reg = <0x9fff0000 0x10000>;
     status = "okay";   // Tava disabled
 };
 
 &uart6 {
     status = "disabled";
 };
 
 &mub {
     status = "okay";
 };
 
 &wdog3{
     status = "disabled";
 };

And this is my overlay on zephyr and other settings:


/*
 * Copyright (c) 2023 NXP
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/ {
	chosen {
		/*
		 * shared memory reserved for the inter-processor communication
		 */
		zephyr,ipc_shm = &ocramfake;
		zephyr,ipc = &mub;
	};

	ocramfake: memory@00901000  {
		compatible = "mmio-sram";
		reg = <0x00901000  0xf000>;
	};
	// ocramfake: memory@8ff00000  {
	// 	compatible = "mmio-sram";
	// 	reg = <0x8ff00000  0x110000>;
	// };
};

&mub {
	status = "okay";
};
CONFIG_KERNEL_BIN_NAME="zephyr_openamp_rsc_table"
CONFIG_PRINTK=n
CONFIG_IPM=y
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_OPENAMP=y
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=16
CONFIG_OPENAMP_RSC_TABLE=y
CONFIG_OPENAMP_MASTER=n

CONFIG_LOG_PRINTK=n
CONFIG_IPM_IMX_MAX_DATA_SIZE_16=n
CONFIG_IPM_IMX_MAX_DATA_SIZE_4=y

#CONFIG_OPENAMP_WITH_DCACHE=y

CmakeLists.txt
zephyr_sources(
  soc.c
  soc_clk_freq.c
  )
  
if(CONFIG_OPENAMP_RSC_TABLE)
  zephyr_linker_section(NAME .resource_table GROUP ROM_REGION NOINPUT)
  zephyr_linker_section_configure(SECTION .resource_table KEEP INPUT ".resource_table*")
endif()

#set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "")

# iMX7 M4 core series

# Copyright (c) 2017, NXP
# SPDX-License-Identifier: Apache-2.0

if SOC_SERIES_IMX7_M4

config SOC_SERIES
	default "mcimx7_m4"

# config IPM_IMX
#     bool
#     default y
#     depends on IPM && SOC_MCIMX7_M4 && SOC_SERIES_IMX7_M4

config NUM_IRQS
	# must be >= the highest interrupt number used
	default 127

config PINCTRL_IMX
	default y if HAS_IMX_IOMUXC
	depends on PINCTRL

source "soc/arm/nxp_imx/mcimx7_m4/Kconfig.defconfig.mcimx7_m4"

endif # SOC_SERIES_IMX7_M4


 #include <zephyr/arch/arm/cortex_m/scripts/linker.ld>

 SECTIONS
     {
 #ifdef CONFIG_OPENAMP_RSC_TABLE
        SECTION_PROLOGUE(.resource_table,, SUBALIGN(4))
        {
            KEEP(*(.resource_table*))
        } GROUP_LINK_IN(ROMABLE_REGION)
 #endif
    }


Are you using ipm_imx_rev2??? Or not?

root@scorpion:/sys/bus/virtio/devices# ls /dev/rpmsg*
/dev/rpmsg_ctrl0  /dev/rpmsg_ctrl1
root@scorpion:/sys/bus/virtio/devices# dmesg | grep -i "virtio"
[    0.134883] virtio_rpmsg_bus virtio0: rpmsg host is online
[   55.904751] virtio_rpmsg_bus virtio1: rpmsg host is online
[   55.912441]  remoteproc0#vdev0buffer: registered virtio1 (type 7)
root@scorpion:/sys/bus/virtio/devices# cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories
Carveout memory entry:
	Name: vdev0vring0
	Virtual address: 26d194e1
	DMA address: 0x00902000
	Device address: 0x902000
	Length: 0x2000 Bytes

Carveout memory entry:
	Name: vdev0vring1
	Virtual address: d8145475
	DMA address: 0x00904000
	Device address: 0x904000
	Length: 0x2000 Bytes

root@scorpion:/sys/bus/virtio/devices# cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories
Carveout memory entry:
	Name: vdev0vring0
	Virtual address: 26d194e1
	DMA address: 0x00902000
	Device address: 0x902000
	Length: 0x2000 Bytes

Carveout memory entry:
	Name: vdev0vring1
	Virtual address: d8145475
	DMA address: 0x00904000
	Device address: 0x904000
	Length: 0x2000 Bytes
root@scorpion:/lib/firmware# modprobe rpmsg_client_sample && modprobe imx_rpmsg_tty 
[   52.776939] NLB imx_rpmmsg_tty
root@scorpion:/lib/firmware# echo start > /sys/class/remoteproc/remoteproc0/state    
[   58.498550] remoteproc remoteproc0: powering up imx-rproc
[   58.522741] remoteproc remoteproc0: Booting fw image zephyr_openamp_rsc_table.elf, size 660180
[   58.531721]  remoteproc0#vdev0buffer: assigned reserved memory node vdev0buffer@00906000
[   58.543938] virtio_rpmsg_bus virtio1: rpmsg host is online
[   58.551535]  remoteproc0#vdev0buffer: registered virtio1 (type 7)
[   58.557738] remoteproc remoteproc0: remote processor imx-rproc is now u

Please, Look it. Nothing about virtio0 (type 7) (this, immediately above.)
And
And nothing about vdev0buffer in the cat results

@jlh-makeen
Copy link
Contributor

@neuberfran

Well it's hard to tell because I've not gotten /dev/ttyRPMSG to appear on my system yet.

I don't see errors in when you start the M4 core though, so that's a first good thing.

I'm not sure if the shared memories and vrings can reside in the OCRAM region 0x009xxxxx.

On our system we have put them in DDR area at address 0xBFF00000 since we only have 1GB of RAM (from 0x80000000 to 0xBFFFFFFF).
The nice thing is that when using the DDR, the addresses are the same on A7 and M4 "System bus". (aka from 0x80000000)

I believe you are accessing the sh_mem on the "System bus" aka as RAM and not CODE. Therefore pay attention to the addresses.
image
I think that if you use the OCRAM, you need to change your Zephyr shared memory address to the matching in 0x20200000's.

Maybe I'm wrong, but I'd suggest you use DDR instead of OCRAM.

If you have 1GB ram, use 0xBFF00000, if you have 512MB, use 0x9FF00000
In your case it would probably look something like this:

 reserved-memory {
         #address-cells = <1>;
         #size-cells = <1>;
         ranges;
    

         vdev0vring0: vdev0vring0@9ff00000 {
            compatible = "shared-dma-pool";
            reg = <0x9ff00000 0x1000>;
            no-map;
        };

        vdev0vring1: vdev0vring1@9ff01000 {
            compatible = "shared-dma-pool";
            reg = <0x9ff01000 0x1000>;
            no-map;
        };

        vdev0buffer: vdev0buffer@9ff02000 {
            compatible = "shared-dma-pool";
              reg = <0x9ff02000 0xfe000>;
            no-map;
        };
 
        cm4tcmcode: cm4tcmcode@0x7f8000 {
             compatible = "shared-dma-pool";
             reg = <0x007f8000 0x8000>;
             no-map;
         };
 
         cm4sramcode: cm4sramcode@0x900000 {
             compatible = "shared-dma-pool";
             reg = <0x00900000 0x40000>;
            no-map;
         };
     };

@neuberfran
Copy link
Author

@jlh-makeen I have 1gb here (imx7d-pico with 1gb Model and not 512mb model)

Are you using ipm_imx_rev2??? Or not?

For a better basis, we have this updated an5317:
https://www.nxp.com/docs/en/application-note/AN5317.pdf

@jlh-makeen
Copy link
Contributor

@jlh-makeen I have 1gb here (imx7d-pico with 1gb Model and not 512mb model)

Are you using ipm_imx_rev2??? Or not?

For a better basis, we have this updated an5317: https://www.nxp.com/docs/en/application-note/AN5317.pdf

I don't believe we are using IPM_IMX_REV2 no.

@neuberfran
Copy link
Author

neuberfran commented Mar 25, 2024

@jlh-makeen
https://community.st.com/t5/stm32cubeide-mpus/decreasing-rpmsg-buffer-size-to-256-bytes-on-linux-kernel-will/td-p/112073
Do you think I will have to make changes to the linux/remoteproc driver files like:

below = imx_rpmsg_tty.c

#define RPMSG_MAX_SIZE 256
below = imx_rpmsg.c
``
#define REMOTE_READY_WAIT_MAX_RETRIES 500

#define RPMSG_NUM_BUFS (512)
#define RPMSG_BUF_SIZE (512)
#define RPMSG_BUFS_SPACE (RPMSG_NUM_BUFS * RPMSG_BUF_SIZE)
#define RPMSG_VRING_ALIGN (4096)
#define RPMSG_RING_SIZE ((DIV_ROUND_UP(vring_size(RPMSG_NUM_BUFS / 2,
RPMSG_VRING_ALIGN), PAGE_SIZE)) * PAGE_SIZE)

#define to_imx_virdev(vd) container_of(vd, struct imx_virdev, vdev)

rpdev->ivdev[i]->vring[0] = start;
rpdev->ivdev[i]->vring[1] = start + 0x8000;
start += 0x10000;

**below = virtio_rpmsg_bus.c**

#define MAX_RPMSG_NUM_BUFS (512)
#define MAX_RPMSG_BUF_SIZE (512)

#define RPMSG_RESERVED_ADDRESSES (4096)

**My last DT on A7-M4-Linux Kirkstone Side is this (I have rpmsg_ctrl0 and rpmsg_ctrl1, but I never have /dev/ttyRPMSG):**

@jlh-makeen
Copy link
Contributor

jlh-makeen commented Mar 26, 2024

@neuberfran

I'm sorry I'm no sure if this will be useful.

One thing my colleague pointed out is that the function virtqueue_get_available_buffer() fails on my zephyr program:
image

This could explain why the Name Service (NS) notification don't wakeup the drivers in Linux (as for my case at least).

Here is what I can log from my zephyr appplication:

OpenAMP[remote] Linux responder demo started
metal_init
:metal_register_generic_device
:metal_device_open
:metal_io_init
:metal_device_io_region
:rsc_table_get
:metal_io_init
:metal_device_io_region
:device_is_ready
[00:00:00.541,000] \x1B[0m<dbg> openamp_rsc_table: platform_ipm_callback: platform_ipm_callback: msg received from mb 1
\x1B[0m
:ipm_set_enabled
:platform_init
rproc_virtio_create_vdev
rproc_virtio_create_vdev
rproc_virtio_init_vring0 : 0xbff00000 / 64
rproc_virtio_init_vring1: 0xbff01000 / 64
rpmsg_init_vdev
:platform_create_rpmsg_vdev
[00:00:00.542,000] \x1B[0m<dbg> openamp_rsc_table: receive_message: recv message
\x1B[0m
ERR: virtqueue_get_available_buffer
OpenAMP[remote] Linux sample client responder started
[00:00:00.602,000] \x1B[0m<dbg> openamp_rsc_table: mailbox_notify: mailbox_notify: msg received -> priv:(nil) id:0
\x1B[0m
Endpoint rpmsg-client-sample created: res:0 support_ns: 1

OpenAMP[remote] Linux TTY responder started
[00:00:00.602,000] \x1B[0m<dbg> openamp_rsc_table: mailbox_notify: mailbox_notify: msg received -> priv:(nil) id:0
\x1B[0m
Endpoint rpmsg-tty created: res:0 support_ns: 1

EDIT: Well I've added some printk statements here and there in my Zephyr openamp:

OpenAMP[remote] Linux responder demo started
metal_init
:metal_register_generic_device
:metal_device_open
:metal_io_init
:metal_device_io_region
:rsc_table_get
:metal_io_init
:metal_device_io_region
:device_is_ready
[00:00:00.542,000] \x1B[0m<dbg> openamp_rsc_table: platform_ipm_callback: platform_ipm_callback: msg received from mb 1
\x1B[0m
:ipm_set_enabled
:platform_init
rproc_virtio_create_vdev
rproc_virtio_create_vdev
rproc_virtio_init_vring0 : 0xbff00000 / 64
rproc_virtio_init_vring1: 0xbff01000 / 64
rpmsg_init_vdev
:platform_create_rpmsg_vdev
[00:00:00.542,000] \x1B[0m<dbg> openamp_rsc_table: receive_message: recv message
\x1B[0m
ERR: virtqueue_get_available_buffer
OpenAMP[remote] Linux sample client responder started
DBG: rpmsg_send_offchannel_raw: ept->name:rpmsg-client-sample src:400 dst:35
DBG: virtqueue_get_available_buffer : buffer: 0xbff02000 
DBG: rpmsg_virtio_get_tx_payload_buffer : rp_hdr: 0xbff02000
[00:00:00.602,000] \x1B[0m<dbg> openamp_rsc_table: mailbox_notify: mailbox_notify: msg received -> priv:(nil) id:0
\x1B[0m
DBG: rpmsg_create_ept: ept->name:rpmsg-client-sample support_ns:1 ept->dest_addr:ffffffff
Endpoint rpmsg-client-sample created: res:0 support_ns: 1

OpenAMP[remote] Linux TTY responder started
DBG: rpmsg_send_offchannel_raw: ept->name:rpmsg-virtual-tty-channel src:401 dst:35
DBG: virtqueue_get_available_buffer : buffer: 0xbff02200 
DBG: rpmsg_virtio_get_tx_payload_buffer : rp_hdr: 0xbff02200
[00:00:00.603,000] \x1B[0m<dbg> openamp_rsc_table: mailbox_notify: mailbox_notify: msg received -> priv:(nil) id:0
\x1B[0m
DBG: rpmsg_create_ept: ept->name:rpmsg-virtual-tty-channel support_ns:1 ept->dest_addr:ffffffff
Endpoint rpmsg-tty created: res:0 support_ns: 1

I can see that the buffers are correctly taken from the vdev0buffer reserved memory which is 0xbff02000 and onwards.
The rpmsg channel names and are correctly passed to the endpoints and the mailbox notify function is called which should kick the A7 mailbox and let Linux handle the NS annoucements to get the drivers and tty running.

But nothing else happens on the Linux side unfortunately.
I'm wondering if it is due to the first buffer fail I'm seeing. I'll investigate more about this.

@neuberfran
Copy link
Author

neuberfran commented Mar 30, 2024

@jlh-makeen

Unfortunately, I still don't have carveout for vdev0buffer And /dev/ttyRPMSG.

pico_pi_m4.overlay

/ {
	chosen {
		/*
		 * shared memory reserved for the inter-processor communication
		 */
		zephyr,ipc_shm = &ocramfake;
		zephyr,ipc = &mub;
	};

	ocramfake: memory@9ff00000  {
		compatible = "mmio-sram";
		reg = <0x9ff0000  0x100000>;
//   I tried with 0x110000 and with 0x100000
	};
	// ocramfake: memory@8ff00000  {
	// 	compatible = "mmio-sram";
	// 	reg = <0x8ff00000  0x110000>;
	// };
};

&mub {
	status = "okay";
};

imx7d-pico-pi-qca-m4.dts

/*
 * Copyright 2018 TechNexion Ltd.
 *
 * Author: Tapani Utriainen <[email protected]>
 *         Richard Hu <[email protected]>
 *         Ray Chang <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */

 #include "imx7d-pico-pi-qca.dts"

 / {
     memory {
         linux,usable-memory = <0x80000000 0x1ff00000>;
     };
 
     reserved-memory {
         #address-cells = <1>;
         #size-cells = <1>;
         ranges;


         vdev0vring0: vdev0vring0@9ff00000 {
            compatible = "shared-dma-pool";
            reg = <0x9ff00000 0x1000>;
            no-map;
        };

        vdev0vring1: vdev0vring1@9ff01000 {
            compatible = "shared-dma-pool";
            reg = <0x9ff01000 0x1000>;
            no-map;
        };

        vdev0buffer: vdev0buffer@9ff02000 {
            compatible = "shared-dma-pool";
              reg = <0x9ff02000 0xfe000>;
            no-map;
        };
 
        cm4tcmcode: cm4tcmcode@0x7f8000 {
             compatible = "shared-dma-pool";
             reg = <0x007f8000 0x8000>;
             no-map;
         };
 
         cm4sramcode: cm4sramcode@0x900000 {
             compatible = "shared-dma-pool";
             reg = <0x00900000 0x40000>;
            no-map;
         };
    };
         
//         vdev0vring0: vdev0vring0@00902000 {
//             compatible = "shared-dma-pool";
// //            compatible = "shared-dma-pool";
// //            reg = <0x9ff00000  0x8000>;
//             reg = <0x00902000 0x2000>;
//             no-map;
//         };

//         vdev0vring1: vdev0vring1@00904000 {
//             compatible = "shared-dma-pool";
// //            compatible = "shared-dma-pool";
// //            reg = <0x9ff08000  0x8000>;
//             reg = <0x00904000 0x2000>;
//             no-map;
//         };

//         vdev0buffer: vdev0buffer@00906000 {
//             compatible = "shared-dma-pool";
// //            reg = <0x9ff10000 0x80000>;
//               reg = <0x00906000 0x9C40>;
//             no-map;
//         };

//         cm4tcmcode: cm4tcmcode@0x7f8000 {
//              compatible = "shared-dma-pool";
//              reg = <0x007f8000 0x8000>;
//              no-map;
//          };
   
//      };
 
     imx7d-cm4 {
         compatible = "fsl,imx7d-cm4";
         clocks = <&clks IMX7D_ARM_M4_ROOT_CLK>;
//         fsl,auto-boot;
         mbox-names = "tx0", "rx0", "rxdb0";
		 mboxes = <&mub 0 1
			  &mub 1 1
			  &mub 3 1>;
  //	     memory-region = <&rpmsg_vrings>, <&cm4tcmcode>, <&cm4sramcode>;
        memory-region = <&vdev0buffer>, <&vdev0vring0>, <&vdev0vring1>, <&cm4tcmcode>, <&cm4sramcode>; 
        fsl,rproc-auto-boot = <1>;
        fsl,rproc-fw-name="zephyr_openamp_rsc_table.elf";
        syscon = <&src>;
        status = "okay"; 
     };
 
     m4_tcm: tcml@007f8000 {
         compatible = "fsl, m4_tcml";
         reg = <0x007f8000 0x8000>;
     };
 
     gpio-leds {
         status = "disabled";
     };
 };
 
 &adc1 {
     status = "disabled";
 };
 
 &adc2 {
     status = "disabled";
 };
 
 &gpt3 {
     status = "disabled";
 };
 
 &gpt4 {
     status = "disabled";
 };
 
 &ocram {
     reg = <0x00901000 0xf000>;
 };
 
 &rpmsg{
     vdev-nums = <1>;
//     memory-region = <&vdev0buffer>;
//     memory-region = <&vdev0vring0>, <&vdev0vring1>, <&vdevbuffer>, <&cm4tcmcode>, <&cm4sramcode>;
     reg = <0x9fff0000 0x10000>;
     status = "okay";   // Tava disabled
 };
 
 &uart6 {
     status = "disabled";
 };
 
 &mub {
     status = "okay";
 };
 
 &wdog3{
     status = "disabled";
 };

root@scorpion:/lib/firmware# modprobe rpmsg_client_sample && modprobe imx_rpmsg_tty 
[   86.807476] NLB imx_rpmmsg_tty
root@scorpion:/lib/firmware# echo start > /sys/class/remoteproc/remoteproc0/state    
[   92.828659] remoteproc remoteproc0: powering up imx-rproc
[   92.852848] remoteproc remoteproc0: Booting fw image zephyr_openamp_rsc_table.elf, size 660180
[   92.861895]  remoteproc0#vdev0buffer: assigned reserved memory node vdev0buffer@9ff02000
[   92.875105] virtio_rpmsg_bus virtio1: rpmsg host is online
[   92.882776]  remoteproc0#vdev0buffer: registered virtio1 (type 7)
[   92.889343] remoteproc remoteproc0: remote processor imx-rproc is now up
root@scorpion:/lib/firmware# cat /sys/kernel/debug/remoteproc/remoteproc0/resource_table 
Entry 0 is of type vdev
  ID 7
  Notify ID 0
  Device features 0x1
  Guest features 0x1
  Config length 0x0
  Status 0x7
  Number of vrings 2
  Reserved (should be zero) [0][0]

  Vring 0
    Device Address 0x9ff00000
    Alignment 16
    Number of buffers 16
    Notify ID 0
    Physical Address 0x0

  Vring 1
    Device Address 0x9ff01000
    Alignment 16
    Number of buffers 16
    Notify ID 1
    Physical Address 0x0

root@scorpion:/lib/firmware# cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories
Carveout memory entry:
	Name: vdev0vring0
	Virtual address: 7b0edb64
	DMA address: 0x9ff00000
	Device address: 0x9ff00000
	Length: 0x1000 Bytes

Carveout memory entry:
	Name: vdev0vring1
	Virtual address: 7c87c534
	DMA address: 0x9ff01000
	Device address: 0x9ff01000
	Length: 0x1000 Bytes

Carveout memory entry:
	Name: cm4tcmcode
	Virtual address: 75013cd3
	DMA address: 0x007f8000
	Device address: 0x7f8000
	Length: 0x8000 Bytes

Carveout memory entry:
	Name: cm4sramcode
	Virtual address: 243f5356
	DMA address: 0x00900000
	Device address: 0x900000
	Length: 0x40000 Bytes

root@scorpion:/lib/firmware# ls /dev/r*
/dev/ram0   /dev/ram13	/dev/ram4  /dev/ram9	     /dev/rpmsg_ctrl1
/dev/ram1   /dev/ram14	/dev/ram5  /dev/random	     /dev/rtc
/dev/ram10  /dev/ram15	/dev/ram6  /dev/remoteproc0  /dev/rtc0
/dev/ram11  /dev/ram2	/dev/ram7  /dev/rfkill
/dev/ram12  /dev/ram3	/dev/ram8  /dev/rpmsg_ctrl0
root@scorpion:/lib/firmware# ls /dev/tty*
/dev/tty    /dev/tty19	/dev/tty3   /dev/tty40	/dev/tty51  /dev/tty62
/dev/tty0   /dev/tty2	/dev/tty30  /dev/tty41	/dev/tty52  /dev/tty63
/dev/tty1   /dev/tty20	/dev/tty31  /dev/tty42	/dev/tty53  /dev/tty7
/dev/tty10  /dev/tty21	/dev/tty32  /dev/tty43	/dev/tty54  /dev/tty8
/dev/tty11  /dev/tty22	/dev/tty33  /dev/tty44	/dev/tty55  /dev/tty9
/dev/tty12  /dev/tty23	/dev/tty34  /dev/tty45	/dev/tty56  /dev/ttymxc4
/dev/tty13  /dev/tty24	/dev/tty35  /dev/tty46	/dev/tty57  /dev/ttymxc6
/dev/tty14  /dev/tty25	/dev/tty36  /dev/tty47	/dev/tty58
/dev/tty15  /dev/tty26	/dev/tty37  /dev/tty48	/dev/tty59
/dev/tty16  /dev/tty27	/dev/tty38  /dev/tty49	/dev/tty6
/dev/tty17  /dev/tty28	/dev/tty39  /dev/tty5	/dev/tty60
/dev/tty18  /dev/tty29	/dev/tty4   /dev/tty50	/dev/tty61
root@scorpion:/lib/firmware# 
root@scorpion:/lib/firmware# dmesg | grep -i "remoteproc"
[    2.139313] remoteproc remoteproc0: imx-rproc is available
[    2.159148] remoteproc remoteproc0: attaching to imx-rproc
[    2.164721] remoteproc remoteproc0: remote processor imx-rproc is now attached
[   27.148570] remoteproc remoteproc0: stopped remote processor imx-rproc
[   92.828659] remoteproc remoteproc0: powering up imx-rproc
[   92.852848] remoteproc remoteproc0: Booting fw image zephyr_openamp_rsc_table.elf, size 660180
[   92.861895]  remoteproc0#vdev0buffer: assigned reserved memory node vdev0buffer@9ff02000
[   92.882776]  remoteproc0#vdev0buffer: registered virtio1 (type 7)
[   92.889343] remoteproc remoteproc0: remote processor imx-rproc is now up
root@scorpion:/lib/firmware# dmesg | grep -i "virtio0"
[    0.134940] virtio_rpmsg_bus virtio0: rpmsg host is online
root@scorpion:/lib/firmware# dmesg | grep -i "virtio1"
[   92.875105] virtio_rpmsg_bus virtio1: rpmsg host is online
[   92.882776]  remoteproc0#vdev0buffer: registered virtio1 (type 7)
root@scorpion:/lib/firmware# dmesg | grep -i "virtio0"
[    0.134940] virtio_rpmsg_bus virtio0: rpmsg host is online

@neuberfran
Copy link
Author

@jlh-makeen I really need vdev0buffer to appear in Cat Carveout result and you (maybe) need to check the correct mailbox passage (mub or mu?)

Screenshot_20240330_144147_Chrome
Screenshot_20240330_144231_Chrome

@jlh-makeen
Copy link
Contributor

@neuberfran

So regarding the DT configs, Zephyr needs to use MU_B 0x30ab0000 and Linux needs to use MU_A 0x30aa0000.

Otherwise you get a ressource conflict.

@neuberfran
Copy link
Author

@jlh-makeen Pls. Tell me Why I don't have vdev0buffer in Cat Carveout Cmd Result

@neuberfran
Copy link
Author

neuberfran commented Mar 31, 2024

@neuberfran

Portanto, com relação às configurações do DT, o Zephyr precisa usar MU_B 0x30ab0000 e o Linux precisa usar MU_A 0x30aa0000.

Caso contrário, você terá um conflito de recursos.

damn! Am I always doing it wrong using mub on Linux and Zephyr?

And what do you think about my mbox-namex (tx0, rx0, rxdb0 and not tx, rx, rxdb) and my mboxes (mub 0 1, mub 1 1 and mub 3 1)
Captura de tela de 2024-03-31 10-55-11

I change my main.c in openamp_tsc_table Zephyr project to ret = rpmsg_create_ept(&tty_ept, rpdev, "rpmsg-virtual-tty-channel",

But not solved yet
Captura de tela de 2024-03-31 11-05-35

I change 9ff00000 to bff00000
But not solved Yet (I can`t see vdev0buffer)

root@scorpion:/lib/firmware# cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories
Carveout memory entry:
	Name: vdev0vring0
	Virtual address: b1a53eef
	DMA address: 0xbff00000
	Device address: 0xbff00000
	Length: 0x1000 Bytes

Carveout memory entry:
	Name: vdev0vring1
	Virtual address: 6aaff1bd
	DMA address: 0xbff01000
	Device address: 0xbff01000
	Length: 0x1000 Bytes

Carveout memory entry:
	Name: cm4tcmcode
	Virtual address: 7c35a98b
	DMA address: 0x007f8000
	Device address: 0x7f8000
	Length: 0x8000 Bytes

Carveout memory entry:
	Name: cm4sramcode
	Virtual address: c93cf8ec
	DMA address: 0x00900000
	Device address: 0x900000
	Length: 0x40000 Bytes

@jlh-makeen
Copy link
Contributor

@neuberfran

It looks mostly right, your zephyr side was missing a zero in the reg= <0x9ff00000...

But you know I'm not expert here and I still haven't got my ttyrpmsg to show up.

I would disable the rpsmg node as the rproc is also allocating the mailboxes and virtio rpmsg bus.
Can you try disabling the "rpmsg" node and double check your addresses in DT ?

@neuberfran
Copy link
Author

@jlh-makeen Pls, give-me your main.c from openamp_rsc_table. I think there are differences between your main.c and mine. I want to keep them both the same.

@jlh-makeen
Copy link
Contributor

@jlh-makeen Pls, give-me your main.c from openamp_rsc_table. I think there are differences between your main.c and mine. I want to keep them both the same.

You can run the default openamp_rsc_table sample without modifications.

It is only necessary to provide the Zephyr ipc and shm nodes with the same setting as your Linux side, I advise that you use DDR for the shared memory vrings/vdevbuffer and zephyr side shm, in order to have symetric setup in zephyr/linux (the addresses will be the same).

When the openamp_rsc_table sample starts up, you should see rpmsg virtio bus ns-announcements, even if you don't have tty-rpmsg driver from Linux 5.16.

If you have that, you'll be ready for rpmsg :)

@neuberfran
Copy link
Author

-rom-start.ld

I need change my /home/neuberfran/zephyrproject/zephyr/include/zephyr/arch/arm/cortex_m/scripts/linker.ld from this:


/*
 * Copyright (c) 2013-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @file
 * @brief Linker command/script file
 *
 * Linker script for the Cortex-M platforms.
 */

#include <zephyr/linker/sections.h>
#include <zephyr/devicetree.h>

#include <zephyr/linker/devicetree_regions.h>
#include <zephyr/linker/linker-defs.h>
#include <zephyr/linker/linker-tool.h>

/* physical address of RAM */
#ifdef CONFIG_XIP
#define ROMABLE_REGION FLASH
#else
#define ROMABLE_REGION RAM
#endif
#define RAMABLE_REGION RAM

#if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0)
#define ROM_ADDR RAM_ADDR
#else
#define ROM_ADDR (CONFIG_FLASH_BASE_ADDRESS + CONFIG_FLASH_LOAD_OFFSET)
#endif

#if CONFIG_FLASH_LOAD_SIZE > 0
#define ROM_SIZE CONFIG_FLASH_LOAD_SIZE
#else
#define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET)
#endif

#if defined(CONFIG_XIP)
#if defined(CONFIG_IS_BOOTLOADER)
#define RAM_SIZE (CONFIG_BOOTLOADER_SRAM_SIZE * 1K)
#define RAM_ADDR (CONFIG_SRAM_BASE_ADDRESS + \
	(CONFIG_SRAM_SIZE * 1K - RAM_SIZE))
#else
#define RAM_SIZE (CONFIG_SRAM_SIZE * 1K)
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
#endif
#else
#define RAM_SIZE (CONFIG_SRAM_SIZE * 1K - CONFIG_BOOTLOADER_SRAM_SIZE * 1K)
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
#endif

#if defined(CONFIG_CUSTOM_SECTION_ALIGN)
_region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE;
#else
/* Set alignment to CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
 * to make linker section alignment comply with MPU granularity.
 */
#if defined(CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE)
_region_min_align = CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE;
#else
/* If building without MPU support, use default 4-byte alignment. */
_region_min_align = 4;
#endif
#endif

#if !defined(CONFIG_CUSTOM_SECTION_ALIGN) && defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
#define MPU_ALIGN(region_size) \
    . = ALIGN(_region_min_align); \
    . = ALIGN( 1 << LOG2CEIL(region_size))
#else
#define MPU_ALIGN(region_size) \
    . = ALIGN(_region_min_align)
#endif

MEMORY
    {
    FLASH (rx) : ORIGIN = ROM_ADDR, LENGTH = ROM_SIZE
    RAM   (wx) : ORIGIN = RAM_ADDR, LENGTH = RAM_SIZE
    LINKER_DT_REGIONS()
    /* Used by and documented in include/linker/intlist.ld */
    IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K
    }

ENTRY(CONFIG_KERNEL_ENTRY)

SECTIONS
    {

#include <zephyr/linker/rel-sections.ld>

    /*
     * .plt and .iplt are here according to 'arm-zephyr-elf-ld --verbose',
     * before text section.
     */
    /DISCARD/ :
	{
	*(.plt)
	}

    /DISCARD/ :
	{
	*(.iplt)
	}

    GROUP_START(ROMABLE_REGION)

	__rom_region_start = ROM_ADDR;

    SECTION_PROLOGUE(rom_start,,)
	{

/* Located in generated directory. This file is populated by calling
 * zephyr_linker_sources(ROM_START ...). This typically contains the vector
 * table and debug information.
 */
#include <snippets-rom-start.ld>

	} GROUP_LINK_IN(ROMABLE_REGION)

#ifdef CONFIG_CODE_DATA_RELOCATION

#include <linker_relocate.ld>

#endif /* CONFIG_CODE_DATA_RELOCATION */

    SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
	{
	__text_region_start = .;

#include <zephyr/linker/kobject-text.ld>

	*(.text)
	*(".text.*")
	*(".TEXT.*")
	*(.gnu.linkonce.t.*)

	/*
	 * These are here according to 'arm-zephyr-elf-ld --verbose',
	 * after .gnu.linkonce.t.*
	 */
	*(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
	. = ALIGN(4);

	} GROUP_LINK_IN(ROMABLE_REGION)

	__text_region_end = .;

#if defined (CONFIG_CPP)
	SECTION_PROLOGUE(.ARM.extab,,)
	{
	/*
	 * .ARM.extab section containing exception unwinding information.
	 */
	*(.ARM.extab* .gnu.linkonce.armextab.*)
	} GROUP_LINK_IN(ROMABLE_REGION)
#endif

	SECTION_PROLOGUE(.ARM.exidx,,)
	{
	/*
	 * This section, related to stack and exception unwinding, is placed
	 * explicitly to prevent it from being shared between multiple regions.
	 * It  must be defined for gcc to support 64-bit math and avoid
	 * section overlap.
	 */
	__exidx_start = .;
#if defined (__GCC_LINKER_CMD__)
	*(.ARM.exidx* gnu.linkonce.armexidx.*)
#endif
	__exidx_end = .;
	} GROUP_LINK_IN(ROMABLE_REGION)

	__rodata_region_start = .;

#include <zephyr/linker/common-rom.ld>
#include <zephyr/linker/thread-local-storage.ld>

    SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
	{
	*(.rodata)
	*(".rodata.*")
	*(.gnu.linkonce.r.*)

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-rodata.ld>

#include <zephyr/linker/kobject-rom.ld>

	/*
	 * For XIP images, in order to avoid the situation when __data_rom_start
	 * is 32-bit aligned, but the actual data is placed right after rodata
	 * section, which may not end exactly at 32-bit border, pad rodata
	 * section, so __data_rom_start points at data and it is 32-bit aligned.
	 *
	 * On non-XIP images this may enlarge image size up to 3 bytes. This
	 * generally is not an issue, since modern ROM and FLASH memory is
	 * usually 4k aligned.
	 */
	. = ALIGN(4);
	} GROUP_LINK_IN(ROMABLE_REGION)

#include <zephyr/linker/cplusplus-rom.ld>

#if defined(CONFIG_BUILD_ALIGN_LMA)
    /*
     * Include a padding section here to make sure that the LMA address
     * of the sections in the RAMABLE_REGION are aligned with those
     * section's VMA alignment requirements.
     */
    SECTION_PROLOGUE(padding_section,,)
	{
	__rodata_region_end = .;
	MPU_ALIGN(__rodata_region_end - ADDR(rom_start));
	} GROUP_LINK_IN(ROMABLE_REGION)
#else
	__rodata_region_end = .;
	MPU_ALIGN(__rodata_region_end - ADDR(rom_start));
#endif
	__rom_region_end = __rom_region_start + . - ADDR(rom_start);

    GROUP_END(ROMABLE_REGION)

    /*
     * These are here according to 'arm-zephyr-elf-ld --verbose',
     * before data section.
     */
    /DISCARD/ : {
	*(.got.plt)
	*(.igot.plt)
	*(.got)
	*(.igot)
	}

    GROUP_START(RAMABLE_REGION)

	. = RAM_ADDR;
	/* Align the start of image RAM with the
	 * minimum granularity required by MPU.
	 */
	. = ALIGN(_region_min_align);
	_image_ram_start = .;

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-ram-sections.ld>

#if defined(CONFIG_USERSPACE)
#define APP_SHARED_ALIGN . = ALIGN(_region_min_align);
#define SMEM_PARTITION_ALIGN MPU_ALIGN

#include <app_smem.ld>

	_app_smem_size = _app_smem_end - _app_smem_start;
	_app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME);

    SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
	{
        /*
         * For performance, BSS section is assumed to be 4 byte aligned and
         * a multiple of 4 bytes
         */
        . = ALIGN(4);
	__bss_start = .;
	__kernel_ram_start = .;

	*(.bss)
	*(".bss.*")
	*(COMMON)
	*(".kernel_bss.*")

#ifdef CONFIG_CODE_DATA_RELOCATION
#include <linker_sram_bss_relocate.ld>
#endif

        /*
         * As memory is cleared in words only, it is simpler to ensure the BSS
         * section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
		 */
	__bss_end = ALIGN(4);
	} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)

#include <zephyr/linker/common-noinit.ld>

#endif  /* CONFIG_USERSPACE */

    GROUP_START(DATA_REGION)

    SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,)
	{
	__data_region_start = .;
	__data_start = .;
	*(.data)
	*(".data.*")
	*(".kernel.*")

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-rwdata.ld>

#ifdef CONFIG_CODE_DATA_RELOCATION
#include <linker_sram_data_relocate.ld>
#endif
	__data_end = .;

	} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
    __data_size = __data_end - __data_start;
    __data_load_start = LOADADDR(_DATA_SECTION_NAME);

    __data_region_load_start = LOADADDR(_DATA_SECTION_NAME);

#include <zephyr/linker/common-ram.ld>
#include <zephyr/linker/kobject-data.ld>

#include <zephyr/linker/cplusplus-ram.ld>

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-data-sections.ld>

    __data_region_end = .;

#ifndef CONFIG_USERSPACE
   SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
	{
        /*
         * For performance, BSS section is assumed to be 4 byte aligned and
         * a multiple of 4 bytes
         */
        . = ALIGN(4);
	__bss_start = .;
	__kernel_ram_start = .;

	*(.bss)
	*(".bss.*")
	*(COMMON)
	*(".kernel_bss.*")

#ifdef CONFIG_CODE_DATA_RELOCATION
#include <linker_sram_bss_relocate.ld>
#endif

        /*
         * As memory is cleared in words only, it is simpler to ensure the BSS
         * section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
		 */
	__bss_end = ALIGN(4);
	} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)

    SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),)
        {
        /*
         * This section is used for non-initialized objects that
         * will not be cleared during the boot process.
         */
        *(.noinit)
        *(".noinit.*")
	*(".kernel_noinit.*")

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-noinit.ld>

        } GROUP_NOLOAD_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
#endif /* CONFIG_USERSPACE */

    /* Define linker symbols */

    __kernel_ram_end = RAM_ADDR + RAM_SIZE;
    __kernel_ram_size = __kernel_ram_end - __kernel_ram_start;

#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
GROUP_START(ITCM)

	SECTION_PROLOGUE(_ITCM_SECTION_NAME,,SUBALIGN(4))
	{
		__itcm_start = .;
		*(.itcm)
		*(".itcm.*")
		__itcm_end = .;
	} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)

	__itcm_size = __itcm_end - __itcm_start;
	__itcm_load_start = LOADADDR(_ITCM_SECTION_NAME);

GROUP_END(ITCM)
#endif

#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)
GROUP_START(DTCM)

	SECTION_PROLOGUE(_DTCM_BSS_SECTION_NAME, (NOLOAD),SUBALIGN(4))
	{
		__dtcm_start = .;
		__dtcm_bss_start = .;
		*(.dtcm_bss)
		*(".dtcm_bss.*")
		__dtcm_bss_end = .;
	} GROUP_LINK_IN(DTCM)

	SECTION_PROLOGUE(_DTCM_NOINIT_SECTION_NAME, (NOLOAD),SUBALIGN(4))
	{
		__dtcm_noinit_start = .;
		*(.dtcm_noinit)
		*(".dtcm_noinit.*")
		__dtcm_noinit_end = .;
	} GROUP_LINK_IN(DTCM)

	SECTION_PROLOGUE(_DTCM_DATA_SECTION_NAME,,SUBALIGN(4))
	{
		__dtcm_data_start = .;
		*(.dtcm_data)
		*(".dtcm_data.*")
		__dtcm_data_end = .;
	} GROUP_LINK_IN(DTCM AT> ROMABLE_REGION)

	__dtcm_end = .;

	__dtcm_data_load_start = LOADADDR(_DTCM_DATA_SECTION_NAME);

GROUP_END(DTCM)
#endif

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-sections.ld>

#include <zephyr/linker/ram-end.ld>

    GROUP_END(RAMABLE_REGION)

#include <zephyr/linker/debug-sections.ld>

    /DISCARD/ : { *(.note.GNU-stack) }

    SECTION_PROLOGUE(.ARM.attributes, 0,)
	{
	KEEP(*(.ARM.attributes))
	KEEP(*(.gnu.attributes))
	}

    /* Sections generated from 'zephyr,memory-region' nodes */
    LINKER_DT_SECTIONS()

/* Must be last in romable region */
SECTION_PROLOGUE(.last_section,,)
{
#ifdef CONFIG_LINKER_LAST_SECTION_ID
  /* Fill last section with a word to ensure location counter and actual rom
   * region data usage match. */
  LONG(CONFIG_LINKER_LAST_SECTION_ID_PATTERN)
#endif
} GROUP_LINK_IN(ROMABLE_REGION)

/* To provide the image size as a const expression,
 * calculate this value here. */
_flash_used = LOADADDR(.last_section) + SIZEOF(.last_section) - __rom_region_start;

    }

to??????????

@jlh-makeen
Copy link
Contributor

As I explained before to this:


/*
 * Copyright (c) 2013-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @file
 * @brief Linker command/script file
 *
 * Linker script for the Cortex-M platforms.
 */

#include <zephyr/linker/sections.h>
#include <zephyr/devicetree.h>

#include <zephyr/linker/devicetree_regions.h>
#include <zephyr/linker/linker-defs.h>
#include <zephyr/linker/linker-tool.h>

/* physical address of RAM */
#ifdef CONFIG_XIP
#define ROMABLE_REGION FLASH
#else
#define ROMABLE_REGION RAM
#endif
#define RAMABLE_REGION RAM

#if !defined(CONFIG_XIP) && (CONFIG_FLASH_SIZE == 0)
#define ROM_ADDR RAM_ADDR
#else
#define ROM_ADDR (CONFIG_FLASH_BASE_ADDRESS + CONFIG_FLASH_LOAD_OFFSET)
#endif

#if CONFIG_FLASH_LOAD_SIZE > 0
#define ROM_SIZE CONFIG_FLASH_LOAD_SIZE
#else
#define ROM_SIZE (CONFIG_FLASH_SIZE*1K - CONFIG_FLASH_LOAD_OFFSET)
#endif

#if defined(CONFIG_XIP)
#if defined(CONFIG_IS_BOOTLOADER)
#define RAM_SIZE (CONFIG_BOOTLOADER_SRAM_SIZE * 1K)
#define RAM_ADDR (CONFIG_SRAM_BASE_ADDRESS + \
	(CONFIG_SRAM_SIZE * 1K - RAM_SIZE))
#else
#define RAM_SIZE (CONFIG_SRAM_SIZE * 1K)
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
#endif
#else
#define RAM_SIZE (CONFIG_SRAM_SIZE * 1K - CONFIG_BOOTLOADER_SRAM_SIZE * 1K)
#define RAM_ADDR CONFIG_SRAM_BASE_ADDRESS
#endif

#if defined(CONFIG_CUSTOM_SECTION_ALIGN)
_region_min_align = CONFIG_CUSTOM_SECTION_MIN_ALIGN_SIZE;
#else
/* Set alignment to CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
 * to make linker section alignment comply with MPU granularity.
 */
#if defined(CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE)
_region_min_align = CONFIG_ARM_MPU_REGION_MIN_ALIGN_AND_SIZE;
#else
/* If building without MPU support, use default 4-byte alignment. */
_region_min_align = 4;
#endif
#endif

#if !defined(CONFIG_CUSTOM_SECTION_ALIGN) && defined(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT)
#define MPU_ALIGN(region_size) \
    . = ALIGN(_region_min_align); \
    . = ALIGN( 1 << LOG2CEIL(region_size))
#else
#define MPU_ALIGN(region_size) \
    . = ALIGN(_region_min_align)
#endif

MEMORY
    {
    BOOTVECTOR (rx) : ORIGIN = 0x00180000, LENGTH = 32K
    FLASH (rx) : ORIGIN = ROM_ADDR, LENGTH = ROM_SIZE
    RAM   (wx) : ORIGIN = RAM_ADDR, LENGTH = RAM_SIZE
    LINKER_DT_REGIONS()
    /* Used by and documented in include/linker/intlist.ld */
    IDT_LIST (wx) : ORIGIN = 0xFFFFF7FF, LENGTH = 2K
    }

ENTRY(CONFIG_KERNEL_ENTRY)

SECTIONS
    {

#include <zephyr/linker/rel-sections.ld>

    /*
     * .plt and .iplt are here according to 'arm-zephyr-elf-ld --verbose',
     * before text section.
     */
    /DISCARD/ :
	{
	*(.plt)
	}

    /DISCARD/ :
	{
	*(.iplt)
	}

    GROUP_START(ROMABLE_REGION)

	__rom_region_start = ROM_ADDR;

    SECTION_PROLOGUE(rom_start,,)
	{

/* Located in generated directory. This file is populated by calling
 * zephyr_linker_sources(ROM_START ...). This typically contains the vector
 * table and debug information.
 */
#include <snippets-rom-start.ld>

	} GROUP_LINK_IN(BOOTVECTOR)

#ifdef CONFIG_CODE_DATA_RELOCATION

#include <linker_relocate.ld>

#endif /* CONFIG_CODE_DATA_RELOCATION */

    SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
	{
	__text_region_start = .;

#include <zephyr/linker/kobject-text.ld>

	*(.text)
	*(".text.*")
	*(".TEXT.*")
	*(.gnu.linkonce.t.*)

	/*
	 * These are here according to 'arm-zephyr-elf-ld --verbose',
	 * after .gnu.linkonce.t.*
	 */
	*(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
	. = ALIGN(4);

	} GROUP_LINK_IN(ROMABLE_REGION)

	__text_region_end = .;

#if defined (CONFIG_CPP)
	SECTION_PROLOGUE(.ARM.extab,,)
	{
	/*
	 * .ARM.extab section containing exception unwinding information.
	 */
	*(.ARM.extab* .gnu.linkonce.armextab.*)
	} GROUP_LINK_IN(ROMABLE_REGION)
#endif

	SECTION_PROLOGUE(.ARM.exidx,,)
	{
	/*
	 * This section, related to stack and exception unwinding, is placed
	 * explicitly to prevent it from being shared between multiple regions.
	 * It  must be defined for gcc to support 64-bit math and avoid
	 * section overlap.
	 */
	__exidx_start = .;
#if defined (__GCC_LINKER_CMD__)
	*(.ARM.exidx* gnu.linkonce.armexidx.*)
#endif
	__exidx_end = .;
	} GROUP_LINK_IN(ROMABLE_REGION)

	__rodata_region_start = .;

#include <zephyr/linker/common-rom.ld>
#include <zephyr/linker/thread-local-storage.ld>

    SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
	{
	*(.rodata)
	*(".rodata.*")
	*(.gnu.linkonce.r.*)

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-rodata.ld>

#include <zephyr/linker/kobject-rom.ld>

	/*
	 * For XIP images, in order to avoid the situation when __data_rom_start
	 * is 32-bit aligned, but the actual data is placed right after rodata
	 * section, which may not end exactly at 32-bit border, pad rodata
	 * section, so __data_rom_start points at data and it is 32-bit aligned.
	 *
	 * On non-XIP images this may enlarge image size up to 3 bytes. This
	 * generally is not an issue, since modern ROM and FLASH memory is
	 * usually 4k aligned.
	 */
	. = ALIGN(4);
	} GROUP_LINK_IN(ROMABLE_REGION)

#include <zephyr/linker/cplusplus-rom.ld>

#if defined(CONFIG_BUILD_ALIGN_LMA)
    /*
     * Include a padding section here to make sure that the LMA address
     * of the sections in the RAMABLE_REGION are aligned with those
     * section's VMA alignment requirements.
     */
    SECTION_PROLOGUE(padding_section,,)
	{
	__rodata_region_end = .;
	MPU_ALIGN(__rodata_region_end - ADDR(rom_start));
	} GROUP_LINK_IN(ROMABLE_REGION)
#else
	__rodata_region_end = .;
	MPU_ALIGN(__rodata_region_end - ADDR(rom_start));
#endif
	__rom_region_end = __rom_region_start + . - ADDR(rom_start);

    GROUP_END(ROMABLE_REGION)

    /*
     * These are here according to 'arm-zephyr-elf-ld --verbose',
     * before data section.
     */
    /DISCARD/ : {
	*(.got.plt)
	*(.igot.plt)
	*(.got)
	*(.igot)
	}

    GROUP_START(RAMABLE_REGION)

	. = RAM_ADDR;
	/* Align the start of image RAM with the
	 * minimum granularity required by MPU.
	 */
	. = ALIGN(_region_min_align);
	_image_ram_start = .;

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-ram-sections.ld>

#if defined(CONFIG_USERSPACE)
#define APP_SHARED_ALIGN . = ALIGN(_region_min_align);
#define SMEM_PARTITION_ALIGN MPU_ALIGN

#include <app_smem.ld>

	_app_smem_size = _app_smem_end - _app_smem_start;
	_app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME);

    SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
	{
        /*
         * For performance, BSS section is assumed to be 4 byte aligned and
         * a multiple of 4 bytes
         */
        . = ALIGN(4);
	__bss_start = .;
	__kernel_ram_start = .;

	*(.bss)
	*(".bss.*")
	*(COMMON)
	*(".kernel_bss.*")

#ifdef CONFIG_CODE_DATA_RELOCATION
#include <linker_sram_bss_relocate.ld>
#endif

        /*
         * As memory is cleared in words only, it is simpler to ensure the BSS
         * section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
		 */
	__bss_end = ALIGN(4);
	} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)

#include <zephyr/linker/common-noinit.ld>

#endif  /* CONFIG_USERSPACE */

    GROUP_START(DATA_REGION)

    SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,)
	{
	__data_region_start = .;
	__data_start = .;
	*(.data)
	*(".data.*")
	*(".kernel.*")

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-rwdata.ld>

#ifdef CONFIG_CODE_DATA_RELOCATION
#include <linker_sram_data_relocate.ld>
#endif
	__data_end = .;

	} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
    __data_size = __data_end - __data_start;
    __data_load_start = LOADADDR(_DATA_SECTION_NAME);

    __data_region_load_start = LOADADDR(_DATA_SECTION_NAME);

#include <zephyr/linker/common-ram.ld>
#include <zephyr/linker/kobject-data.ld>

#include <zephyr/linker/cplusplus-ram.ld>

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-data-sections.ld>

    __data_region_end = .;

#ifndef CONFIG_USERSPACE
   SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
	{
        /*
         * For performance, BSS section is assumed to be 4 byte aligned and
         * a multiple of 4 bytes
         */
        . = ALIGN(4);
	__bss_start = .;
	__kernel_ram_start = .;

	*(.bss)
	*(".bss.*")
	*(COMMON)
	*(".kernel_bss.*")

#ifdef CONFIG_CODE_DATA_RELOCATION
#include <linker_sram_bss_relocate.ld>
#endif

        /*
         * As memory is cleared in words only, it is simpler to ensure the BSS
         * section ends on a 4 byte boundary. This wastes a maximum of 3 bytes.
		 */
	__bss_end = ALIGN(4);
	} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)

    SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),)
        {
        /*
         * This section is used for non-initialized objects that
         * will not be cleared during the boot process.
         */
        *(.noinit)
        *(".noinit.*")
	*(".kernel_noinit.*")

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-noinit.ld>

        } GROUP_NOLOAD_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
#endif /* CONFIG_USERSPACE */

    /* Define linker symbols */

    __kernel_ram_end = RAM_ADDR + RAM_SIZE;
    __kernel_ram_size = __kernel_ram_end - __kernel_ram_start;

#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
GROUP_START(ITCM)

	SECTION_PROLOGUE(_ITCM_SECTION_NAME,,SUBALIGN(4))
	{
		__itcm_start = .;
		*(.itcm)
		*(".itcm.*")
		__itcm_end = .;
	} GROUP_LINK_IN(ITCM AT> ROMABLE_REGION)

	__itcm_size = __itcm_end - __itcm_start;
	__itcm_load_start = LOADADDR(_ITCM_SECTION_NAME);

GROUP_END(ITCM)
#endif

#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)
GROUP_START(DTCM)

	SECTION_PROLOGUE(_DTCM_BSS_SECTION_NAME, (NOLOAD),SUBALIGN(4))
	{
		__dtcm_start = .;
		__dtcm_bss_start = .;
		*(.dtcm_bss)
		*(".dtcm_bss.*")
		__dtcm_bss_end = .;
	} GROUP_LINK_IN(DTCM)

	SECTION_PROLOGUE(_DTCM_NOINIT_SECTION_NAME, (NOLOAD),SUBALIGN(4))
	{
		__dtcm_noinit_start = .;
		*(.dtcm_noinit)
		*(".dtcm_noinit.*")
		__dtcm_noinit_end = .;
	} GROUP_LINK_IN(DTCM)

	SECTION_PROLOGUE(_DTCM_DATA_SECTION_NAME,,SUBALIGN(4))
	{
		__dtcm_data_start = .;
		*(.dtcm_data)
		*(".dtcm_data.*")
		__dtcm_data_end = .;
	} GROUP_LINK_IN(DTCM AT> ROMABLE_REGION)

	__dtcm_end = .;

	__dtcm_data_load_start = LOADADDR(_DTCM_DATA_SECTION_NAME);

GROUP_END(DTCM)
#endif

/* Located in generated directory. This file is populated by the
 * zephyr_linker_sources() Cmake function.
 */
#include <snippets-sections.ld>

#include <zephyr/linker/ram-end.ld>

    GROUP_END(RAMABLE_REGION)

#include <zephyr/linker/debug-sections.ld>

    /DISCARD/ : { *(.note.GNU-stack) }

    SECTION_PROLOGUE(.ARM.attributes, 0,)
	{
	KEEP(*(.ARM.attributes))
	KEEP(*(.gnu.attributes))
	}

    /* Sections generated from 'zephyr,memory-region' nodes */
    LINKER_DT_SECTIONS()

/* Must be last in romable region */
SECTION_PROLOGUE(.last_section,,)
{
#ifdef CONFIG_LINKER_LAST_SECTION_ID
  /* Fill last section with a word to ensure location counter and actual rom
   * region data usage match. */
  LONG(CONFIG_LINKER_LAST_SECTION_ID_PATTERN)
#endif
} GROUP_LINK_IN(ROMABLE_REGION)

/* To provide the image size as a const expression,
 * calculate this value here. */
_flash_used = LOADADDR(.last_section) + SIZEOF(.last_section) - __rom_region_start;

    }

@neuberfran
Copy link
Author

@jlh-makeen Unfortunately, it hasn't been resolved yet. The *.bin file generated after the changes did not fit in the Uboot partition (I had to remove it to load Linux). According to the commands in the photo, I still have virtio0 in the directories, but I still don't have /dev/ttyRPMSG
Captura de tela de 2024-04-12 12-56-16


pwd
/home/neuberfran/zephyrproject/zephyr/build/openamp_rsc_table/zephyr
neuberfran@ubuntu2204:~/zephyrproject/zephyr/build/openamp_rsc_table/zephyr$ ls -lha -S
total 515M
-rwxrwxr-x  1 neuberfran neuberfran 511M abr 12 12:42 zephyr_openamp_rsc_table.bin
-rw-rw-r--  1 neuberfran neuberfran 655K abr 12 12:42 edt.pickle
-rwxrwxr-x  1 neuberfran neuberfran 647K abr 12 12:42 zephyr_pre0.elf
-rwxrwxr-x  1 neuberfran neuberfran 647K abr 12 12:42 zephyr_openamp_rsc_table.elf
-rw-rw-r--  1 neuberfran neuberfran 412K abr 12 12:42 libzephyr.a
-rw-rw-r--  1 neuberfran neuberfran 319K abr 12 12:42 zephyr_pre0.map
-rw-rw-r--  1 neuberfran neuberfran 318K abr 12 12:42 zephyr_final.map
-rw-rw-r--  1 neuberfran neuberfran 318K abr 12 12:42 zephyr_openamp_rsc_table.map
-rw-rw-r--  1 neuberfran neuberfran 282K abr 12 12:42 dts.cmake
-rw-rw-r--  1 neuberfran neuberfran 188K abr 12 12:42 zephyr.dts.pre
-rw-rw-r--  1 neuberfran neuberfran  42K abr 12 12:42 zephyr.dts
-rw-rw-r--  1 neuberfran neuberfran  39K abr 12 12:42 .config
-rw-rw-r--  1 neuberfran neuberfran  14K abr 12 12:42 cmake_install.cmake
-rw-rw-r--  1 neuberfran neuberfran  13K abr 12 12:42 linker_zephyr_pre0.cmd
-rw-rw-r--  1 neuberfran neuberfran  13K abr 12 12:42 linker.cmd
-rw-rw-r--  1 neuberfran neuberfran  11K abr 12 12:42 isr_tables.c
-rw-rw-r--  1 neuberfran neuberfran 6,0K abr 12 12:42 linker_zephyr_pre0.cmd.dep
-rw-rw-r--  1 neuberfran neuberfran 6,0K abr 12 12:42 linker.cmd.dep
-rw-rw-r--  1 neuberfran neuberfran 4,7K abr 12 12:42 zephyr_openamp_rsc_table.stat
drwxrwxr-x 14 neuberfran neuberfran 4,0K abr 12 12:42 .
drwxrwxr-x  7 neuberfran neuberfran 4,0K abr 12 12:42 ..
drwxrwxr-x  5 neuberfran neuberfran 4,0K abr 12 12:42 arch
drwxrwxr-x  3 neuberfran neuberfran 4,0K abr 12 12:42 boards
drwxrwxr-x  5 neuberfran neuberfran 4,0K abr 12 12:42 cmake
drwxrwxr-x  6 neuberfran neuberfran 4,0K abr 12 12:42 CMakeFiles
drwxrwxr-x 15 neuberfran neuberfran 4,0K abr 12 12:42 drivers
drwxrwxr-x  3 neuberfran neuberfran 4,0K abr 12 12:42 include
drwxrwxr-x  3 neuberfran neuberfran 4,0K abr 12 12:42 kconfig
drwxrwxr-x  3 neuberfran neuberfran 4,0K abr 12 12:42 kernel
drwxrwxr-x  9 neuberfran neuberfran 4,0K abr 12 12:42 lib
drwxrwxr-x  3 neuberfran neuberfran 4,0K abr 12 12:42 misc
drwxrwxr-x  4 neuberfran neuberfran 4,0K abr 12 12:42 soc
drwxrwxr-x 22 neuberfran neuberfran 4,0K abr 12 12:42 subsys
-rw-rw-r--  1 neuberfran neuberfran  922 abr 12 12:42 zephyr.dts.d
-rw-rw-r--  1 neuberfran neuberfran  801 abr 12 12:42 snippets_generated.cmake
-rw-rw-r--  1 neuberfran neuberfran  110 abr 12 12:42 .config.sysbuild
-rw-rw-r--  1 neuberfran neuberfran   96 abr 12 12:42 .cmake.dotconfig.checksum
-rwxrwxr-x  1 neuberfran neuberfran   40 abr 12 12:42 isrList.bin

@neuberfran
Copy link
Author

neuberfran commented Apr 12, 2024

@jlh-makeen In portuguese to english novo=new and antigo=old. VsCode only noticed 2 changes

Screenshot from 2024-04-12 13-18-21

@neuberfran
Copy link
Author

@jlh-makeen I'm already suspecting that my vrings may not be 0x1000 but rather 0x8000. So I don't know if I have enough (remaining) memory for the vdevbuffer and what the vdevbuffer would look like. Could you tell me?
https://community.toradex.com/t/verdin-mini-rpmsg-lite-increase-buffer-size/18356/5
https://community.nxp.com/t5/i-MX-Processors/Changing-RPMsg-Buffer-Size/m-p/1221466/highlight/true#M168448

@jlh-makeen
Copy link
Contributor

jlh-makeen commented Apr 18, 2024

@jlh-makeen I'm already suspecting that my vrings may not be 0x1000 but rather 0x8000. So I don't know if I have enough (remaining) memory for the vdevbuffer and what the vdevbuffer would look like. Could you tell me? https://community.toradex.com/t/verdin-mini-rpmsg-lite-increase-buffer-size/18356/5 https://community.nxp.com/t5/i-MX-Processors/Changing-RPMsg-Buffer-Size/m-p/1221466/highlight/true#M168448

@neuberfran

In order to get rpmsg to work, we had to update to kernel 5.16 to have the official tty-rpmsg and rpmsgctrl drivers.
Then in the DT, we have defined 0x1000 size for the VRING0 and VRING1 and 0x8000 for the vdevbuffer all in DDR memory.

When rproc cannot allocate the memory you request (512 bytes * CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF)

For 0x8000 you can go up to CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=32 buffers
You will get error -62 when kicking the virtio when remoteproc.
If you get -62 you need to reduce the number of buffers or increase the memory size for the vdevbuffer.

Our particular setup:

Entry 0 is of type vdev
  ID 7
  Notify ID 0
  Device features 0x1
  Guest features 0x1
  Config length 0x0
  Status 0x7
  Number of vrings 2
  Reserved (should be zero) [0][0]

  Vring 0
    Device Address 0xbfff0000
    Alignment 16
    Number of buffers 32
    Notify ID 0
    Physical Address 0x0

  Vring 1
    Device Address 0xbfff1000
    Alignment 16
    Number of buffers 32
    Notify ID 1
    Physical Address 0x0

When our app starts we created 3 tty endpoints:

[ 8883.780211] remoteproc remoteproc0: powering up imx-rproc
[ 8883.807068] remoteproc remoteproc0: Booting fw image zephyr_pnet_ipm.elf, size 2223228
[ 8883.814115] remoteproc remoteproc0: no SP or PC loaded into M4 bootrom vector. Core will not start!
[ 8883.823367]  remoteproc0#vdev0buffer: assigned reserved memory node vdev0buffer0@bfff2000
[ 8883.835930]  remoteproc0#vdev0buffer: registered virtio0 (type 7)
[ 8883.849667] remoteproc remoteproc0: remote processor imx-rproc is now up
[ 8883.862012] virtio_rpmsg_bus virtio0: rpmsg host is online
[ 8883.862321] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty addr 0x400
[ 8883.880476] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty addr 0x401
[ 8883.892294] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty addr 0x402

In our case we needed the linker script to start the M4 boot-vector as I mention in this discussion:

#71617

I'll provide a PR for the bootvector when I have time.

Regarding the if your kernel doesn't have the rpmsg-tty driver but instead the:
when creating the endpoint for imx-rpmsg-tty driver you need the endpoint name: "rpmsg-virtual-tty-channel"

// As defined  in the linux kernel imx-rpmsg-tty
static struct rpmsg_device_id rpmsg_driver_tty_id_table[] = {
	{ .name	= "rpmsg-virtual-tty-channel-1" },
	{ .name	= "rpmsg-virtual-tty-channel" },
	{ .name = "rpmsg-openamp-demo-channel" },
	{ },
};

You also need to use mbox id 0 as mentionned before in the Linux DT.

@neuberfran
Copy link
Author

@jlh-makeen

After I chage zephyr,flash (to)= &ocram_code; (from &tcml_code)
messages from zephyr_openamp_rsc_table.bin no longer appear on the zephyr side
Question:
Do I need to start zephyr_openamp_rsc_table.bin in Uboot at 0x7f8000 or 0x900000?

## No elf image at address 0x007f8000
## Starting auxiliary core stack = 0x200020B0, pc = 0x00900CE9...
baseboard is pi
lmb_dump_all:
 memory.cnt  = 0x1
 memory[0]	[0x80000000-0xbfffffff], 0x40000000 bytes flags: 0
 reserved.cnt  = 0x1
 reserved[0]	[0xbcd5d858-0xbfffffff], 0x032a27a8 bytes flags: 0

Captura de tela de 2024-04-21 15-06-31

@neuberfran
Copy link
Author

@jlh-makeen


readelf -S zephyr_openamp_rsc_table.elf 
Há 31 cabeçalhos de secção, começando no desvio 0xa14b4:

Cabeçalho de Seções:
  [Nr] Nome Fora do Tipo de Endereço ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] rom_start         PROGBITS        00180000 000114 00023c 00 WAX  0   0  4
  [ 2] text              PROGBITS        00901000 000350 00455c 00  AX  0   0  4
  [ 3] .ARM.exidx        ARM_EXIDX       0090555c 0048ac 000008 00  AL  2   0  4
  [ 4] initlevel         PROGBITS        00905564 0048b4 000040 00   A  0   0  4
  [ 5] device_area       PROGBITS        009055a4 0048f4 000028 00   A  0   0  4
  [ 6] sw_isr_table      PROGBITS        009055cc 00491c 0003f8 00  WA  0   0  4
  [ 7] tbss              NOBITS          009059c4 004d14 000004 00 WAT  0   0  4
  [ 8] rodata            PROGBITS        009059c4 004d14 0009c0 00   A  0   0  4
  [ 9] .ramfunc          PROGBITS        20000000 005858 000000 00   W  0   0  1
  [10] datas             PROGBITS        20000000 0056d4 0000e0 00  WA  0   0  4
  [11] device_states     PROGBITS        200000e0 0057b4 000004 00  WA  0   0  1
  [12] k_heap_area       PROGBITS        200000e4 0057b8 000014 00  WA  0   0  4
  [13] k_sem_area        PROGBITS        200000f8 0057cc 000030 00  WA  0   0  4
  [14] bss               NOBITS          20000128 005858 000442 00  WA  0   0  8
  [15] noinit            NOBITS          20000570 005858 001f4c 00  WA  0   0  8
  [16] .comment          PROGBITS        00000000 005858 000020 01  MS  0   0  1
  [17] .debug_aranges    PROGBITS        00000000 005878 001298 00      0   0  8
  [18] .debug_info       PROGBITS        00000000 006b10 048893 00      0   0  1
  [19] .debug_abbrev     PROGBITS        00000000 04f3a3 00a53b 00      0   0  1
  [20] .debug_line       PROGBITS        00000000 0598de 017ab0 00      0   0  1
  [21] .debug_frame      PROGBITS        00000000 071390 002c24 00      0   0  4
  [22] .debug_str        PROGBITS        00000000 073fb4 0099a6 01  MS  0   0  1
  [23] .debug_loc        PROGBITS        00000000 07d95a 015d1f 00      0   0  1
  [24] .debug_ranges     PROGBITS        00000000 093680 0035f8 00      0   0  8
  [25] .ARM.attributes   ARM_ATTRIBUTES  00000000 096c78 000032 00      0   0  1
  [26] .last_section     PROGBITS        009064ac 0057fc 000004 00   A  0   0  1
  [27] .resource_table   PROGBITS        009064b0 005800 000058 00  WA  0   0  4
  [28] .symtab           SYMTAB          00000000 096cac 005ca0 10     29 787  4
  [29] .strtab           STRTAB          00000000 09c94c 004a2a 00      0   0  1
  [30] .shstrtab         STRTAB          00000000 0a1376 00013c 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required)
```, G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), y (purecode), p (processor specific)

@neuberfran
Copy link
Author

@jlh-makeen

I carried out several tests today, but unfortunately still without success.

Captura de tela de 2024-04-21 20-56-55

@neuberfran
Copy link
Author

neuberfran commented Apr 23, 2024

@jlh-makeen Hello. Firstly, I want to congratulate you for being able to upload /dev/ttyRPMSG using Remoteproc/Linux-UserSpace/Zephyr Upstream on your imx7d device (even though it only has 1gb)

For my part, I haven't managed it yet and I would like you (if possible) to clarify my doubts using the photos below:

  1. Do you change something in NS announcement in the RPMSG on Linux?
    Captura de tela de 2024-04-23 12-04-03

  2. Is there a possibility that I can be successful using Linux 5.15? If so, what changes should I make?
    Captura de tela de 2024-04-23 11-59-59

  3. Can I use &tcml_code in zephyr,flash ?

@jlh-makeen
Copy link
Contributor

@jlh-makeen Hello. Firstly, I want to congratulate you for being able to upload /dev/ttyRPMSG using Remoteproc/Linux-UserSpace/Zephyr Upstream on your imx7d device (even though it only has 1gb)

For my part, I haven't managed it yet and I would like you (if possible) to clarify my doubts using the photos below:

  1. Do you change something in NS announcement in the RPMSG on Linux?
    Captura de tela de 2024-04-23 12-04-03
  2. Is there a possibility that I can be successful using Linux 5.15? If so, what changes should I make?
    Captura de tela de 2024-04-23 11-59-59
  3. Can I use &tcml_code in zephyr,flash ?

@neuberfran

There is no need to modify the Linux driver, at least in Linux 5.16.

We have only been able to successfully have ttyRPMSG on Linux 5.16 (and newer should work too)

You need PR #71684 in order to have the zephyr.elf file place the rom_start region (aka boot vector) into the OCRAM_S in order to be able to boot the M4 core using tcml_code memory.

There is a trick where you can get the M4 to boot by using ocram_s by changing the definition in the DT for ocram_s_code from address to the alias 0x00000000, this way the rproc driver is going to properly load the zephyr.elf file and boot-vectors at the right place.
This will also be a valid addresssing for the M4 core as address space 0x00180000 for OCRAM_S code is aliased at 0x00000000.

I do not have the ressources and time to try it with linux 5.15, we need people from NXP or your vendor to support us here. As I explained linux 5.15 doesn't include the generic "tty-rpmsg" driver but instead the "imx-tty-rpmsg" which uses different rpmsg-endpoint names.

As of now, people have been very silent on the subject.

@neuberfran
Copy link
Author

neuberfran commented May 2, 2024

@jlh-makeen I can do echo "test2" > /dev/ttyRPMSG0 and led light red blink in cp2102 UART-USB adapter in USB1 (by m4 side) But nothing appear in USB1 m4 side
image

cat /sys/kernel/debug/remoteproc/remoteproc0/resource_table 
Entry 0 is of type vdev
  ID 7
  Notify ID 0
  Device features 0x1
  Guest features 0x1
  Config length 0x0
  Status 0x7
  Number of vrings 2
  Reserved (should be zero) [0][0]

  Vring 0
    Device Address 0x9ff00000
    Alignment 16
    Number of buffers 16
    Notify ID 0
    Physical Address 0x0

  Vring 1
    Device Address 0x9ff01000
    Alignment 16
    Number of buffers 16
    Notify ID 1
    Physical Address 0x0
cat /sys/kernel/debug/remoteproc/remoteproc0/carveout_memories
Carveout memory entry:
	Name: vdevbuffer
	Virtual address: 61161a75
	DMA address: 0x9ff02000
	Device address: 0x9ff02000
	Length: 0xfe000 Bytes

Carveout memory entry:
	Name: vdev0vring0
	Virtual address: c79cef80
	DMA address: 0x9ff00000
	Device address: 0x9ff00000
	Length: 0x1000 Bytes

Carveout memory entry:
	Name: vdev0vring1
	Virtual address: 49beba9f
	DMA address: 0x9ff01000
	Device address: 0x9ff01000
	Length: 0x1000 Bytes

Carveout memory entry:
	Name: cm4tcmcode
	Virtual address: f8f35095
	DMA address: 0x007f8000
	Device address: 0x7f8000
	Length: 0x8000 Bytes

Carveout memory entry:
	Name: cm4sramcode
	Virtual address: 0aa07789
	DMA address: 0x00900000
	Device address: 0x900000
	Length: 0x40000 Bytes

@jlh-makeen
Copy link
Contributor

@neuberfran
Looks like you are very close to the goal in fact your Linux kernel is now receiving the RPMSG name service annoucements message and it is creating the proper channels rpmsg-tty and rpmsg-client-sample.

Does /dev/ttyRPMSG0 show up by itself in the /dev directory ?

Because I can see the dmesg output it not showing that the rpmsg-tty driver was probed by the annoucement on channel rpmsg-tty / 0x401.

Did you manage to update to Linux 5.16 or are you still on 5.15 ?

If on 5.15, you probably don't have the rpmsg-tty driver but rather the imx_rpmsg_tty driver instead.
If that's the case, need to replace "rpmsg-tty" on the Zephyr side for the rpmsg endpoint name to the same as imx_rpmsg_tty driver instead "rpmsg-virtual-tty-channel".

See the endpoint names here:
https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/rpmsg/imx_rpmsg_tty.c#L211-L216

Change is done here:
https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c#L290

I haven't tested on kernel 5.15 and cannot test it for you.

Make sure you also enable the LOGGING framework in Zephyr to see all the messages coming on the M4 side as it doesn't use PRINTK the print statements in openamp_rsc_table example.

@neuberfran
Copy link
Author

neuberfran commented May 6, 2024

@jlh-makeen

Yes, I use kernel 5.16 now,
Yes, I have /dev/ttyRPMSG now

So I'm trying two approaches:

  1. First with your PR-71684 in order to have the zephyr.elf file place the rom_start region

In this case the resulting zephyr.bin became very large (511m) (i don't know why).

1,1) I even tried to approach your approach (that is, using PR) and uploading zephyr.elf only in sysfs (echo start) in Userspace, but I got error -62 and I can't upload rproc that way, unfortunately.

  1. In the second approach, I got a smaller zephyr.bin and had better success (as shown in the print screen in the last post)

I could be wrong, but this concludes that I have to use zephyr.bin(Uboot starts) and zephyr.elf(rproc starts) in this project on a mandatory basis. Otherwise I may have error -62

Now comes the issue that Linux (TX part of Linux) is not sending messages (**RPMsg/OpenAMP messages) to the Zephyr

** You can see in the window on the right side of the last photo (print screen) I posted that (despite CONFIG_PRINTK=n and CONFIG_LOG_PRINTK=n) some messages already arrive in m4, but not the main ones about RPMsg and OpenAMP, type test in echo "test" > /dev/ttyRPMSG0

What I've already tried to resolve:

  1. Change CONFIG_PRINTK=n and CONFIG_LOG_PRINTK=n to CONFIG_PRINTK=y and CONFIG_LOG_PRINTK=y (Not solved)
  2. Change vdev0vring0 and vdev0vring1 to vdevvring0 and vdevvring1, in Linux DT (Not solved)
  3. Number of buffers 32
printk("\r\nOpenAMP[remote] Linux tty ccc1.2 started\r\n");            

        if (tty_msg.len) {
            LOG_INF("ipc_service_open_instance() 14 failure");
            snprintk(tx_buff, 13, "TTY 0x%04x: ", tty_ept.addr);
            memcpy(&tx_buff[12], tty_msg.data, tty_msg.len);
            LOG_INF("ipc_service_open_instance() 15 failure");
            rpmsg_send(&tty_ept, tx_buff, tty_msg.len + 13);
            rpmsg_release_rx_buffer(&tty_ept, tty_msg.data);
            LOG_INF("ipc_service_open_instance() 16 failure");
        }
        printk("\r\nOpenAMP[remote] Linux tty ccc3 started\r\n"); 
OpenAMP[remote] Linux sample client ccc10 started                               
OpenAMP Linux sample client responder ended                                     
                                                                                
OpenAMP[remote] Linux task ccc21 started                                        
                                                                                
OpenAMP[remote] Linux task ccc20 started                                        
                                                                                
OpenAMP[remote] Linux tty ccc1.2 started                                        
I: ipc_service_open_instance() 14 failure                                       
I: ipc_service_open_instance() 15 failure                                       
I: ipc_service_open_instance() 16 failure                                       
                                                                                
OpenAMP[remote] Linux tty ccc3 started                                          
                                                                                
OpenAMP[remote] Linux tty ccc1.1 started  

Please, give-me your main_remote.c and your prj.conf generic and your_board.conf

@jlh-makeen
Copy link
Contributor

jlh-makeen commented May 7, 2024

@neuberfran

Let me try to be as clear as possible.

We have a custom carrier board using the cl-som-imx7d from Compulab so some changes might not be necessary on your board:

~/zephyrproject/zephyr/boards/makeen$ tree
.
├── index.rst
└── makeen_gw
    ├── board.yml
    ├── doc
    │   ├── dw_makeen_imx7d_m4.png
    │   └── index.rst
    ├── Kconfig.defconfig
    ├── Kconfig.makeen_gw
    ├── makeen_gw_mcimx7d_m4_defconfig
    ├── makeen_gw_mcimx7d_m4.dts
    ├── makeen_gw-pinctrl.dtsi
    └── makeen_gw.yaml

2 directories, 10 files

~/zephyrproject/zephyr/boards/makeen$ cat makeen_gw/makeen_gw_mcimx7d_m4_defconfig 
#
# Copyright (c) 2024, MAKEEN Energy
#
# SPDX-License-Identifier: Apache-2.0
#

CONFIG_UART_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE=y
CONFIG_XIP=y
CONFIG_PINCTRL=y
CONFIG_GPIO_HOGS=y

In the Zephyr DT I have &mub set to status = "okay"

Regarding the project I can build the native example from samples/subsys/ipc/openamp_rsc_table using this board config:

Create boards/makeen_gw_mcimx7d_m4.conf in samples/subsys/ipc/openamp_rsc_table:

CONFIG_IPM=y
CONFIG_IPM_IMX_MAX_DATA_SIZE_4=y
CONFIG_OPENAMP_WITH_DCACHE=y
CONFIG_PLATFORM_SPECIFIC_INIT=n
CONFIG_OPENAMP=y
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=32
CONFIG_OPENAMP_RSC_TABLE=y
CONFIG_OPENAMP_MASTER=n

Before Building you must use my ROMSTART_REGION relocation PR in order to have the correct boot-vector placement for Linux RPROC. You don't need the BIN files anymore, only ELF file.

Then on your Linux board create the following boot_m4.sh script:

#!/bin/bash

fw=$1

cp $fw /lib/firmware

echo stop > /sys/class/remoteproc/remoteproc0/state
echo $fw > /sys/class/remoteproc/remoteproc0/firmware
echo start > /sys/class/remoteproc/remoteproc0/state

Don't forget to chmod +x boot_m4.sh

Build :

cd ~/zephyrproject/zephyr/samples/subsys/ipc/openamp_rsc_table
west build -p always -b makeen_gw/mcimx7d/m4

Then SCP the zephyr_openamp_rsc_table.elf file and boot_m4.sh to your home directory of the linux board:

Then call the script:

su root
./boot_m4.sh zephyr_openamp_rsc_table.elf && dmesg

It should output the following:

[ 1529.626593] remoteproc remoteproc0: stopped remote processor imx-rproc
[ 1529.637142] remoteproc remoteproc0: powering up imx-rproc
[ 1529.645231] remoteproc remoteproc0: Booting fw image zephyr_openamp_rsc_table.elf, size 1282424
[ 1529.661279]  remoteproc0#vdev0buffer: assigned reserved memory node vdev0buffer0@bfff2000
[ 1529.718327] virtio_rpmsg_bus virtio0: rpmsg host is online
[ 1529.718981] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty addr 0x400
[ 1529.722666]  remoteproc0#vdev0buffer: registered virtio0 (type 7)
[ 1529.730217] virtio_rpmsg_bus virtio0: creating channel rpmsg-client-sample addr 0x401
[ 1529.741235] virtio_rpmsg_bus virtio0: creating channel rpmsg-tty addr 0x402
[ 1529.741946] remoteproc remoteproc0: remote processor imx-rproc is now up

Now I have 2 /dev/ttyRPMSG0 and /dev/ttyRPMSG1 showing up if you are using the latest openamp_rsc_table sample that enables the SHELL and SHELL_RPMSG_BACKEND.

To use the shell you can use your TTY terminal of choice like minicom:

su root
minicom -D /dev/ttyRPMSG0

Then press CTRL+C a few times to trigger the shell prompt:
You should see ipc:~$, then you can type kernel version to see that you are currently running Zephyr on the M4 !

Welcome to minicom 2.8

OPTIONS: I18n
Compiled on Jan  1 2021, 17:45:55.
Port /dev/ttyRPMSG0, 06:09:54

Press CTRL-A Z for help on special keys



ipc:~$ kernel version
Zephyr version 3.6.99
ipc:~$

You can also use /dev/ttyRPMSG1 to see the regular TTY echo of the sample when you send data to the tty

Welcome to minicom 2.8

OPTIONS: I18n
Compiled on Jan  1 2021, 17:45:55.
Port /dev/ttyRPMSG1, 06:10:44

Press CTRL-A Z for help on special keys

TTY 0x0402: eTTY 0x0402: eTTY 0x0402: eTTY 0x0402: e

Be aware that the sample uses approximately 48kB of CODE memory so I think you must run the code from OCRAM, but RAM usage is approx 20kB and can fit on any of TCM/OCRAM_S/DDR

[171/171] Linking C executable zephyr/zephyr_openamp_rsc_table.elf
Memory region         Used Size  Region Size  %age Used
 ROMSTART_REGION:         572 B         1 KB     55.86%
           FLASH:       48304 B       128 KB     36.85%

I hope this helps.

@neuberfran
Copy link
Author

neuberfran commented May 7, 2024

@jlh-makeen Tks. But I don't want open /dev/ttyRPMSG0 in minicom or picocom. I want:

  1. open Linux a7 side in picocom usb0
  2. open Zephyr m4 side in minicom usb1
  3. Execute rproc sysfs in linux and in linux -> echo "test" > /dev/ttyRPMSG0.
  4. At that moment I would see the word test next to the Zephyr (in usb1 minicom window)
    Note: 1) All that remains to be done is resolve this issue at the moment 4)
  5. I try LOG_INF("TTY 0x%04x: ", tty_ept.addr); Result is: TTY 0x401
  6. Nothing to tty_ept.addr, Why
if (tty_msg.len) {
            LOG_INF("ipc_service_open_instance() 14 failure");
            snprintf(tx_buff, 13, "TTY 0x%04x: ", tty_ept.addr);
            memcpy(&tx_buff[12], tty_msg.data, tty_msg.len);
            LOG_INF("ipc_service_open_instance() 15 failure");
            rpmsg_send(&tty_ept, tx_buff, tty_msg.len + 13);
            rpmsg_release_rx_buffer(&tty_ept, tty_msg.data);
            LOG_INF("ipc_service_open_instance() 16 failure");
        }

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.3/zephyr/samples/subsys/ipc/openamp_rsc_table/README.html

Screenshot from 2024-05-07 14-20-52

@jlh-makeen
Copy link
Contributor

@jlh-makeen Tks. But I don't want open /dev/ttyRPMSG0 in minicom or picocom. I want:

  1. open Linux a7 side in picocom usb0
  2. open Zephyr m4 side in minicom usb1
  3. Execute rproc sysfs in linux and in linux -> echo "test" > /dev/ttyRPMSG0.
  4. At that moment I would see the word test next to the Zephyr (in usb1 minicom window)
    Note: 1) All that remains to be done is resolve this issue at the moment 4)
  5. I try LOG_INF("TTY 0x%04x: ", tty_ept.addr); Result is: TTY 0x401
  6. Nothing to tty_ept.addr, Why
if (tty_msg.len) {
            LOG_INF("ipc_service_open_instance() 14 failure");
            snprintf(tx_buff, 13, "TTY 0x%04x: ", tty_ept.addr);
            memcpy(&tx_buff[12], tty_msg.data, tty_msg.len);
            LOG_INF("ipc_service_open_instance() 15 failure");
            rpmsg_send(&tty_ept, tx_buff, tty_msg.len + 13);
            rpmsg_release_rx_buffer(&tty_ept, tty_msg.data);
            LOG_INF("ipc_service_open_instance() 16 failure");
        }

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.3/zephyr/samples/subsys/ipc/openamp_rsc_table/README.html

Screenshot from 2024-05-07 14-20-52

Congrats !
I can see in your screenshot here that the Zephyr TTY side has successfully received the message from the Linux and sent the Echo back to Linux ! See the TTY 0x0401: Hello Zephyr so it is working perfectly now !

You don't see anything from your LOG_INF because you have not enabled CONFIG_LOG=y.

Try to add a printk statement instead, like this:

if (tty_msg.len) {
  printk("Linux rx message %*.s\n", tty_msg.len, tty_msg.data);
  snprintf(tx_buff, 13, "TTY 0x%04x: ", tty_ept.addr);
  memcpy(&tx_buff[12], tty_msg.data, tty_msg.len);
  rpmsg_send(&tty_ept, tx_buff, tty_msg.len + 13);
  rpmsg_release_rx_buffer(&tty_ept, tty_msg.data);
}

When you receive a message from Linux, you'll the message content appear in the Zephyr console.

Now it is implementation details you will have to care about by yourself, now that /dev/ttyRPMSG shows in Linux and the RPMSG sample works on your platform I think we should close the issue as it's resolved.

If you encounter application specific requests, feel free to report to the documentation or open a new issue for the new subject.

@neuberfran
Copy link
Author

neuberfran commented May 7, 2024

@jlh-makeen Unfortunately, I still couldn't get echo test > /dev/ttyRPMSG0 to appear in the other window

I am one of the first interested parties to close this topic.

I thought that adding the printk you suggested would solve it (it was the only thing I hadn't tried yet). But unfortunately not yet

Screenshot from 2024-05-07 15-37-02

if (tty_msg.len) {
            printk("Linux rx message %*.s\n", tty_msg.len, tty_msg.data);
            LOG_INF("ipc_service_open_instance() 14 failure");
            snprintf(tx_buff, 13, "TTY 0x%04x: ", tty_ept.addr);
            memcpy(&tx_buff[12], tty_msg.data, tty_msg.len);
            LOG_INF("ipc_service_open_instance() 15 failure");
            rpmsg_send(&tty_ept, tx_buff, tty_msg.len + 13);
            rpmsg_release_rx_buffer(&tty_ept, tty_msg.data);
            LOG_INF("ipc_service_open_instance() 16 failure");
        }

prj.conf


CONFIG_KERNEL_BIN_NAME="zephyr_openamp_rsc_table"
CONFIG_PRINTK=y
CONFIG_LOG=y 
CONFIG_LOG_DEFAULT_LEVEL=0
CONFIG_LOG_MODE_MINIMAL=y
CONFIG_IPM=y
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_OPENAMP=y
CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF=32
CONFIG_OPENAMP_RSC_TABLE=y
CONFIG_OPENAMP_MASTER=n
CONFIG_PLATFORM_SPECIFIC_INIT=n
#CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# CONFIG_LOG=y
# CONFIG_LOG_BACKEND_UART=y
# CONFIG_SERIAL=y

# CONFIG_IPC_SERVICE=ys
# CONFIG_PRINTK=y 
# CONFIG_LOG=y # required to allocate virtqueues 
# #CONFIG_HEAP_MEM_POOL_SIZE=2048
# CONFIG_IPC_SERVICE_LOG_LEVEL_INF=y 

pico_pi_m4.conf

CONFIG_UART_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE=y
CONFIG_LOG_PRINTK=y
CONFIG_IPM_IMX_MAX_DATA_SIZE_16=n
CONFIG_IPM_IMX_MAX_DATA_SIZE_4=y
CONFIG_OPENAMP_WITH_DCACHE=y

# CONFIG_IPM=y--> Interrupt-based inter-processor mailboxes
# CONFIG_IPM_IMX=y--> Your IPM driver here for Renesas R-Car
# CONFIG_OPENAMP=y--> Enable OpenAMP IPC library
# CONFIG_OPENAMP_SLAVE=y --> Virtqueue are initialized by the host (Linux)
# CONFIG_OPENAMP_RSC_TABLE=y

This is Correct Result When Everything Works Ok

5.2 openamp_rsc_table application in Page=12

AN13970.pdf

@neuberfran
Copy link
Author

neuberfran commented May 7, 2024

@jlh-makeen

Pls
Can you perform these procedures below?

  1. open Linux a7 side in picocom usb0
  2. open Zephyr m4 side in minicom usb1
  3. Execute rproc sysfs in linux and in linux write echo "test" > /dev/ttyRPMSG0.
  4. Please let me know if you can see the message test or openamp_rsc_table: platform_ipm_callback:
    platform_ipm_callback: msg received from mb 0
    in m4 side window

@jlh-makeen
Copy link
Contributor

It is weird that printk doesn't display the message can you print the size of the message too ?

printk("Linux rx message [%d] %*.s\n", tty_msg.len, tty_msg.len, tty_msg.data);

@neuberfran
Copy link
Author

@jlh-makeen

Linux rx message [5]

Screenshot from 2024-05-08 08-42-32

@neuberfran
Copy link
Author

@jlh-makeen???????

@jlh-makeen
Copy link
Contributor

@jlh-makeen

Linux rx message [5]

Screenshot from 2024-05-08 08-42-32

You succesfully received the "test\n" string so it is working, the length of the message is 5 :)

You don't see the message because I made a mistake with the printk:
I swapped the .* in the printk statement.
printk("Linux rx message [%d] %.*s\n", tty_msg.len, tty_msg.len, tty_msg.data);

See the test here:
image

@neuberfran
Copy link
Author

neuberfran commented May 11, 2024

@jlh-makeen Tks. With printk("Linux rx message [%d] %.*s\n", tty_msg.len, tty_msg.len, tty_msg.data); (Without mistakes) I have sucess

Other things I changed (in main remote.c) to have the messages shown in the screenshot below:

  1. LOG_MODULE_REGISTER(openamp_rsc_table, LOG_LEVEL_DBG); to LOG_MODULE_REGISTER(openamp_rsc_table, LOG_LEVEL_INF);

  2. All LOG_DBG from main_remote.c to LOG_INF

  3. Now I have I: mailbox_notify: msg received and I: platform_ipm_callback: msg received from mb 0 and I: mailbox_notify: msg received

Screenshot from 2024-05-11 16-42-45

@neuberfran
Copy link
Author

https://www.youtube.com/watch?v=V06RC2G_3M8

@jlh-makeen
Copy link
Contributor

https://www.youtube.com/watch?v=V06RC2G_3M8

Excellent, here we are finally 👍

Regarding the LOG framework, the default level is INF that's why you had to change the module default level, but you could also have changed the default log level in prj.conf:

#set default level to 4
CONFIG_LOG_DEFAULT_LEVEL=4

Refer to the logging doc:
https://docs.zephyrproject.org/latest/services/logging/index.html
https://docs.zephyrproject.org/latest/kconfig.html#CONFIG_LOG_DEFAULT_LEVEL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: AMP Asymmetric Multi-processing (AMP) bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

5 participants