MCPcopy Create free account
hub / github.com/apache/nuttx / create_image

Function create_image

tools/cxd56/mkspk.c:224–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222}
223
224static void *create_image(struct elf_file *elf, int core, char *savename,
225 int *image_size)
226{
227 char *img;
228 struct spk_header *header;
229 struct spk_prog_info *pi;
230 Elf32_Phdr *ph;
231 Elf32_Sym *sym;
232 char *name;
233 int snlen;
234 int nphs;
235 int psize;
236 int imgsize;
237 int i;
238 int j;
239 uint32_t offset;
240 uint32_t sp;
241
242 snlen = alignup(strlen(savename) + 1, 16);
243
244 nphs = 0;
245 psize = 0;
246 for (i = 0, ph = elf->phdr; i < elf->ehdr->e_phnum; i++, ph++)
247 {
248 if (ph->p_type != PT_LOAD || ph->p_memsz == 0)
249 {
250 continue;
251 }
252
253 nphs++;
254 psize += alignup(ph->p_filesz, 16);
255 }
256
257 imgsize = sizeof(*header) + snlen + (nphs * 16) + psize;
258
259 img = malloc(imgsize + 32);
260 if (!img)
261 {
262 return NULL;
263 }
264
265 *image_size = imgsize;
266 sym = elf->symtab;
267 name = elf->string;
268 sp = 0;
269
270 for (j = 0; j < elf->nsyms; j++, sym++)
271 {
272 if (!strcmp("__stack", name + sym->st_name))
273 {
274 sp = sym->st_value;
275 }
276 }
277
278 memset(img, 0, imgsize);
279
280 header = (struct spk_header *)img;
281 header->magic[0] = 0xef;

Callers 1

mainFunction · 0.85

Calls 6

strlenFunction · 0.50
mallocFunction · 0.50
strcmpFunction · 0.50
memsetFunction · 0.50
strncpyFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected