Linux 内核驱动程序:NVRAM 访问的模型是什么?
我刚刚为我的主板上的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
块驱动程序仅适用于看起来像磁盘驱动器的设备。您打算在 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 canopen()
,read()
,write()
,lseek()
, andclose()
.我认为实现
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.