summaryrefslogtreecommitdiffstats
path: root/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c
blob: 04772d74fed4a51a28a189709055d5c5acc06325 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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;
}
OpenPOWER on IntegriCloud