如何在C中获得Linux闪存ROM的大小



是否有任何C/C++库或Linux系统命令可以用来获取ROM大小?启动时,内核以Mb为单位显示正确的大小。我只是好像找不到从中提取它的位置

谢谢-Naze

顺便说一句,im在嵌入式系统上使用jff2 ROM文件系统。ARM7 cpu。

如果它显示为mtd设备,您可以执行以下

cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00030000 00010000 "BootLoaders"
mtd1: 00200000 00010000 "Kernel"
mtd2: 00280000 00010000 "RootFS"
mtd3: 00350000 00010000 "User"

大小以十六进制表示

有关单个mtd的更多信息,您可以在/sys/class/mtd<n>目录

中找到它们

不确定底层系统功能是什么,但dmidecode(这里(是一个可以在shell上运行的程序,它会转储一堆信息,包括bios ROM大小。在我的机器上,它是这样做的:

sophiel:/home/owner# dmidecode | more
# dmidecode 2.9
SMBIOS 2.3 present.
59 structures occupying 1891 bytes.
Table at 0x000F0450.
Handle 0xDA00, DMI type 218, 35 bytes
OEM-specific Type
        Header and Data:
                DA 23 00 DA B2 00 17 0B 0E 18 00 58 00 58 00 01
                00 59 00 59 00 01 00 05 80 05 80 01 00 FF FF 00
                00 00 00
Handle 0xDA01, DMI type 218, 17 bytes
OEM-specific Type
        Header and Data:
                DA 11 01 DA B2 00 17 0B 0E 18 00 FF FF 00 00 00
                00
Handle 0x0000, DMI type 0, 20 bytes
BIOS Information
        Vendor: Dell Computer Corporation
        Version: A03
        Release Date: 01/05/2006
        Address: 0xF0000
        Runtime Size: 64 kB
        ROM Size: 512 kB
        Characteristics:
                PCI is supported
                PNP is supported
                APM is supported
                BIOS is upgradeable
                BIOS shadowing is allowed
                ESCD support is available
                Boot from CD is supported
                Selectable boot is supported
                EDD is supported
                Japanese floppy for Toshiba 1.2 MB is supported (int 13h)
                Print screen service is supported (int 5h)
                8042 keyboard services are supported (int 9h)
                Serial services are supported (int 14h)
                Printer services are supported (int 17h)
                ACPI is supported
                USB legacy is supported
                LS-120 boot is supported
                BIOS boot specification is supported
                Function key-initiated network boot is supported

它是开源的,所以我打赌你可以深入研究它并弄清楚它是如何工作的:我希望有一堆二进制数据解码是必要的。

最新更新