Add OEM command to request flash size
The BMC flash is `/dev/mtd0` and the size can found in
`/sys/class/mtd/mtd0/size`. This OEM command will request that
information with MTDINFO.
Tested:
Successfully requested the flash size information with ipmitool.
```
cat /sys/class/mtd/mtd0/size
67108864
```
67108864 / 1024 / 1024 = 64MB flash
```
ipmitool raw 0x2e 0x32 0x79 0x2b 0x00 0x09
79 2b 00 09 00 00 00 04
```
Output in little endian.
0x04000000 -> 67108864
Change-Id: Iec1b33503d1166a42ceef4b8491e5c19c3a077fe
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/handler.cpp b/handler.cpp
index 4f1bc56..ef48842 100644
--- a/handler.cpp
+++ b/handler.cpp
@@ -20,7 +20,12 @@
#include "handler_impl.hpp"
#include "util.hpp"
+#include <fcntl.h>
#include <ipmid/api.h>
+#include <mtd/mtd-abi.h>
+#include <mtd/mtd-user.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
#include <cinttypes>
#include <cstdio>
@@ -213,6 +218,20 @@
ofs.close();
}
+uint32_t Handler::getFlashSize()
+{
+ mtd_info_t info;
+ int fd = open("/dev/mtd0", O_RDONLY);
+ int err = ioctl(fd, MEMGETINFO, &info);
+ close(fd);
+
+ if (err)
+ {
+ throw IpmiException(IPMI_CC_UNSPECIFIED_ERROR);
+ }
+ return info.size;
+}
+
std::string Handler::getEntityName(std::uint8_t id, std::uint8_t instance)
{
// Check if we support this Entity ID.