1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments Incorporated - http://www.ti.com/
10 #include <remoteproc.h>
15 * dm_test_remoteproc_base() - test the operations after initializations
16 * @uts: unit test state
18 * Return: 0 if test passed, else error
20 static int dm_test_remoteproc_base(struct unit_test_state *uts)
22 if (!rproc_is_initialized())
23 ut_assertok(rproc_init());
25 /* Ensure we are initialized */
26 ut_asserteq(true, rproc_is_initialized());
29 /* platform data device 1 */
30 ut_assertok(rproc_stop(0));
31 ut_assertok(rproc_reset(0));
32 /* -> invalid attempt tests */
33 ut_asserteq(-EINVAL, rproc_start(0));
34 ut_asserteq(-EINVAL, rproc_ping(0));
36 ut_assertok(rproc_load(0, 1, 0));
37 ut_assertok(rproc_start(0));
38 ut_assertok(rproc_is_running(0));
39 ut_assertok(rproc_ping(0));
40 ut_assertok(rproc_reset(0));
41 ut_assertok(rproc_stop(0));
43 /* dt device device 1 */
44 ut_assertok(rproc_stop(1));
45 ut_assertok(rproc_reset(1));
46 ut_assertok(rproc_load(1, 1, 0));
47 ut_assertok(rproc_start(1));
48 ut_assertok(rproc_is_running(1));
49 ut_assertok(rproc_ping(1));
50 ut_assertok(rproc_reset(1));
51 ut_assertok(rproc_stop(1));
53 /* dt device device 2 */
54 ut_assertok(rproc_stop(0));
55 ut_assertok(rproc_reset(0));
56 /* -> invalid attempt tests */
57 ut_asserteq(-EINVAL, rproc_start(0));
58 ut_asserteq(-EINVAL, rproc_ping(0));
60 ut_assertok(rproc_load(2, 1, 0));
61 ut_assertok(rproc_start(2));
62 ut_assertok(rproc_is_running(2));
63 ut_assertok(rproc_ping(2));
64 ut_assertok(rproc_reset(2));
65 ut_assertok(rproc_stop(2));
69 DM_TEST(dm_test_remoteproc_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
71 #define DEVICE_TO_PHYSICAL_OFFSET 0x1000
73 * dm_test_remoteproc_elf() - test the ELF operations
74 * @uts: unit test state
76 * Return: 0 if test passed, else error
78 static int dm_test_remoteproc_elf(struct unit_test_state *uts)
81 /* @0x00 - ELF HEADER - */
83 0x7f, 0x45, 0x4c, 0x46,
87 #ifdef __LITTLE_ENDIAN
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 /* Type : executable */
101 0x01, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x08,
104 /* phoff (program header offset @ 0x40)*/
105 0x40, 0x00, 0x00, 0x00,
106 /* shoff (section header offset : none) */
107 0x00, 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00, 0x00,
110 /* ehsize (elf header size = 0x34) */
112 /* phentsize (program header size = 0x20) */
114 /* phnum (program header number : 1) */
116 /* shentsize (section heade size : none) */
118 /* shnum (section header number: none) */
120 /* shstrndx (section header name section index: none) */
123 0x00, 0x00, 0x00, 0x00,
124 0x00, 0x00, 0x00, 0x00,
125 0x00, 0x00, 0x00, 0x00,
126 /* @0x40 - PROGRAM HEADER TABLE - */
128 0x01, 0x00, 0x00, 0x00,
130 0x00, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00,
133 /* paddr : physical address */
134 0x00, 0x00, 0x00, 0x00,
135 /* filesz : 0x20 bytes (program header size) */
136 0x20, 0x00, 0x00, 0x00,
138 0x20, 0x00, 0x00, 0x00,
139 /* flags : readable and exectuable */
140 0x05, 0x00, 0x00, 0x00,
142 0x00, 0x00, 0x00, 0x00,
144 unsigned int size = ARRAY_SIZE(valid_elf32);
146 phys_addr_t loaded_firmware_paddr;
147 void *loaded_firmware;
148 u32 loaded_firmware_size;
149 Elf32_Ehdr *ehdr = (Elf32_Ehdr *)valid_elf32;
150 Elf32_Phdr *phdr = (Elf32_Phdr *)(valid_elf32 + ehdr->e_phoff);
152 ut_assertok(uclass_get_device(UCLASS_REMOTEPROC, 0, &dev));
155 * In its Program Header Table, let the firmware specifies to be loaded
156 * at SDRAM_BASE *device* address (p_paddr field).
157 * Its size is defined by the p_filesz field.
159 phdr->p_paddr = CONFIG_SYS_SDRAM_BASE;
160 loaded_firmware_size = phdr->p_filesz;
163 * This *device* address is converted to a *physical* address by the
164 * device_to_virt() operation of sandbox_test_rproc which returns
165 * DeviceAddress + DEVICE_TO_PHYSICAL_OFFSET.
166 * This is where we expect to get the firmware loaded.
168 loaded_firmware_paddr = phdr->p_paddr + DEVICE_TO_PHYSICAL_OFFSET;
169 loaded_firmware = map_physmem(loaded_firmware_paddr,
170 loaded_firmware_size, MAP_NOCACHE);
171 ut_assertnonnull(loaded_firmware);
172 memset(loaded_firmware, 0, loaded_firmware_size);
174 /* Load firmware in loaded_firmware, and verify it */
175 ut_assertok(rproc_elf32_load_image(dev, (ulong)valid_elf32, size));
176 ut_assertok(memcmp(loaded_firmware, valid_elf32, loaded_firmware_size));
177 ut_asserteq(rproc_elf_get_boot_addr(dev, (unsigned long)valid_elf32),
179 unmap_physmem(loaded_firmware, MAP_NOCACHE);
181 /* Invalid ELF Magic */
183 ut_asserteq(-EPROTONOSUPPORT,
184 rproc_elf32_sanity_check((ulong)valid_elf32, size));
188 DM_TEST(dm_test_remoteproc_elf, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);