cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Participant
Participant
701 Views
Registered: ‎12-09-2019

How to edit lscript.ld and device tree for openamp application

Jump to solution

Hi.

   I am using z7035 board and petalinux 2018.2. I am using openamp for my application. I am able to run the demo applications for openamp. While merging my application and editing the BSP as per my needs i get an error " PS7_DDR_0_S_AXI_BASEADDRESS overflow.  "

lscript before editing is ,

ps7_ddr_0_s_axi_baseaddr : ORIGIN = 0x3e000000, LENGTH = 0x00400000
ps7_ram_0_s_axi_baseaddr : ORIGIN = 0x0, LENGTH = 0x00030000
ps7_ram_1_s_axi_baseaddr : ORIGIN = 0xFFFF0000, LENGTH = 0x0000FE00

So i increased the size in the lscript. 

lscript after editing is ,

ps7_ddr_0_s_axi_baseaddr : ORIGIN = 0x20000000, LENGTH = 0x08000000
ps7_ram_0_s_axi_baseaddr : ORIGIN = 0x0, LENGTH = 0x00030000
ps7_ram_1_s_axi_baseaddr : ORIGIN = 0xFFFF0000, LENGTH = 0x0000FE00

Then the project builds without an error. 

The rsc_table before editing is 

/* Resource table entries */
#define NUM_VRINGS                  0x02
#define VRING_ALIGN                 0x1000
#define RING_TX                     0x3e400000
#define RING_RX                     0x3e404000
#define VRING_SIZE                  256


/* Offsets of rsc entries */
	{
	 offsetof(struct remote_resource_table, rproc_mem),
	 offsetof(struct remote_resource_table, rpmsg_vdev),
	 },

	{RSC_RPROC_MEM, 0x3e400000, 0x3e400000, 0x100000, 0},

 

The device tree is given as 

/ {
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
rproc_0_reserved: rproc@3e000000 {
no-map;
reg = <0x3e000000 0x01000000>;
};
};
amba {
elf_ddr_0: ddr@0 {
compatible = "mmio-sram";
reg = <0x3e000000 0x400000>;
};
};
remoteproc0: remoteproc@0 {
compatible = "xlnx,zynq_remoteproc";
firmware = "firmware";
vring0 = <15>;
vring1 = <14>;
srams = <&elf_ddr_0>;
};
};

 

project is built and bootable. While loading the application an error comes. 

remoteproc remoteproc0: bad phdr da 0x3e100000 mem 0x1f97280
remoteproc remoteproc0: Failed to load program segments: -22
remoteproc remoteproc0: Boot failed: -22

 

I need to start from 0x20000000 and size as 0x0800000.

Can anyone help me in editing the parameters correctly. And it would be more helpful if someone explain the device tree node entries. 

 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Participant
Participant
616 Views
Registered: ‎12-09-2019

Hi,

We managed to find a solution for the scenario. For loading the elf file at a different location we had to make changes in our rsc_table.c, rsc_table.h, lscript.ld and device tree node of remoteproc. This is how we edited it.

My intention was to give more ddr_0 memory space from the remote program running in cpu1 so as i can increase the stack size in the project bsp. I needed to allocate at least 50MB for the remote program. So i decided to give last 50 MB of the ddr_0.  

In lscript. 

 

 

ps7_ddr_0_s_axi_baseaddr : ORIGIN = 0x3B600000, LENGTH = 0x03200000
ps7_ram_0_s_axi_baseaddr : ORIGIN = 0x0, LENGTH = 0x00030000
ps7_ram_1_s_axi_baseaddr : ORIGIN = 0xFFFF0000, LENGTH = 0x0000FE00

 

 

Starting from 0x3b6000000(950th MB) , 50MB (0x3200000) has to be allocated. 

In device tree node :

 

/ {
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
rproc_0_reserved: rproc@3B600000 {
no-map;
reg = <0x3B600000 0x03200000>;
};
};
amba {
elf_ddr_0: ddr@0 {
compatible = "mmio-sram";
reg = <0x3B600000 0x03200000>;
};
};
remoteproc0: remoteproc@0 {
compatible = "xlnx,zynq_remoteproc";
firmware = "firmware";
vring0 = <15>;
vring1 = <14>;
srams = <&elf_ddr_0>;
};
};

 

While making this change in the device tree node Linux will get 974MB and the rest wont be accessed by Linux kernel.

There are some important changes that has to be done in rsc_table.c. 

 

/* Remote supports Name Service announcement */
#define VIRTIO_RPMSG_F_NS           0

#define NUM_VRINGS                  0x02
#define VRING_ALIGN                 0x1000
#define RING_TX                     0x3B600000
#define RING_RX                     0x3B604000
#define VRING_SIZE                  256

 

In the remote_resource_table  structure 

 

	/* Offsets of rsc entries */
	{
	 offsetof(struct remote_resource_table, elf),
	 offsetof(struct remote_resource_table, rpmsg_vdev),
	 },

	/* Virtio device entry */
	{
         RSC_CARVEOUT, 0x3B600000, 0x3B600000, 0x3200000, 0, 0, "elf", },
	 RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0,
	 NUM_VRINGS, {0, 0},
	 },

 

 

In file rsc_table.h we have to edit the structure remote_resource_table  

/* Resource table for the given remote */
struct remote_resource_table {
	unsigned int version;
	unsigned int num;
	unsigned int reserved[2];
	unsigned int offset[NO_RESOURCE_ENTRIES];
	
	 struct fw_rsc_carveout elf;
	struct fw_rsc_vdev_vring rpmsg_vring0;
	struct fw_rsc_vdev_vring rpmsg_vring1;
}__attribute__((packed, aligned(0x100000)));

 Done. Now the elf file loads without an error and application works. We tried to give 300 MB for remoteproc but at he load time DMA error was coming up. For 100 MB no error came and program was loading without DMA error. 

Thank you.

 

View solution in original post

2 Replies
Highlighted
Participant
Participant
664 Views
Registered: ‎12-09-2019

I changed the settings as. Now it now showing the error but the app is not loaded.

Changed settings.

lscript.ld

ps7_ddr_0_s_axi_baseaddr : ORIGIN = 0x3B600000, LENGTH = 0x03200000
ps7_ram_0_s_axi_baseaddr : ORIGIN = 0x0, LENGTH = 0x00030000
ps7_ram_1_s_axi_baseaddr : ORIGIN = 0xFFFF0000, LENGTH = 0x0000FE00

 

rsc_table.c

/* Resource table entries */
#define NUM_VRINGS                  0x02
#define VRING_ALIGN                 0x1000
#define RING_TX                     0x3B600000
#define RING_RX                     0x3B604000
#define VRING_SIZE                  256


/* Offsets of rsc entries */
	{
	 offsetof(struct remote_resource_table, rproc_mem),
	 offsetof(struct remote_resource_table, rpmsg_vdev),
	 },

	{RSC_RPROC_MEM, 0x3B600000, 0x3B600000, 0x03200000, 0},

 

device tree node :

/ {
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
rproc_0_reserved: rproc@3B600000 {
no-map;
reg = <0x3B600000 0x03200000>;
};
};
amba {
elf_ddr_0: ddr@0 {
compatible = "mmio-sram";
reg = <0x3B600000 0x03200000>;
};
};
remoteproc0: remoteproc@0 {
compatible = "xlnx,zynq_remoteproc";
firmware = "firmware";
vring0 = <15>;
vring1 = <14>;
srams = <&elf_ddr_0>;
};
};

 

Now the output is 

root@18_2:~#
root@18_2:~#  echo start > /sys/class/remoteproc/remoteproc0/state
remoteproc remoteproc0: powering up remoteproc@0
remoteproc remoteproc0: Booting fw image mtxapp.elf, size 1541064
virtio_rpmsg_bus virtio0: rpmsg host is online
remoteproc remoteproc0: registered virtio0 (type 7)
remoteproc remoteproc0: remote processor remoteproc@0 is now up

But the program doesn't run. 

Any idea??

regards ...

0 Kudos
Highlighted
Participant
Participant
617 Views
Registered: ‎12-09-2019

Hi,

We managed to find a solution for the scenario. For loading the elf file at a different location we had to make changes in our rsc_table.c, rsc_table.h, lscript.ld and device tree node of remoteproc. This is how we edited it.

My intention was to give more ddr_0 memory space from the remote program running in cpu1 so as i can increase the stack size in the project bsp. I needed to allocate at least 50MB for the remote program. So i decided to give last 50 MB of the ddr_0.  

In lscript. 

 

 

ps7_ddr_0_s_axi_baseaddr : ORIGIN = 0x3B600000, LENGTH = 0x03200000
ps7_ram_0_s_axi_baseaddr : ORIGIN = 0x0, LENGTH = 0x00030000
ps7_ram_1_s_axi_baseaddr : ORIGIN = 0xFFFF0000, LENGTH = 0x0000FE00

 

 

Starting from 0x3b6000000(950th MB) , 50MB (0x3200000) has to be allocated. 

In device tree node :

 

/ {
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
rproc_0_reserved: rproc@3B600000 {
no-map;
reg = <0x3B600000 0x03200000>;
};
};
amba {
elf_ddr_0: ddr@0 {
compatible = "mmio-sram";
reg = <0x3B600000 0x03200000>;
};
};
remoteproc0: remoteproc@0 {
compatible = "xlnx,zynq_remoteproc";
firmware = "firmware";
vring0 = <15>;
vring1 = <14>;
srams = <&elf_ddr_0>;
};
};

 

While making this change in the device tree node Linux will get 974MB and the rest wont be accessed by Linux kernel.

There are some important changes that has to be done in rsc_table.c. 

 

/* Remote supports Name Service announcement */
#define VIRTIO_RPMSG_F_NS           0

#define NUM_VRINGS                  0x02
#define VRING_ALIGN                 0x1000
#define RING_TX                     0x3B600000
#define RING_RX                     0x3B604000
#define VRING_SIZE                  256

 

In the remote_resource_table  structure 

 

	/* Offsets of rsc entries */
	{
	 offsetof(struct remote_resource_table, elf),
	 offsetof(struct remote_resource_table, rpmsg_vdev),
	 },

	/* Virtio device entry */
	{
         RSC_CARVEOUT, 0x3B600000, 0x3B600000, 0x3200000, 0, 0, "elf", },
	 RSC_VDEV, VIRTIO_ID_RPMSG_, 0, RPMSG_IPU_C0_FEATURES, 0, 0, 0,
	 NUM_VRINGS, {0, 0},
	 },

 

 

In file rsc_table.h we have to edit the structure remote_resource_table  

/* Resource table for the given remote */
struct remote_resource_table {
	unsigned int version;
	unsigned int num;
	unsigned int reserved[2];
	unsigned int offset[NO_RESOURCE_ENTRIES];
	
	 struct fw_rsc_carveout elf;
	struct fw_rsc_vdev_vring rpmsg_vring0;
	struct fw_rsc_vdev_vring rpmsg_vring1;
}__attribute__((packed, aligned(0x100000)));

 Done. Now the elf file loads without an error and application works. We tried to give 300 MB for remoteproc but at he load time DMA error was coming up. For 100 MB no error came and program was loading without DMA error. 

Thank you.

 

View solution in original post