Linux 内核驱动程序:NVRAM 访问的模型是什么?

发布于 2024-09-07 13:47:24 字数 307 浏览 8 评论 0原文

我刚刚为我的主板上的 NXP RTC 芯片编写了一个 RTC 驱动程序,效果很好。该芯片还有一些电池支持的 RAM,我希望将其提供给用户空间应用程序。 RTC 框架不支持此功能。它只有 512 字节,但我在执行可查找的 CHAR 驱动程序或完整的 BLOCK 驱动程序之间犹豫不决。我以前从未做过块驱动程序,但它似乎需要比简单的 CHAR 更多的信息。

我还可以与 IOCTLS 进行交互,但这感觉并不那么干净。让这些字节可供用户空间使用的最佳方式是什么?

[编辑] 我忘了提及 RTC 芯片挂在 I2C 端口上,它没有映射到内存中,因此不适合进行映射。 [/编辑]

I just wrote a RTC driver for an NXP RTC chip on my board, it works great. This chip also has some battery backed RAM that I'd like to make available to a user space application. The RTC framework doesn't support this. It's only 512 bytes but I'm tossed between doing a seekable CHAR driver or a full blown BLOCK driver. I've never done a block driver before but it appears to require a bit more information than a simple CHAR.

I could also interface with IOCTLS but that doesn't feel as clean as it could be. What feels like the best way to make these bytes available to userland?

[EDIT] I forgot to mention that that the RTC chip is hanging off an I2C port, it's not mapped into memory, thus not making it a good candidate for mmaping. [/EDIT]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦断已成空 2024-09-14 13:47:24

块驱动程序仅适用于看起来像磁盘驱动器的设备。您打算在 512 字节上放置一个文件系统吗?不?使其成为字符设备。

你可以像其他司机那样做。查看drivers/char/nvram.c。这会创建一个字符设备,您可以使用 open()read()write()lseek()close()

Block drivers are only for devices that look like disk drives. Are you going to put a filesystem on your 512 bytes? No? Make it a character device.

You could just do it like other drivers have. Check out drivers/char/nvram.c. That creates a char device you can open(), read(), write(), lseek(), and close().

趁年轻赶紧闹 2024-09-14 13:47:24

我认为实现 mmap 的字符设备驱动程序应该足够了。 Linux 设备驱动 涵盖了第 15 章中的内容。

编辑:

嗯,i2c 是串行总线,因此< code>mmap 不是一个选项。我将向您推荐Essential Linux Device Drivers一书。我相信第 8 章中有一个示例 i2c EEPROM 字符设备驱动程序。希望这会有所帮助。

I think a character device driver implementing mmap should be adequate. Linux Device Drives covers that in chapter 15.

Edit:

Well, i2c is a serial bus, so mmap is not an option. I will refer you to Essential Linux Device Drivers book. I believe it has a sample i2c EEPROM char device driver in Chapter 8. Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文