meta-facebook/meta-lightning/recipes-lightning/ipmid/files/fruid.c (72 lines of code) (raw):

/* * * 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 <openbmc/pal.h> #include "fruid.h" #define FRUID_SIZE 256 /* * dump_eeprom - 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 dump_eeprom(const char * eeprom_file, const char * bin_file) { int eeprom; int bin; uint64_t tmp[FRUID_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, "dump_eeprom: 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, "dump_eeprom: unable to create %s file: %s", bin_file, strerror(errno)); return errno; } bytes_rd = read(eeprom, tmp, FRUID_SIZE); if (bytes_rd != FRUID_SIZE) { syslog(LOG_ERR, "dump_eeprom: write to %s file failed: %s", eeprom_file, strerror(errno)); return errno; } bytes_wr = write(bin, tmp, bytes_rd); if (bytes_wr != bytes_rd) { syslog(LOG_ERR, "dump_eeprom: 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 fru, ret; char eeprom[128]; char binfile[128]; for (fru = 1; fru <= MAX_NUM_FRUS; fru++) { ret = pal_get_fruid_eeprom_path(fru, eeprom); if (ret < 0) { syslog(LOG_WARNING, "plat_fruid_init: pal_get_fruid_eeprom_path failed for fru: %d", fru); continue; } ret = pal_get_fruid_path(fru, binfile); if (ret < 0) { syslog(LOG_WARNING, "plat_fruid_init: pal_get_fruid_path failed for fru: %d", fru); continue; } ret = dump_eeprom(eeprom, binfile); } return ret; } int plat_fruid_size(unsigned char payload_id) { /* TODO: Not supported yet */ return 0; } int plat_fruid_data(unsigned char payload_id, int fru_id, int offset, int count, unsigned char *data) { /* TODO: Not supported yet */ return 0; }