Commit b02b1242 authored by Federico Vaga's avatar Federico Vaga

lib|tools: lsfmc show FRU name

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent d4d431b5
......@@ -14,7 +14,7 @@ LIB = ./lib/
TOOLS = lsfmc \
fmc-slot-eeprom
CFLAGS = -ggdb -I. -I$(LIB) -I../kernel -Wall -Werror $(EXTRACFLAGS)
CFLAGS = -ggdb -I. -I$(LIB) -I../include/uapi/ -I../kernel -Wall -Werror $(EXTRACFLAGS)
GIT_VERSION := $(shell git describe --dirty --long --tags)
CFLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\""
......
......@@ -15,9 +15,9 @@ SO_VERSION_X := $(shell echo $(SO_VERSION_XYZ) | cut -d "." -f 1)
LIB = libfmc.a
LIBS = libfmc.so
LIBS_XYZ = $(LIBS).$(SO_VERSION_XYZ)
LOBJ := libfmc.o
LOBJ := libfmc.o ipmifru.o
CFLAGS = -Wall -Werror -ggdb -O2 -I. -I../include/uapi
CFLAGS = -Wall -Werror -ggdb -O2 -I. -I../../include/uapi
CFLAGS += -fPIC
CFLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\""
CFLAGS += $(EXTRACFLAGS)
......
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*/
#include <stdlib.h>
#include <string.h>
#include <linux/ipmi/fru.h>
/* The fru parser is both user and kernel capable: it needs alloc */
static void *fru_alloc(size_t size)
{
void *buf = malloc(size);
if (!buf)
memset(buf, 0, size);
return buf;
}
/* Some internal helpers */
static struct fru_type_length *
__fru_get_board_tl(struct fru_common_header *header, int nr)
{
struct fru_board_info_area *bia;
struct fru_type_length *tl;
bia = fru_get_board_area(header);
tl = bia->tl;
while (nr > 0 && !fru_is_eof(tl)) {
tl = fru_next_tl(tl);
nr--;
}
if (fru_is_eof(tl))
return NULL;
return tl;
}
static char *__fru_alloc_get_tl(struct fru_common_header *header, int nr)
{
struct fru_type_length *tl;
char *res;
tl = __fru_get_board_tl(header, nr);
if (!tl)
return NULL;
res = fru_alloc(fru_strlen(tl) + 1);
if (!res)
return NULL;
return fru_strcpy(res, tl);
}
/* Get various stuff, trivial */
char *fru_get_board_manufacturer(struct fru_common_header *header)
{
return __fru_alloc_get_tl(header, 0);
}
char *fru_get_product_name(struct fru_common_header *header)
{
return __fru_alloc_get_tl(header, 1);
}
char *fru_get_serial_number(struct fru_common_header *header)
{
return __fru_alloc_get_tl(header, 2);
}
char *fru_get_part_number(struct fru_common_header *header)
{
return __fru_alloc_get_tl(header, 3);
}
......@@ -9,8 +9,9 @@
#include <string.h>
#include <libgen.h>
#include <getopt.h>
#include <errno.h>
#include <fmc/core.h>
#include <linux/ipmi/fru.h>
static const char git_version[] = "git version: " GIT_VERSION;
static char *name;
......@@ -39,6 +40,36 @@ static void print_carrier_name(struct fmc_tkn *tkn)
fprintf(stdout, "\tcarrier: %s\n", carr_name);
}
static void print_slot_name(struct fmc_tkn *tkn, unsigned int id)
{
char *fru;
int ret;
fru = malloc(FRU_SIZE_MAX);
if (!fru)
goto err_alloc;
ret = fmc_slot_eeprom_read(tkn, id, fru, FRU_SIZE_MAX, 0);
if (ret < 0)
goto err_read;
if (ret == FRU_SIZE_MAX) {
char *fmc_name;
fmc_name = fru_get_product_name((struct fru_common_header *)fru);
fprintf(stdout, "\t\tmodule: %s\n", fmc_name);
free(fmc_name);
}
free(fru);
return;
err_read:
free(fru);
err_alloc:
fprintf(stdout, "\t\tmodule: unknown (%s)\n",
fmc_strerror(errno));
}
static void print_slot_flags(struct fmc_tkn *tkn, unsigned int id)
{
fputs("\t\tflags:\n", stdout);
......@@ -80,6 +111,7 @@ static void print_slot(struct fmc_tkn *tkn,
unsigned int carr_id, unsigned int id)
{
fprintf(stdout, "\t- fmc-slot-%u.%u:\n", carr_id, id);
print_slot_name(tkn, id);
if (verbose > 0)
print_slot_flags(tkn, id);
if (verbose > 1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment