drivers/nvmem/u-boot-env.c
Source file repositories/reference/linux-study-clean/drivers/nvmem/u-boot-env.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvmem/u-boot-env.c- Extension
.c- Size
- 2575 bytes
- Lines
- 101
- Domain
- Driver Families
- Bucket
- drivers/nvmem
- 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/mod_devicetable.hlinux/module.hlinux/mtd/mtd.hlinux/nvmem-provider.hlinux/of.hlinux/platform_device.hlinux/slab.hlayouts/u-boot-env.h
Detected Declarations
struct u_boot_envfunction u_boot_env_readfunction u_boot_env_probe
Annotated Snippet
struct u_boot_env {
struct device *dev;
struct nvmem_device *nvmem;
enum u_boot_env_format format;
struct mtd_info *mtd;
};
static int u_boot_env_read(void *context, unsigned int offset, void *val,
size_t bytes)
{
struct u_boot_env *priv = context;
struct device *dev = priv->dev;
size_t bytes_read;
int err;
err = mtd_read(priv->mtd, offset, bytes, &bytes_read, val);
if (err && !mtd_is_bitflip(err)) {
dev_err(dev, "Failed to read from mtd: %d\n", err);
return err;
}
if (bytes_read != bytes) {
dev_err(dev, "Failed to read %zu bytes\n", bytes);
return -EIO;
}
return 0;
}
static int u_boot_env_probe(struct platform_device *pdev)
{
struct nvmem_config config = {
.name = "u-boot-env",
.reg_read = u_boot_env_read,
};
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct u_boot_env *priv;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->dev = dev;
priv->format = (uintptr_t)of_device_get_match_data(dev);
priv->mtd = of_get_mtd_device_by_node(np);
if (IS_ERR(priv->mtd)) {
dev_err_probe(dev, PTR_ERR(priv->mtd), "Failed to get %pOF MTD\n", np);
return PTR_ERR(priv->mtd);
}
config.dev = dev;
config.priv = priv;
config.size = priv->mtd->size;
priv->nvmem = devm_nvmem_register(dev, &config);
if (IS_ERR(priv->nvmem))
return PTR_ERR(priv->nvmem);
return u_boot_env_parse(dev, priv->nvmem, priv->format);
}
static const struct of_device_id u_boot_env_of_match_table[] = {
{ .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, },
{ .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
{ .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
{ .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BROADCOM, },
{},
};
static struct platform_driver u_boot_env_driver = {
.probe = u_boot_env_probe,
.driver = {
.name = "u_boot_env",
.of_match_table = u_boot_env_of_match_table,
},
};
module_platform_driver(u_boot_env_driver);
MODULE_AUTHOR("Rafał Miłecki");
MODULE_DESCRIPTION("U-Boot environment variables support module");
MODULE_LICENSE("GPL");
MODULE_DEVICE_TABLE(of, u_boot_env_of_match_table);
Annotation
- Immediate include surface: `linux/mod_devicetable.h`, `linux/module.h`, `linux/mtd/mtd.h`, `linux/nvmem-provider.h`, `linux/of.h`, `linux/platform_device.h`, `linux/slab.h`, `layouts/u-boot-env.h`.
- Detected declarations: `struct u_boot_env`, `function u_boot_env_read`, `function u_boot_env_probe`.
- Atlas domain: Driver Families / drivers/nvmem.
- 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.