1 /* 2 * Copyright 2009, François Revol, revol@free.fr. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include <uimage.h> 7 8 #include <KernelExport.h> 9 #include <ByteOrder.h> 10 11 12 void dump_uimage(struct image_header *image) 13 { 14 uint32 *sizes; 15 int i; 16 17 dprintf("uimage @ %p:\n", image); 18 19 if (!image) 20 return; 21 dprintf("magic: %x\n", ntohl(image->ih_magic)); 22 dprintf("size: %d\n", ntohl(image->ih_size)); 23 dprintf("load: %p\n", (void *)ntohl(image->ih_load)); 24 dprintf("ep: %p\n", (void *)ntohl(image->ih_ep)); 25 dprintf("os: %d\n", image->ih_os); 26 dprintf("arch: %d\n", image->ih_arch); 27 dprintf("type: %d\n", image->ih_type); 28 dprintf("comp: %d\n", image->ih_comp); 29 dprintf("name: '%-32s'\n", image->ih_name); 30 if (image->ih_type != IH_TYPE_MULTI) 31 return; 32 sizes = (uint32 *)(&image[1]); 33 for (i = 0; sizes[i]; i++) { 34 dprintf("contents[%d] :", i); 35 dprintf("%d bytes\n", (int)ntohl(sizes[i])); 36 } 37 } 38 39 40 bool 41 image_multi_getimg(struct image_header *image, uint32 idx, uint32 *data, uint32 *size) 42 { 43 uint32 *sizes; 44 uint32 base; 45 int i, count = 0; 46 47 sizes = (uint32 *)(&image[1]); 48 base = (uint32)sizes; 49 for (i = 0; sizes[i]; i++) 50 count++; 51 base += (count + 1) * sizeof(uint32); 52 for (i = 0; sizes[i] && i < count; i++) { 53 if (idx == i) { 54 *data = base; 55 *size = ntohl(sizes[i]); 56 return true; 57 } 58 base += (ntohl(sizes[i]) + 3) & ~3; 59 } 60 return false; 61 } 62 63