简体   繁体   中英

How to get the Linux Flash ROM size in C?

Is there any C/C++ library or Linux system command that i can use to get the ROM size? ON start-up the Kernel displays the proper size in Mb. I just can't seem to find where i can pull it from

Thanks -Naze

By the way, im using a jff2 ROM file system on an embedded system. ARM7 cpu.

If it appears as an mtd device, you can do the following

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

Size are in hexadecimal

For more information on an individual mtd, you will find them in the /sys/class/mtd<n> directory

No sure what the underlying system functions are, but dmidecode ( here )is a program you can run at the shell that will dump out a bunch of info, including the bios ROM size. On my machine it does this:

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

It is open source so I'm betting you can dig through it and figure out how it works: I expect there is a bunch of binary data decoding necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM