aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSjur Brændeland <sjur.brandeland@stericsson.com>2013-02-21 12:15:33 -0500
committerOhad Ben-Cohen <ohad@wizery.com>2013-04-05 01:49:44 -0400
commitf665b2cd3f569a353c0a62b03a95827dd8743e9b (patch)
treea7b6577f28d6a8af3170c82f96936c9069b15c67
parentf6161aa153581da4a3867a2d1a7caf4be19b6ec9 (diff)
remoteproc: refactor rproc_elf_find_rsc_table()
Refactor rproc_elf_find_rsc_table() and split out the scanning for the section header named resource table. This is done to prepare for loading firmware once. Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com> Acked-by: Ido Yariv <ido@wizery.com> [small function name change to make the code easier to read] Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
-rw-r--r--drivers/remoteproc/remoteproc_elf_loader.c75
1 files changed, 46 insertions, 29 deletions
diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c
index 0d36f94ab51d..774e5f768bf3 100644
--- a/drivers/remoteproc/remoteproc_elf_loader.c
+++ b/drivers/remoteproc/remoteproc_elf_loader.c
@@ -208,41 +208,22 @@ rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
208 return ret; 208 return ret;
209} 209}
210 210
211/** 211static struct elf32_shdr *
212 * rproc_elf_find_rsc_table() - find the resource table 212find_table(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size)
213 * @rproc: the rproc handle
214 * @fw: the ELF firmware image
215 * @tablesz: place holder for providing back the table size
216 *
217 * This function finds the resource table inside the remote processor's
218 * firmware. It is used both upon the registration of @rproc (in order
219 * to look for and register the supported virito devices), and when the
220 * @rproc is booted.
221 *
222 * Returns the pointer to the resource table if it is found, and write its
223 * size into @tablesz. If a valid table isn't found, NULL is returned
224 * (and @tablesz isn't set).
225 */
226static struct resource_table *
227rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
228 int *tablesz)
229{ 213{
230 struct elf32_hdr *ehdr;
231 struct elf32_shdr *shdr; 214 struct elf32_shdr *shdr;
215 int i;
232 const char *name_table; 216 const char *name_table;
233 struct device *dev = &rproc->dev;
234 struct resource_table *table = NULL; 217 struct resource_table *table = NULL;
235 int i; 218 const u8 *elf_data = (void *)ehdr;
236 const u8 *elf_data = fw->data;
237 219
238 ehdr = (struct elf32_hdr *)elf_data; 220 /* look for the resource table and handle it */
239 shdr = (struct elf32_shdr *)(elf_data + ehdr->e_shoff); 221 shdr = (struct elf32_shdr *)(elf_data + ehdr->e_shoff);
240 name_table = elf_data + shdr[ehdr->e_shstrndx].sh_offset; 222 name_table = elf_data + shdr[ehdr->e_shstrndx].sh_offset;
241 223
242 /* look for the resource table and handle it */
243 for (i = 0; i < ehdr->e_shnum; i++, shdr++) { 224 for (i = 0; i < ehdr->e_shnum; i++, shdr++) {
244 int size = shdr->sh_size; 225 u32 size = shdr->sh_size;
245 int offset = shdr->sh_offset; 226 u32 offset = shdr->sh_offset;
246 227
247 if (strcmp(name_table + shdr->sh_name, ".resource_table")) 228 if (strcmp(name_table + shdr->sh_name, ".resource_table"))
248 continue; 229 continue;
@@ -250,7 +231,7 @@ rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
250 table = (struct resource_table *)(elf_data + offset); 231 table = (struct resource_table *)(elf_data + offset);
251 232
252 /* make sure we have the entire table */ 233 /* make sure we have the entire table */
253 if (offset + size > fw->size) { 234 if (offset + size > fw_size || offset + size < size) {
254 dev_err(dev, "resource table truncated\n"); 235 dev_err(dev, "resource table truncated\n");
255 return NULL; 236 return NULL;
256 } 237 }
@@ -280,10 +261,46 @@ rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
280 return NULL; 261 return NULL;
281 } 262 }
282 263
283 *tablesz = shdr->sh_size; 264 return shdr;
284 break;
285 } 265 }
286 266
267 return NULL;
268}
269
270/**
271 * rproc_elf_find_rsc_table() - find the resource table
272 * @rproc: the rproc handle
273 * @fw: the ELF firmware image
274 * @tablesz: place holder for providing back the table size
275 *
276 * This function finds the resource table inside the remote processor's
277 * firmware. It is used both upon the registration of @rproc (in order
278 * to look for and register the supported virito devices), and when the
279 * @rproc is booted.
280 *
281 * Returns the pointer to the resource table if it is found, and write its
282 * size into @tablesz. If a valid table isn't found, NULL is returned
283 * (and @tablesz isn't set).
284 */
285static struct resource_table *
286rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
287 int *tablesz)
288{
289 struct elf32_hdr *ehdr;
290 struct elf32_shdr *shdr;
291 struct device *dev = &rproc->dev;
292 struct resource_table *table = NULL;
293 const u8 *elf_data = fw->data;
294
295 ehdr = (struct elf32_hdr *)elf_data;
296
297 shdr = find_table(dev, ehdr, fw->size);
298 if (!shdr)
299 return NULL;
300
301 table = (struct resource_table *)(elf_data + shdr->sh_offset);
302 *tablesz = shdr->sh_size;
303
287 return table; 304 return table;
288} 305}
289 306