From 2a51b7c1c2165ddb188c511e192b75f0aa0fbead Mon Sep 17 00:00:00 2001 From: Tian Fang Date: Mon, 9 Mar 2015 22:53:57 -0700 Subject: Initial open source release of OpenBMC --- .../recipes-wedge/po-eeprom/files/Makefile | 10 +++ .../recipes-wedge/po-eeprom/files/po-eeprom.c | 80 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files/Makefile create mode 100644 meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files/po-eeprom.c (limited to 'meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files') diff --git a/meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files/Makefile b/meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files/Makefile new file mode 100644 index 0000000..408de95 --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files/Makefile @@ -0,0 +1,10 @@ +# Copyright 2014-present Facebook. All Rights Reserved. +all: po-eeprom + +po-eeprom: po-eeprom.o + $(CC) -o $@ $^ $(LDFLAGS) + +.PHONY: clean + +clean: + rm -rf *.o po-eeprom diff --git a/meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files/po-eeprom.c b/meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files/po-eeprom.c new file mode 100644 index 0000000..46debee --- /dev/null +++ b/meta-facebook/meta-wedge/recipes-wedge/po-eeprom/files/po-eeprom.c @@ -0,0 +1,80 @@ +/* + * Copyright 2014-present Facebook. All Rights Reserved. + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#define SERIAL_LEN 17 + +usage() +{ + fprintf(stderr, "Usage: po-eeprom filename [filename...]\n" + "\twhere filename is the location of the PowerOne EEPROM, likely\n" + "\t/sys/bus/i2c/drivers/at24/7-0051/eeprom or\n" + "\t/sys/bus/i2c/drivers/at24/7-0052/eeprom\n"); + exit(2); +} + +int safe_read(int fd, void *buf, size_t size, char *msg) +{ + if (read(fd, buf, size) != size) { + perror(msg); + exit(3); + } +} + +int main(int argc, char **argv) +{ + int fd; + int file = 1; + uint8_t size; + uint8_t junk; + uint16_t crc; + char serial[SERIAL_LEN + 1]; + + if (argc < 2) + usage(); + + while (file < argc) { + fd = open(argv[file], O_RDONLY); + if (fd < 0) { + fprintf(stderr, "Couldn't open %s for EEPROM reading\n", argv[1]); + exit(1); + } + + safe_read(fd, &size, sizeof(size), "read size"); + safe_read(fd, &junk, sizeof(junk), "read junk"); + /* + * Should probably check CRC here, PowerOne provided some code where + * it looks like a pretty standard CCITT CRC16. + */ + safe_read(fd, &crc, sizeof(crc), "read CRC len"); + safe_read(fd, serial, SERIAL_LEN, "read serial number"); + + serial[SERIAL_LEN] = 0; + printf("Serial number: %s\n", serial); + close(fd); + file++; + } +} -- cgit v1.1