struct footer_v1 {
u32 image_info_base; /* Address of first word of ImageFooter */
u32 image_start; /* Start of area reserved by this footer */
u32 signature; /* 'Magic' number proves it's a footer */
u32 type; /* Area type: ARM Image, SIB, customer */
u32 checksum; /* Just this structure */
};
struct image_info_v1 {
u32 bootFlags; /* Boot flags, compression etc. */
u32 imageNumber; /* Unique number, selects for boot etc. */
u32 loadAddress; /* Address program should be loaded to */
u32 length; /* Actual size of image */
u32 address; /* Image is executed from here */ char name[16]; /* Null terminated */
u32 headerBase; /* Flash Address of any stripped header */
u32 header_length; /* Length of header in memory */
u32 headerType; /* AIF, RLF, s-record etc. */
u32 checksum; /* Image checksum (inc. this struct) */
};
static u32 word_sum(void *words, int num)
{
u32 *p = words;
u32 sum = 0;
while (num--)
sum += *p++;
return sum;
}
static u32 word_sum_v2(u32 *p, u32 num)
{
u32 sum = 0; int i;
for (i = 0; i < num; i++) {
u32 val;
val = p[i]; if (val > ~sum)
sum++;
sum += val;
} return ~sum;
}
staticbool afs_is_v1(struct mtd_info *mtd, u_int off)
{ /* The magic is 12 bytes from the end of the erase block */
u_int ptr = off + mtd->erasesize - 12;
u32 magic;
size_t sz; int ret;
ret = mtd_read(mtd, ptr, 4, &sz, (u_char *)&magic); if (ret < 0) {
printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
ptr, ret); returnfalse;
} if (ret >= 0 && sz != 4) returnfalse;
return (magic == AFSV1_FOOTER_MAGIC);
}
staticbool afs_is_v2(struct mtd_info *mtd, u_int off)
{ /* The magic is the 8 last bytes of the erase block */
u_int ptr = off + mtd->erasesize - 8;
u32 foot[2];
size_t sz; int ret;
ret = mtd_read(mtd, ptr, 8, &sz, (u_char *)foot); if (ret < 0) {
printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
ptr, ret); returnfalse;
} if (ret >= 0 && sz != 8) returnfalse;
staticint afs_parse_v1_partition(struct mtd_info *mtd,
u_int off, struct mtd_partition *part)
{ struct footer_v1 fs; struct image_info_v1 iis;
u_int mask; /* * Static checks cannot see that we bail out if we have an error * reading the footer.
*/
u_int iis_ptr;
u_int img_ptr;
u_int ptr;
size_t sz; int ret; int i;
/* * This is the address mask; we use this to mask off out of * range address bits.
*/
mask = mtd->size - 1;
ptr = off + mtd->erasesize - sizeof(fs);
ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs); if (ret >= 0 && sz != sizeof(fs))
ret = -EINVAL; if (ret < 0) {
printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
ptr, ret); return ret;
} /* * Check the checksum.
*/ if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) return -EINVAL;
/* * Hide the SIB (System Information Block)
*/ if (fs.type == 2) return 0;
/* * Check the image info base. This can not * be located after the footer structure.
*/ if (iis_ptr >= ptr) return 0;
/* * Check the start of this image. The image * data can not be located after this block.
*/ if (img_ptr > off) return 0;
/* Read the image info block */
memset(&iis, 0, sizeof(iis));
ret = mtd_read(mtd, iis_ptr, sizeof(iis), &sz, (u_char *)&iis); if (ret < 0) {
printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
iis_ptr, ret); return -EINVAL;
}
if (sz != sizeof(iis)) return -EINVAL;
/* * Validate the name - it must be NUL terminated.
*/ for (i = 0; i < sizeof(iis.name); i++) if (iis.name[i] == '\0') break; if (i > sizeof(iis.name)) return -EINVAL;
part->name = kstrdup(iis.name, GFP_KERNEL); if (!part->name) return -ENOMEM;
pr_debug(" region %d: address: %08x, size: %08x, " "offset: %08x\n",
i,
region_load_addr,
region_size,
region_offset);
region_start = off + region_offset;
region_end = region_start + region_size; /* Align partition to end of erase block */
region_end += (mtd->erasesize - 1);
region_end &= ~(mtd->erasesize -1);
pr_debug(" partition start = %08x, partition end = %08x\n",
region_start, region_end);
/* Create one partition per region */
part->name = kstrdup(name, GFP_KERNEL); if (!part->name) return -ENOMEM;
part->offset = region_start;
part->size = region_end - region_start;
part->mask_flags = 0;
}
return 0;
}
staticint parse_afs_partitions(struct mtd_info *mtd, conststruct mtd_partition **pparts, struct mtd_part_parser_data *data)
{ struct mtd_partition *parts;
u_int off, sz; int ret = 0; int i;
/* Count the partitions by looping over all erase blocks */ for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) { if (afs_is_v1(mtd, off)) {
sz += sizeof(struct mtd_partition);
i += 1;
} if (afs_is_v2(mtd, off)) {
sz += sizeof(struct mtd_partition);
i += 1;
}
}
if (!i) return 0;
parts = kzalloc(sz, GFP_KERNEL); if (!parts) return -ENOMEM;
/* * Identify the partitions
*/ for (i = off = 0; off < mtd->size; off += mtd->erasesize) { if (afs_is_v1(mtd, off)) {
ret = afs_parse_v1_partition(mtd, off, &parts[i]); if (ret) goto out_free_parts;
i++;
} if (afs_is_v2(mtd, off)) {
ret = afs_parse_v2_partition(mtd, off, &parts[i]); if (ret) goto out_free_parts;
i++;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.