drivers/mtd/parsers/brcm_u-boot.c
Source file repositories/reference/linux-study-clean/drivers/mtd/parsers/brcm_u-boot.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/parsers/brcm_u-boot.c- Extension
.c- Size
- 2050 bytes
- Lines
- 86
- 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/module.hlinux/kernel.hlinux/slab.hlinux/mtd/mtd.hlinux/mtd/partitions.h
Detected Declarations
struct brcm_u_boot_headerfunction brcm_u_boot_parse
Annotated Snippet
struct brcm_u_boot_header {
__le32 magic;
__le32 length;
} __packed;
static const char *names[BRCM_U_BOOT_MAX_PARTS] = {
"u-boot-env",
"u-boot-env-backup",
};
static int brcm_u_boot_parse(struct mtd_info *mtd,
const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
{
struct brcm_u_boot_header header;
struct mtd_partition *parts;
size_t bytes_read;
size_t offset;
int err;
int i = 0;
parts = kzalloc_objs(*parts, BRCM_U_BOOT_MAX_PARTS);
if (!parts)
return -ENOMEM;
for (offset = 0;
offset < min_t(size_t, mtd->size, BRCM_U_BOOT_MAX_OFFSET);
offset += BRCM_U_BOOT_STEP) {
err = mtd_read(mtd, offset, sizeof(header), &bytes_read, (uint8_t *)&header);
if (err && !mtd_is_bitflip(err)) {
pr_err("Failed to read from %s at 0x%zx: %d\n", mtd->name, offset, err);
continue;
}
if (le32_to_cpu(header.magic) != BRCM_U_BOOT_MAGIC)
continue;
parts[i].name = names[i];
parts[i].offset = offset;
parts[i].size = sizeof(header) + le32_to_cpu(header.length);
i++;
pr_info("offset:0x%zx magic:0x%08x BINGO\n", offset, header.magic);
if (i == BRCM_U_BOOT_MAX_PARTS)
break;
}
*pparts = parts;
return i;
};
static const struct of_device_id brcm_u_boot_of_match_table[] = {
{ .compatible = "brcm,u-boot" },
{},
};
MODULE_DEVICE_TABLE(of, brcm_u_boot_of_match_table);
static struct mtd_part_parser brcm_u_boot_mtd_parser = {
.parse_fn = brcm_u_boot_parse,
.name = "brcm_u-boot",
.of_match_table = brcm_u_boot_of_match_table,
};
module_mtd_part_parser(brcm_u_boot_mtd_parser);
MODULE_DESCRIPTION("Broadcom's U-Boot partition parser");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/slab.h`, `linux/mtd/mtd.h`, `linux/mtd/partitions.h`.
- Detected declarations: `struct brcm_u_boot_header`, `function brcm_u_boot_parse`.
- 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.