26 #define pr_fmt(fmt) "%s: " fmt, __func__
28 #include <linux/module.h>
31 #include <linux/elf.h>
51 dev_err(dev,
"failed to load %s\n", name);
56 dev_err(dev,
"Image is too small\n");
65 dev_err(dev,
"Unsupported class: %d\n",
class);
70 # ifdef __LITTLE_ENDIAN
75 dev_err(dev,
"Unsupported firmware endianess\n");
80 dev_err(dev,
"Image is too small\n");
85 dev_err(dev,
"Image is corrupted (bad magic)\n");
90 dev_err(dev,
"No loadable segments\n");
95 dev_err(dev,
"Firmware size is too small\n");
114 u32 rproc_elf_get_boot_addr(
struct rproc *rproc,
const struct firmware *fw)
146 rproc_elf_load_segments(
struct rproc *rproc,
const struct firmware *fw)
152 const u8 *elf_data = fw->
data;
158 for (i = 0; i < ehdr->
e_phnum; i++, phdr++) {
168 dev_dbg(dev,
"phdr: type %d da 0x%x memsz 0x%x filesz 0x%x\n",
169 phdr->
p_type, da, memsz, filesz);
171 if (filesz > memsz) {
172 dev_err(dev,
"bad phdr filesz 0x%x memsz 0x%x\n",
178 if (offset + filesz > fw->
size) {
179 dev_err(dev,
"truncated fw: need 0x%x avail 0x%zx\n",
180 offset + filesz, fw->
size);
188 dev_err(dev,
"bad phdr da 0x%x mem 0x%x\n", da, memsz);
205 memset(ptr + filesz, 0, memsz - filesz);
227 rproc_elf_find_rsc_table(
struct rproc *rproc,
const struct firmware *fw,
236 const u8 *elf_data = fw->
data;
243 for (i = 0; i < ehdr->
e_shnum; i++, shdr++) {
253 if (offset + size > fw->
size) {
254 dev_err(dev,
"resource table truncated\n");
260 dev_err(dev,
"header-less resource table\n");
265 if (table->
ver != 1) {
266 dev_err(dev,
"unsupported fw ver: %d\n", table->
ver);
272 dev_err(dev,
"non zero reserved bytes\n");
277 if (table->
num *
sizeof(table->
offset[0]) +
279 dev_err(dev,
"resource table incomplete\n");
291 .load = rproc_elf_load_segments,
292 .find_rsc_table = rproc_elf_find_rsc_table,
293 .sanity_check = rproc_elf_sanity_check,
294 .get_boot_addr = rproc_elf_get_boot_addr