diff options
Diffstat (limited to 'meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c')
-rw-r--r-- | meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c new file mode 100644 index 0000000..04772d7 --- /dev/null +++ b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c @@ -0,0 +1,111 @@ +/* + * + * Copyright 2015-present Facebook. All Rights Reserved. + * + * This file provides platform specific implementation of FRUID information + * + * FRUID specification can be found at + * www.intel.com/content/dam/www/public/us/en/documents/product-briefs/platform-management-fru-document-rev-1-2-feb-2013.pdf + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <syslog.h> +#include <string.h> +#include <stdint.h> +#include "fruid.h" + +#define EEPROM_SPB "/sys/class/i2c-adapter/i2c-8/8-0051/eeprom" + +#define BIN_SPB "/tmp/fruid_spb.bin" + +#define NAME_SPB "Side Plane Board" + +#define BUF_SIZE 1024 + +/* + * copy_eeprom_to_bin - copy the eeprom to binary file im /tmp directory + * + * @eeprom_file : path for the eeprom of the device + * @bin_file : path for the binary file + * + * returns 0 on successful copy + * returns non-zero on file operation errors + */ +int copy_eeprom_to_bin(const char * eeprom_file, const char * bin_file) { + + int eeprom; + int bin; + uint64_t tmp[BUF_SIZE]; + ssize_t bytes_rd, bytes_wr; + + errno = 0; + + if (access(eeprom_file, F_OK) != -1) { + + eeprom = open(eeprom_file, O_RDONLY); + if (eeprom == -1) { + syslog(LOG_ERR, "copy_eeprom_to_bin: unable to open the %s file: %s", + eeprom_file, strerror(errno)); + return errno; + } + + bin = open(bin_file, O_WRONLY | O_CREAT, 0644); + if (bin == -1) { + syslog(LOG_ERR, "copy_eeprom_to_bin: unable to create %s file: %s", + bin_file, strerror(errno)); + return errno; + } + + while ((bytes_rd = read(eeprom, tmp, BUF_SIZE)) > 0) { + bytes_wr = write(bin, tmp, bytes_rd); + if (bytes_wr != bytes_rd) { + syslog(LOG_ERR, "copy_eeprom_to_bin: write to %s file failed: %s", + bin_file, strerror(errno)); + return errno; + } + } + + close(bin); + close(eeprom); + } + + return 0; +} + +/* Populate the platform specific eeprom for fruid info */ +int plat_fruid_init(void) { + + int ret; + + ret = copy_eeprom_to_bin(EEPROM_SPB, BIN_SPB); + + return ret; +} + +int plat_fruid_size(void) { + /* TODO: Not supported yet */ + return 0; +} +int plat_fruid_data(int offset, int count, unsigned char *data) { + /* TODO: Not supported yet */ + return 0; +} |