Commit 2e35554a authored by Federico Vaga's avatar Federico Vaga

get zio version directly from git

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent ca75f9be
...@@ -14,7 +14,11 @@ obj-m += drivers/ ...@@ -14,7 +14,11 @@ obj-m += drivers/
obj-m += buffers/ obj-m += buffers/
obj-m += triggers/ obj-m += triggers/
GIT_VERSION = $(shell cd $(src); git describe --dirty --long --tags) # src is defined byt the kernel Makefile, but we want to use it also in our
# local Makefile (tools, lib)
src ?= $(shell pwd)
GIT_VERSION := $(shell cd $(src); git describe --dirty --long --tags)
# For this CSM_VERSION, please see ohwr.org/csm documentation # For this CSM_VERSION, please see ohwr.org/csm documentation
ifdef CONFIG_CSM_VERSION ifdef CONFIG_CSM_VERSION
...@@ -23,9 +27,15 @@ else ...@@ -23,9 +27,15 @@ else
ccflags-y += -DCERN_SUPER_MODULE="" ccflags-y += -DCERN_SUPER_MODULE=""
endif endif
# Extract major, minor and patch number
ZIO_VERSION := -D__ZIO_MAJOR_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f 2 | cut -d '.' -f 1; )
ZIO_VERSION += -D__ZIO_MINOR_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f 2 | cut -d '.' -f 2; )
ZIO_VERSION += -D__ZIO_PATCH_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f 3)
export ZIO_VERSION
# WARNING: the line below doesn't work in-kernel if you compile with O= # WARNING: the line below doesn't work in-kernel if you compile with O=
ccflags-y += -I$(src)/include/ -DGIT_VERSION=\"$(GIT_VERSION)\" ccflags-y += -I$(src)/include/ -DGIT_VERSION=\"$(GIT_VERSION)\"
ccflags-y += $(ZIO_VERSION)
ccflags-$(CONFIG_ZIO_DEBUG) += -DDEBUG ccflags-$(CONFIG_ZIO_DEBUG) += -DDEBUG
all: modules tools all: modules tools
......
...@@ -23,7 +23,9 @@ static struct zio_status *zstat = &zio_global_status; /* Always use ptr */ ...@@ -23,7 +23,9 @@ static struct zio_status *zstat = &zio_global_status; /* Always use ptr */
*/ */
static ssize_t zio_show_version(struct bus_type *bus, char *buf) static ssize_t zio_show_version(struct bus_type *bus, char *buf)
{ {
return sprintf(buf, "%d.%d\n", ZIO_MAJOR_VERSION, ZIO_MINOR_VERSION); return sprintf(buf, "%d.%d-%d\n", zio_version_major(zio_version),
zio_version_minor(zio_version),
zio_version_patch(zio_version));
} }
/* /*
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#include <linux/zio-buffer.h> #include <linux/zio-buffer.h>
#include "zio-internal.h" #include "zio-internal.h"
const uint32_t zio_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION);
struct zio_status zio_global_status; struct zio_status zio_global_status;
static struct zio_status *zstat = &zio_global_status; /* Always use ptr */ static struct zio_status *zstat = &zio_global_status; /* Always use ptr */
/* /*
...@@ -31,8 +34,8 @@ struct zio_control *zio_alloc_control(gfp_t gfp) ...@@ -31,8 +34,8 @@ struct zio_control *zio_alloc_control(gfp_t gfp)
if (!ctrl) if (!ctrl)
return NULL; return NULL;
ctrl->major_version = ZIO_MAJOR_VERSION; ctrl->major_version = zio_version_major(zio_version);
ctrl->minor_version = ZIO_MINOR_VERSION; ctrl->minor_version = zio_version_minor(zio_version);
if (ntohl(1) == 1) if (ntohl(1) == 1)
ctrl->flags |= ZIO_CONTROL_BIG_ENDIAN; ctrl->flags |= ZIO_CONTROL_BIG_ENDIAN;
else else
......
...@@ -8,9 +8,24 @@ ...@@ -8,9 +8,24 @@
#ifndef __ZIO_USER_H__ #ifndef __ZIO_USER_H__
#define __ZIO_USER_H__ #define __ZIO_USER_H__
/* ZIO_VERSION: is a zio_class attribute to identify the framework version*/ #define ZIO_VERSION(M, m, p) (((M & 0xFF) << 24) | ((m & 0xFF) << 16) | (p & 0xFFFF))
#define ZIO_MAJOR_VERSION 1
#define ZIO_MINOR_VERSION 0 static inline uint8_t zio_version_major(uint32_t version)
{
return (version >> 24) & 0xFF;
}
static inline uint8_t zio_version_minor(uint32_t version)
{
return (version >> 16) & 0xFF;
}
static inline uint16_t zio_version_patch(uint32_t version)
{
return version & 0xFF;
}
/* /*
* ZIO_OBJ_NAME_LEN is the name's length used for registered objects * ZIO_OBJ_NAME_LEN is the name's length used for registered objects
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#ifdef __KERNEL__ /* Nothing more is for user space */ #ifdef __KERNEL__ /* Nothing more is for user space */
extern const uint32_t zio_version;
/* /*
* ZIO_NAME_LEN is the full name length used in the head structures. * ZIO_NAME_LEN is the full name length used in the head structures.
* It is sometimes built at run time, for example buffer instances * It is sometimes built at run time, for example buffer instances
......
# build user-space tools for zio # build user-space tools for zio
CFLAGS = -I$(M)/include/ -Wall $(EXTRACFLAGS) CFLAGS = -I$(M)/include/ -Wall $(ZIO_VERSION) $(EXTRACFLAGS)
CC ?= $(CROSS_COMPILE)gcc CC ?= $(CROSS_COMPILE)gcc
progs := zio-dump progs := zio-dump
......
...@@ -129,8 +129,8 @@ int main(int argc, char **argv) ...@@ -129,8 +129,8 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
ctrl.major_version = ZIO_MAJOR_VERSION; ctrl.major_version = __ZIO_MAJOR_VERSION;
ctrl.minor_version = ZIO_MINOR_VERSION; ctrl.minor_version = __ZIO_MINOR_VERSION;
if (verbose) { if (verbose) {
printf(" time: %9li.%09li\n", ts.tv_sec, ts.tv_nsec); printf(" time: %9li.%09li\n", ts.tv_sec, ts.tv_nsec);
printf("period: %9li.%09li\n", period.tv_sec, period.tv_nsec); printf("period: %9li.%09li\n", period.tv_sec, period.tv_nsec);
......
...@@ -90,8 +90,8 @@ int main(int argc, char **argv) ...@@ -90,8 +90,8 @@ int main(int argc, char **argv)
if (i != sizeof(ctrl)) if (i != sizeof(ctrl))
goto ctrl_read_error; goto ctrl_read_error;
if (!j) { if (!j) {
if (ctrl.major_version != ZIO_MAJOR_VERSION if (ctrl.major_version != __ZIO_MAJOR_VERSION
|| ctrl.minor_version != ZIO_MINOR_VERSION) { || ctrl.minor_version != __ZIO_MINOR_VERSION) {
fprintf(stderr, "%s: unexpected ZIO version\n", fprintf(stderr, "%s: unexpected ZIO version\n",
argv[0]); argv[0]);
exit(1); exit(1);
......
...@@ -112,18 +112,18 @@ void read_channel(int cfd, int dfd, FILE *log) ...@@ -112,18 +112,18 @@ void read_channel(int cfd, int dfd, FILE *log)
} }
/* Fail badly if the version is not the right one */ /* Fail badly if the version is not the right one */
if (ctrl.major_version != ZIO_MAJOR_VERSION) if (ctrl.major_version != __ZIO_MAJOR_VERSION)
err++; err++;
if (ZIO_MAJOR_VERSION == 0 && ctrl.minor_version != ZIO_MINOR_VERSION) if (__ZIO_MAJOR_VERSION == 0 && ctrl.minor_version != __ZIO_MINOR_VERSION)
err++; err++;
if (err) { if (err) {
fprintf(stderr, "%s: kernel has zio %i.%i, " fprintf(stderr, "%s: kernel has zio %i.%i, "
"but I'm compiled for %i.%i\n", prgname, "but I'm compiled for %i.%i\n", prgname,
ctrl.major_version, ctrl.minor_version, ctrl.major_version, ctrl.minor_version,
ZIO_MAJOR_VERSION, ZIO_MINOR_VERSION); __ZIO_MAJOR_VERSION, __ZIO_MINOR_VERSION);
exit(1); exit(1);
} }
if (ctrl.minor_version != ZIO_MINOR_VERSION) { if (ctrl.minor_version != __ZIO_MINOR_VERSION) {
static int warned; static int warned;
if (!warned++) if (!warned++)
......
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