- mtd_parts = kzalloc(sizeof(struct mtd_partition) * MAX_PARTS, GFP_KERNEL);
- buf = kmalloc(mtd->erasesize, GFP_KERNEL);
- sb = (struct squashfs_super_block *) buf;
- for (i = j = 0; i < num_parts; i++, j++) {
- part = &mtd_parts[j];
- memcpy(part, &spidata->parsed_parts[i], sizeof(struct mtd_partition));
-
- if (!strcmp(part->name, ROOTFS_NAME)) {
- /* create the root device */
- ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, i);
-
- part->size -= mtd->erasesize;
- config_start = part->offset + part->size;
-
- while ((mtd->read(mtd, part->offset, mtd->erasesize, &len, buf) == 0) &&
- (len == mtd->erasesize) &&
- (*((u32 *) buf) == SQUASHFS_MAGIC) &&
- (sb->bytes_used > 0)) {
-
- /* this is squashfs, allocate another partition starting from the end of filesystem data */
- memcpy(&mtd_parts[j + 1], part, sizeof(struct mtd_partition));
-
- len = (u32) sb->bytes_used;
- len += (part->offset & 0x000fffff);
- len += (mtd->erasesize - 1);
- len &= ~(mtd->erasesize - 1);
- len -= (part->offset & 0x000fffff);
-
- if (len + mtd->erasesize > part->size)
- break;
-
- part = &mtd_parts[++j];
-
- part->offset += len;
- part->size -= len;
-
- part->name = kmalloc(10, GFP_KERNEL);
- sprintf(part->name, "rootfs%d", j - i);
- }
- }
- if (!strcmp(part->name, "RedBoot config")) {
- /* add anoterh partition for the board config data */
- memcpy(&mtd_parts[j + 1], part, sizeof(struct mtd_partition));
- j++;
- part = &mtd_parts[j];
- part->offset += part->size;
- part->size = mtd->erasesize;
-
- part->name = kmalloc(16, GFP_KERNEL);
- sprintf(part->name, "board_config");
- }
- }
- num_parts += j - i;
- kfree(buf);
-