Lines Matching +full:class +full:- +full:d
1 // SPDX-License-Identifier: GPL-2.0-only
8 * Ohad Ben-Cohen <ohad@wizery.com>
12 * Suman Anna <s-anna@ti.com>
29 * rproc_elf_sanity_check() - Sanity Check for ELF32/ELF64 firmware image
37 const char *name = rproc->firmware;
38 struct device *dev = &rproc->dev;
47 char class; local
52 return -EINVAL;
55 if (fw->size < sizeof(struct elf32_hdr)) {
57 return -EINVAL;
60 ehdr = (struct elf32_hdr *)fw->data;
62 if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG)) {
64 return -EINVAL;
67 class = ehdr->e_ident[EI_CLASS];
68 if (class != ELFCLASS32 && class != ELFCLASS64) {
69 dev_err(dev, "Unsupported class: %d\n", class);
70 return -EINVAL;
73 if (class == ELFCLASS64 && fw->size < sizeof(struct elf64_hdr)) {
75 return -EINVAL;
80 if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) {
82 if (ehdr->e_ident[EI_DATA] != ELFDATA2MSB) {
85 return -EINVAL;
88 phoff = elf_hdr_get_e_phoff(class, fw->data);
89 shoff = elf_hdr_get_e_shoff(class, fw->data);
90 phnum = elf_hdr_get_e_phnum(class, fw->data);
91 elf_shdr_get_size = elf_size_of_shdr(class);
93 if (fw->size < shoff + elf_shdr_get_size) {
95 return -EINVAL;
100 return -EINVAL;
103 if (phoff > fw->size) {
105 return -EINVAL;
108 dev_dbg(dev, "Firmware is an elf%d file\n",
109 class == ELFCLASS32 ? 32 : 64);
116 * rproc_elf_get_boot_addr() - Get rproc's boot address.
124 * processors. Some will always boot at a specific hard-coded address.
128 return elf_hdr_get_e_entry(fw_elf_get_class(fw), fw->data);
133 * rproc_elf_load_segments() - load firmware segments to memory
158 struct device *dev = &rproc->dev;
162 const u8 *elf_data = fw->data;
163 u8 class = fw_elf_get_class(fw); local
164 u32 elf_phdr_get_size = elf_size_of_phdr(class);
167 phnum = elf_hdr_get_e_phnum(class, ehdr);
168 phdr = elf_data + elf_hdr_get_e_phoff(class, ehdr);
172 u64 da = elf_phdr_get_p_paddr(class, phdr);
173 u64 memsz = elf_phdr_get_p_memsz(class, phdr);
174 u64 filesz = elf_phdr_get_p_filesz(class, phdr);
175 u64 offset = elf_phdr_get_p_offset(class, phdr);
176 u32 type = elf_phdr_get_p_type(class, phdr);
182 dev_dbg(dev, "phdr: type %d da 0x%llx memsz 0x%llx filesz 0x%llx\n",
188 ret = -EINVAL;
192 if (offset + filesz > fw->size) {
194 offset + filesz, fw->size);
195 ret = -EINVAL;
202 ret = -EOVERFLOW;
211 ret = -EINVAL;
227 memset(ptr + filesz, 0, memsz - filesz);
241 const u8 *elf_data = (void *)fw->data;
242 u8 class = fw_elf_get_class(fw); local
243 size_t fw_size = fw->size;
245 u16 shnum = elf_hdr_get_e_shnum(class, ehdr);
246 u32 elf_shdr_get_size = elf_size_of_shdr(class);
247 u16 shstrndx = elf_hdr_get_e_shstrndx(class, ehdr);
250 /* First, get the section header according to the elf class */
251 shdr = elf_data + elf_hdr_get_e_shoff(class, ehdr);
255 name_table = elf_data + elf_shdr_get_sh_offset(class, name_table_shdr);
258 u64 size = elf_shdr_get_sh_size(class, shdr);
259 u64 offset = elf_shdr_get_sh_offset(class, shdr);
260 u32 name = elf_shdr_get_sh_name(class, shdr);
275 dev_err(dev, "header-less resource table\n");
280 if (table->ver != 1) {
281 dev_err(dev, "unsupported fw ver: %d\n", table->ver);
286 if (table->reserved[0] || table->reserved[1]) {
292 if (struct_size(table, offset, table->num) > size) {
304 * rproc_elf_load_rsc_table() - load the resource table
316 struct device *dev = &rproc->dev;
318 const u8 *elf_data = fw->data;
320 u8 class = fw_elf_get_class(fw); local
325 return -EINVAL;
327 sh_offset = elf_shdr_get_sh_offset(class, shdr);
329 tablesz = elf_shdr_get_sh_size(class, shdr);
337 rproc->cached_table = kmemdup(table, tablesz, GFP_KERNEL);
338 if (!rproc->cached_table)
339 return -ENOMEM;
341 rproc->table_ptr = rproc->cached_table;
342 rproc->table_sz = tablesz;
349 * rproc_elf_find_loaded_rsc_table() - find the loaded resource table
354 * call this function if the table wasn't loaded yet - it's a bug if you do.
364 u8 class = fw_elf_get_class(fw); local
365 struct device *dev = &rproc->dev;
367 shdr = find_table(&rproc->dev, fw);
371 sh_addr = elf_shdr_get_sh_addr(class, shdr);
372 sh_size = elf_shdr_get_sh_size(class, shdr);