Commit 4c24eed1 authored by Federico Vaga's avatar Federico Vaga

sw:tool: add program to dump firmware version

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 0b068169
/*
* Copyright (C) 2020 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@cern.ch>
*/
#ifndef __LINUX_UAPI_SPEC_H
#define __LINUX_UAPI_SPEC_H
#ifndef __KERNEL__
#include <stdint.h>
#endif
#define SPEC_FMC_SLOTS 1
/* On FPGA components */
#define PCI_VENDOR_ID_CERN (0x10DC)
#define PCI_DEVICE_ID_SPEC_45T (0x018D)
#define PCI_DEVICE_ID_SPEC_100T (0x01A2)
#define PCI_DEVICE_ID_SPEC_150T (0x01A3)
#define PCI_VENDOR_ID_GENNUM (0x1A39)
#define PCI_DEVICE_ID_GN4124 (0x0004)
#define GN4124_GPIO_MAX 16
#define GN4124_GPIO_BOOTSEL0 15
#define GN4124_GPIO_BOOTSEL1 14
#define GN4124_GPIO_SPRI_DIN 13
#define GN4124_GPIO_SPRI_FLASH_CS 12
#define GN4124_GPIO_IRQ0 9
#define GN4124_GPIO_IRQ1 8
#define GN4124_GPIO_SCL 5
#define GN4124_GPIO_SDA 4
#define SPEC_DDR_SIZE (256 * 1024 * 1024)
#define SPEC_META_VENDOR_ID PCI_VENDOR_ID_CERN
#define SPEC_META_DEVICE_ID 0x53504543
#define SPEC_META_BOM_LE 0xFFFE0000
#define SPEC_META_BOM_END_MASK 0xFFFF0000
#define SPEC_META_BOM_VER_MASK 0x0000FFFF
#define SPEC_META_VERSION_MASK 0xFFFF0000
#define SPEC_META_VERSION_2_0 0x02000000
/**
* struct spec_meta_id Metadata
*/
struct spec_meta_id {
uint32_t vendor;
uint32_t device;
uint32_t version;
uint32_t bom;
uint32_t src[4];
uint32_t cap;
uint32_t uuid[4];
};
#define SPEC_META_VERSION_MAJ(_v) ((_v >> 24) & 0xFF)
#define SPEC_META_VERSION_MIN(_v) ((_v >> 16) & 0xFF)
#define SPEC_META_VERSION_PATCH(_v) (_v & 0xFFFF)
#endif /* __LINUX_UAPI_SPEC_H */
...@@ -15,6 +15,7 @@ ccflags-y += -I$(FPGA_MGR_ABS)/include ...@@ -15,6 +15,7 @@ ccflags-y += -I$(FPGA_MGR_ABS)/include
ccflags-$(CONFIG_FPGA_MGR_BACKPORT) += -DCONFIG_FPGA_MGR_BACKPORT ccflags-$(CONFIG_FPGA_MGR_BACKPORT) += -DCONFIG_FPGA_MGR_BACKPORT
ccflags-y += -I$(FMC_ABS)/include ccflags-y += -I$(FMC_ABS)/include
ccflags-y += -I$(SPI_ABS)/include ccflags-y += -I$(SPI_ABS)/include
ccflags-y += -I$(src)/../include
# priority to I2C, FMC headers from our sources # priority to I2C, FMC headers from our sources
LINUXINCLUDE := -I$(FMC_ABS)/include -I$(FMC_ABS)/include/linux -I$(I2C_ABS)/include -I$(I2C_ABS)/include/linux $(LINUXINCLUDE) LINUXINCLUDE := -I$(FMC_ABS)/include -I$(FMC_ABS)/include/linux -I$(I2C_ABS)/include -I$(I2C_ABS)/include/linux $(LINUXINCLUDE)
......
...@@ -15,32 +15,11 @@ ...@@ -15,32 +15,11 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/fmc.h> #include <linux/fmc.h>
#include <uapi/linux/spec.h>
#include "gn412x.h" #include "gn412x.h"
#include "spec-core-fpga.h" #include "spec-core-fpga.h"
#define SPEC_FMC_SLOTS 1
/* On FPGA components */
#define PCI_VENDOR_ID_CERN (0x10DC)
#define PCI_DEVICE_ID_SPEC_45T (0x018D)
#define PCI_DEVICE_ID_SPEC_100T (0x01A2)
#define PCI_DEVICE_ID_SPEC_150T (0x01A3)
#define PCI_VENDOR_ID_GENNUM (0x1A39)
#define PCI_DEVICE_ID_GN4124 (0x0004)
#define GN4124_GPIO_MAX 16
#define GN4124_GPIO_BOOTSEL0 15
#define GN4124_GPIO_BOOTSEL1 14
#define GN4124_GPIO_SPRI_DIN 13
#define GN4124_GPIO_SPRI_FLASH_CS 12
#define GN4124_GPIO_IRQ0 9
#define GN4124_GPIO_IRQ1 8
#define GN4124_GPIO_SCL 5
#define GN4124_GPIO_SDA 4
#define SPEC_DDR_SIZE (256 * 1024 * 1024)
/** /**
* @SPEC_FPGA_SELECT_FPGA_FLASH: (default) the FPGA is an SPI master that can * @SPEC_FPGA_SELECT_FPGA_FLASH: (default) the FPGA is an SPI master that can
* access the flash (at boot it takes its * access the flash (at boot it takes its
...@@ -79,27 +58,6 @@ enum { ...@@ -79,27 +58,6 @@ enum {
SPEC_META_UUID = SPEC_META_BASE + FPGA_META_UUID, SPEC_META_UUID = SPEC_META_BASE + FPGA_META_UUID,
}; };
#define SPEC_META_VENDOR_ID PCI_VENDOR_ID_CERN
#define SPEC_META_DEVICE_ID 0x53504543
#define SPEC_META_BOM_LE 0xFFFE0000
#define SPEC_META_BOM_END_MASK 0xFFFF0000
#define SPEC_META_BOM_VER_MASK 0x0000FFFF
#define SPEC_META_VERSION_MASK 0xFFFF0000
#define SPEC_META_VERSION_2_0 0x02000000
/**
* struct spec_meta_id Metadata
*/
struct spec_meta_id {
uint32_t vendor;
uint32_t device;
uint32_t version;
uint32_t bom;
uint32_t src[4];
uint32_t cap;
uint32_t uuid[4];
};
/** /**
* struct spec_fpga - it contains data to handle the FPGA * struct spec_fpga - it contains data to handle the FPGA
* *
......
spec-firmware-version
# SPDX-License-Identifier: LGPL-3.0-or-later
#
# Copyright (C) 2020 CERN
# If it exists includes Makefile.specific. In this Makefile, you should put
# specific Makefile code that you want to run before this. For example,
# build a particular environment.
-include Makefile.specific
DESTDIR ?= /usr/local/
TOOLS = spec-firmware-version
CFLAGS = -ggdb -I. -I../include/uapi -Wall -Werror $(EXTRACFLAGS)
GIT_VERSION := $(shell git describe --dirty --long --tags)
CFLAGS += -DGIT_VERSION="\"$(GIT_VERSION)\""
CPPCHECK ?= cppcheck
all: $(TOOLS)
$(TOOLS):
clean:
@$(MAKE) -C $(LIB) $@
rm -f $(TOOLS)
install:
install -d $(DESTDIR)/bin
install -D $(TOOLS) $(DESTDIR)/bin
cppcheck:
$(CPPCHECK) -q -I. -I../include/uapi --suppress=missingIncludeSystem --enable=all *.c *.h --error-exitcode=1
.PHONY=cppcheck
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* Copyright (C) 2020 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@cern.ch>
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include <libgen.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/spec.h>
static const char git_version[] = "git version: " GIT_VERSION;
static char *name;
static void help(void)
{
fprintf(stderr, "%s [options]\n"
"\tPrint the firmware version\n"
"\t-p <PCIID>\n"
"\t-V print version\n"
"\t-h print help\n",
name);
}
static void print_version(void)
{
printf("%s version %s\n", name, git_version);
}
static void cleanup(void)
{
if (name)
free(name);
}
#define PCIID_STR_LEN 16
int main(int argc, char *argv[])
{
struct spec_meta_id *rom;
int err;
int fd;
char path[128];
char opt;
char pciid_str[PCIID_STR_LEN] = "\0";
name = strndup(basename(argv[0]), 64);
if (!name)
exit(EXIT_FAILURE);
err = atexit(cleanup);
if (err)
exit(EXIT_FAILURE);
while ((opt = getopt(argc, argv, "h?Vvp:")) != -1) {
switch (opt) {
case 'h':
case '?':
help();
exit(EXIT_SUCCESS);
case 'V':
print_version();
exit(EXIT_SUCCESS);
case 'p':
strncpy(pciid_str, optarg, PCIID_STR_LEN);
break;
}
}
if (strlen(pciid_str) == 0) {
fputs("PCI ID is mandatory\n", stderr);
help();
exit(EXIT_FAILURE);
}
snprintf(path, 128, "/sys/bus/pci/devices/%s/resource0", pciid_str);
fd = open(path, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Can't open \"%s\": %s\n",
path, strerror(errno));
exit(EXIT_FAILURE);
}
rom = mmap(NULL, sizeof(*rom), PROT_READ, MAP_SHARED, fd, 0);
if ((long)rom == -1) {
fputs("Failed while reading SPEC FPGA ROM\n", stderr);
} else {
fprintf(stdout, "vendor : 0x%08x\n", rom->vendor);
fprintf(stdout, "device : 0x%08x\n", rom->device);
fprintf(stdout, "version : %u.%u.%u\n",
SPEC_META_VERSION_MAJ(rom->version),
SPEC_META_VERSION_MIN(rom->version),
SPEC_META_VERSION_PATCH(rom->version));
if ((rom->bom & SPEC_META_BOM_END_MASK) == SPEC_META_BOM_LE)
fputs("byte-order : little-endian\n", stdout);
else
fputs("byte-order : wrong or unknown\n", stdout);
fprintf(stdout, "sources : %08x%08x%08x%08x\n",
rom->src[0], rom->src[1], rom->src[2], rom->src[3]);
fprintf(stdout, "capabilities : 0x%08x\n", rom->vendor);
fprintf(stdout, "UUID : %08x%08x%08x%08x\n",
rom->uuid[0], rom->uuid[1],
rom->uuid[2], rom->uuid[3]);
}
munmap(rom, sizeof(*rom));
close(fd);
exit(err ? EXIT_FAILURE : EXIT_SUCCESS);
}
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