drivers/mtd/parsers/parser_imagetag.c
Source file repositories/reference/linux-study-clean/drivers/mtd/parsers/parser_imagetag.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/parsers/parser_imagetag.c- Extension
.c- Size
- 5961 bytes
- Lines
- 222
- Domain
- Driver Families
- Bucket
- drivers/mtd
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bcm963xx_tag.hlinux/crc32.hlinux/module.hlinux/kernel.hlinux/sizes.hlinux/slab.hlinux/vmalloc.hlinux/mtd/mtd.hlinux/mtd/partitions.hlinux/of.h
Detected Declarations
function bcm963xx_read_imagetagfunction bcm963xx_parse_imagetag_partitions
Annotated Snippet
if (kstrtouint(buf->kernel_length, 10, &kernellen)) {
pr_err("invalid kernel length: %*ph\n",
(int)sizeof(buf->kernel_length),
buf->kernel_length);
ret = -EINVAL;
goto out;
}
STR_NULL_TERMINATE(buf->total_length);
if (kstrtouint(buf->total_length, 10, &totallen)) {
pr_err("invalid total length: %*ph\n",
(int)sizeof(buf->total_length),
buf->total_length);
ret = -EINVAL;
goto out;
}
/*
* Addresses are flash absolute, so convert to partition
* relative addresses. Assume either kernel or rootfs will
* directly follow the image tag.
*/
if (rootfsaddr < kerneladdr)
offset = rootfsaddr - sizeof(struct bcm_tag);
else
offset = kerneladdr - sizeof(struct bcm_tag);
kerneladdr = kerneladdr - offset;
rootfsaddr = rootfsaddr - offset;
spareaddr = roundup(totallen, master->erasesize);
if (rootfsaddr < kerneladdr) {
/* default Broadcom layout */
rootfslen = kerneladdr - rootfsaddr;
rootfs_first = true;
} else {
/* OpenWrt layout */
rootfsaddr = kerneladdr + kernellen;
rootfslen = spareaddr - rootfsaddr;
}
} else {
goto out;
}
sparelen = master->size - spareaddr;
/* Determine number of partitions */
if (rootfslen > 0)
nrparts++;
if (kernellen > 0)
nrparts++;
parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL);
if (!parts) {
ret = -ENOMEM;
goto out;
}
/* Start building partition list */
if (kernellen > 0) {
int kernelpart = curpart;
if (rootfslen > 0 && rootfs_first)
kernelpart++;
parts[kernelpart].name = "kernel";
parts[kernelpart].offset = kerneladdr;
parts[kernelpart].size = kernellen;
curpart++;
}
if (rootfslen > 0) {
int rootfspart = curpart;
if (kernellen > 0 && rootfs_first)
rootfspart--;
parts[rootfspart].name = "rootfs";
parts[rootfspart].offset = rootfsaddr;
parts[rootfspart].size = rootfslen;
if (sparelen > 0 && !rootfs_first)
parts[rootfspart].size += sparelen;
curpart++;
}
for (i = 0; i < nrparts; i++)
pr_info("Partition %d is %s offset %llx and length %llx\n", i,
parts[i].name, parts[i].offset, parts[i].size);
pr_info("Spare partition is offset %x and length %x\n", spareaddr,
sparelen);
Annotation
- Immediate include surface: `linux/bcm963xx_tag.h`, `linux/crc32.h`, `linux/module.h`, `linux/kernel.h`, `linux/sizes.h`, `linux/slab.h`, `linux/vmalloc.h`, `linux/mtd/mtd.h`.
- Detected declarations: `function bcm963xx_read_imagetag`, `function bcm963xx_parse_imagetag_partitions`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.