Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
Beam Positoning Monitor - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Beam Positoning Monitor - Software
Commits
95e8921e
Commit
95e8921e
authored
Jul 26, 2016
by
Lucas Russo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libs/libsdbutils/*: add SDB utilities library
parent
8f074106
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
706 additions
and
0 deletions
+706
-0
Makefile
src/libs/libsdbutils/Makefile
+186
-0
README.deps
src/libs/libsdbutils/README.deps
+5
-0
compile.sh
src/libs/libsdbutils/compile.sh
+40
-0
sdbutils.h
src/libs/libsdbutils/include/sdbutils.h
+13
-0
sdbutils_classes.h
src/libs/libsdbutils/include/sdbutils_classes.h
+48
-0
sdbutils_core.h
src/libs/libsdbutils/include/sdbutils_core.h
+36
-0
sdbutils_err.h
src/libs/libsdbutils/include/sdbutils_err.h
+36
-0
sdbutils_prelude.h
src/libs/libsdbutils/include/sdbutils_prelude.h
+16
-0
sdbutils_core.c
src/libs/libsdbutils/src/sdbutils_core.c
+271
-0
sdbutils_err.c
src/libs/libsdbutils/src/sdbutils_err.c
+25
-0
version.sh
src/libs/libsdbutils/version.sh
+30
-0
No files found.
src/libs/libsdbutils/Makefile
0 → 100644
View file @
95e8921e
# Set your cross compile prefix with CROSS_COMPILE variable
CROSS_COMPILE
?=
CMDSEP
=
;
CC
?=
$(CROSS_COMPILE)
gcc
AR
?=
$(CROSS_COMPILE)
ar
LD
?=
$(CROSS_COMPILE)
ld
OBJDUMP
?=
$(CROSS_COMPILE)
objdump
OBJCOPY
?=
$(CROSS_COMPILE)
objcopy
SIZE
?=
$(CROSS_COMPILE)
size
MAKE
?=
make
PWD
=
$(
shell
pwd
)
LIBNAME_RAW
=
sdbutils
LIBNAME
=
lib
$(LIBNAME_RAW)
# Config variables suitable for creating shared libraries
LIB_VER
=
$(
shell
./version.sh
$(LIBNAME_RAW))
LIB_VER_MAJOR
=
$(
shell
echo
$(LIB_VER)
|
cut
-d
'.'
-f1
)
LIB_VER_MINOR
=
$(
shell
echo
$(LIB_VER)
|
cut
-d
'.'
-f2
)
LIB_VER_REVESION
=
$(
shell
echo
$(LIB_VER)
|
cut
-d
'.'
-f3
)
PREFIX
?=
/usr/local
export
PREFIX
# General C/CPP flags
CFLAGS_USR
=
-std
=
gnu99
-O2
-fPIC
# We expect tghese variables to be appended to the possible
# command-line options
override
CPPFLAGS
+=
override
CXXFLAGS
+=
# To enable this option, use: make ERRHAND_DBG=y
ifneq
($(ERRHAND_DBG),)
CFLAGS_DEBUG
+=
-DERRHAND_DBG
=
$(ERRHAND_DBG)
endif
# To enable this option use: make ERRHAND_MIN_LEVEL=DBG_MIN_TRACE
ifneq
($(ERRHAND_MIN_LEVEL),)
CFLAGS_DEBUG
+=
-DERRHAND_MIN_LEVEL
=
$(ERRHAND_MIN_LEVEL)
endif
# To enable this option use: make ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | \
# DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
#
# You can also OR the available subsytems to enable debug messages in just the
# those subsytems. See file errhand_opts.h for more information
ifneq
($(ERRHAND_SUBSYS_ON),)
CFLAGS_DEBUG
+=
-DERRHAND_SUBSYS_ON
=
$(ERRHAND_SUBSYS_ON)
endif
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG
+=
-g
# Specific platform Flags
CFLAGS_PLATFORM
=
-Wall
-Wextra
-Werror
LDFLAGS_PLATFORM
=
# Libraries
LIBS
=
# General library flags -L<libdir>
LFLAGS
=
# Source directory
SRC_DIR
=
src
# Include directory
INCLUDE_DIR
=
include
# Include directories
# FIXME. Needed so we can find libsdbfs headers
INCLUDE_DIRS
=
-Iinclude
-I
${
PREFIX
}
/include
\
-I
../../../foreign/libsdbfs
\
-I
../../../include
# Merge all flags. We expect tghese variables to be appended to the possible
# command-line options
override
CFLAGS
+=
$(CFLAGS_USR)
$(CFLAGS_PLATFORM)
$(CFLAGS_DEBUG)
$(CPPFLAGS)
$(CXXFLAGS)
override
LDFLAGS
+=
$(LFLAGS)
$(LDFLAGS_PLATFORM)
# Output library names
OUT
=
$(LIBNAME)
.SECONDEXPANSION
:
# Library objects
$(LIBNAME)
_OBJS_LIB
=
\
$(SRC_DIR)
/sdbutils_core.o
\
$(SRC_DIR)
/sdbutils_err.o
# Objects common for this library
common_OBJS
=
# Objects for each version of library
$(LIBNAME)
_OBJS
=
$(common_OBJS)
$
(
$(LIBNAME)
_OBJS_LIB
)
$(LIBNAME)
_CODE_HEADERS
=
\
$(INCLUDE_DIR)
/sdbutils_classes.h
\
$(INCLUDE_DIR)
/sdbutils_prelude.h
\
$(INCLUDE_DIR)
/sdbutils.h
\
$(INCLUDE_DIR)
/sdbutils_core.h
\
$(INCLUDE_DIR)
/sdbutils_err.h
$(LIBNAME)
_HEADERS
=
$
(
$(LIBNAME)
_CODE_HEADERS
)
OBJS_all
=
$(common_OBJS)
$
(
$(LIBNAME)
_OBJS
)
# Libraries suffixes
LIB_STATIC_SUFFIX
=
.a
LIB_SHARED_SUFFIX
=
.so
# Generate suitable names for static libraries
# Generate suitable names for static libraries
TARGET_STATIC
=
$
(
addsuffix
$(LIB_STATIC_SUFFIX)
,
$(OUT)
)
TARGET_SHARED
=
$
(
addsuffix
$(LIB_SHARED_SUFFIX)
,
$(OUT)
)
TARGET_SHARED_VER
=
$
(
addsuffix
$(LIB_SHARED_SUFFIX)
.
$(LIB_VER)
,
$(OUT)
)
.PHONY
:
all clean mrproper install uninstall
# Avoid deletion of intermediate files, such as objects
.SECONDARY
:
$(OBJS_all)
# Makefile rules
all
:
$(TARGET_STATIC) $(TARGET_SHARED_VER)
# Compile static library
%.a
:
$$($$*_OBJS)
$(AR)
rcs
$@
$^
# Compile dynamic library
%.so.$(LIB_VER)
:
$$($$*_OBJS) $(OBJ_REVISION)
$(CC)
$(LDFLAGS)
-shared
-fPIC
-Wl
,-soname,
$@
-o
$@
$^
# Pull in dependency info for *existing* .o files and don't complain if the
# corresponding .d file is not found
-include $(OBJS_all
:
.o=.d)
# Compile with position-independent objects.
# Autodependencies generatation by Scott McPeak, November 2001,
# from article "Autodependencies with GNU make"
%.o
:
%.c
$(CC)
$(CFLAGS)
$(INCLUDE_DIRS)
-c
$*
.c
-o
$@
# create the dependency files "target: pre-requisites"
${CC}
-MM
$(CFLAGS)
$(INCLUDE_DIRS)
$*.c
>
$*.d
# Workaround to make objects in different folders have
# the correct target path. e.g., "dir/bar.o: dir/bar.c dir/foo.h"
# instead of "bar.o: dir/bar.c dir/foo.h"
@mv
-f
$*.d
$*.d.tmp
@sed -e 's|.*
:
|$*.o:|' < $*.d.tmp > $*.d
# All prereqs listed will also become command-less,
# prereq-less targets. In this way, the prereq file will be
# treated as changed and the target will be rebuilt
# sed: strip the target (everything before colon)
# sed: remove any continuation backslashes
# fmt -1: list words one per line
# sed: strip leading spaces
# sed: add trailing colons
@sed -e 's/.*
:
//' -e 's/
\\
$$//' < $*.d.tmp | fmt -1 |
\
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@
rm
-f
$*
.d.tmp
install
:
$
(
foreach lib,
$(TARGET_SHARED_VER)
,install
-m
755
$(lib)
$(PREFIX)
/lib
$(CMDSEP)
)
$
(
foreach lib,
$(TARGET_SHARED)
,ln
-sf
$(lib)
.
$(LIB_VER)
$(PREFIX)
/lib/
$(lib)
$(CMDSEP)
)
$
(
foreach lib,
$(TARGET_SHARED)
,ln
-sf
$(lib)
.
$(LIB_VER)
$(PREFIX)
/lib/
$(lib)
.
$(LIB_VER_MAJOR)
$(CMDSEP)
)
$
(
foreach lib,
$(TARGET_STATIC)
,install
-m
755
$(lib)
$(PREFIX)
/lib
$(CMDSEP)
)
$
(
foreach header,
$
(
$(LIBNAME)
_HEADERS
)
,install
-m
755
$(header)
$(PREFIX)
/include
$(CMDSEP)
)
uninstall
:
$
(
foreach lib,
$(TARGET_SHARED)
,rm
-f
$(PREFIX)
/lib/
$(lib)
.
$(LIB_VER)
$(CMDSEP)
)
$
(
foreach lib,
$(TARGET_SHARED)
,rm
-f
$(PREFIX)
/lib/
$(lib)
$(CMDSEP)
)
$
(
foreach lib,
$(TARGET_SHARED)
,rm
-f
$(PREFIX)
/lib/
$(lib)
.
$(LIB_VER_MAJOR)
$(CMDSEP)
)
$
(
foreach lib,
$(TARGET_STATIC)
,rm
-f
$(PREFIX)
/lib/
$(lib)
$(CMDSEP)
)
$
(
foreach header,
$
(
notdir
$
(
$(LIBNAME)
_HEADERS
))
,rm
-f
\
$(PREFIX)
/include/
$(header)
$(CMDSEP)
)
clean
:
rm
-f
$(OBJS_all)
$
(
OBJS_all:.o
=
.d
)
mrproper
:
clean
rm
-f
*
.a
*
.so.
$(LIB_VER)
src/libs/libsdbutils/README.deps
0 → 100644
View file @
95e8921e
Project Dependencies:
liberrhand
Foreign Dependencies:
libsdbfs
src/libs/libsdbutils/compile.sh
0 → 100755
View file @
95e8921e
#!/usr/bin/env bash
#######################################
# All of our Makefile options
#######################################
EXTRA_FLAGS
=
$1
#Select if we want to compile with debug mode on. Options are: y(es) or n(o)
ERRHAND_DBG
=
y
# Select the minimum debug verbosity. See liberrhand file errhand_opts.h for more info.
ERRHAND_MIN_LEVEL
=
DBG_LVL_INFO
# Select the subsytems which will have the debug on. See liberrhand file errhand_opts.h for more info.
ERRHAND_SUBSYS_ON
=
'"(DBG_DEV_MNGR | DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
# Select the FMC ADC board type. Options are: passive or active
COMMAND_LIBSDBUTILS
=
"
\
make
\
${
EXTRA_FLAGS
}
\
ERRHAND_DBG=
${
ERRHAND_DBG
}
\
ERRHAND_MIN_LEVEL=
${
ERRHAND_MIN_LEVEL
}
\
ERRHAND_SUBSYS_ON='"
${
ERRHAND_SUBSYS_ON
}
"' &&
\
sudo make install"
COMMAND_ARRAY
=(
"
${
COMMAND_LIBSDBUTILS
}
"
)
for
i
in
"
${
COMMAND_ARRAY
[@]
}
"
do
echo
"Executing: "
$i
eval
$i
# Check return value
rc
=
$?
if
[[
$rc
!=
0
]]
;
then
exit
$rc
fi
done
src/libs/libsdbutils/include/sdbutils.h
0 → 100644
View file @
95e8921e
/*
* Copyright (C) 2016 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU GPL, version 3 or any later version.
*/
#ifndef _SDBUTILS_H_
#define _SDBUTILS_H_
#include "sdbutils_classes.h"
#endif
src/libs/libsdbutils/include/sdbutils_classes.h
0 → 100644
View file @
95e8921e
/*
* Copyright (C) 2016 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU GPL, version 3 or any later version.
*/
#ifndef _SDBUTILS_CLASSES_H_
#define _SDBUTILS_CLASSES_H_
/* External dependencies */
#include <czmq.h>
#include <errhand.h>
#include <libsdbfs.h>
/* version macros for compile-time API detection */
#define SDBUTILS_VERSION_MAJOR 0
#define SDBUTILS_VERSION_MINOR 1
#define SDBUTILS_VERSION_PATCH 0
#define SDBUTILS_MAKE_VERSION(major, minor, patch) \
((major) * 10000 + (minor) * 100 + (patch))
#define SDBUTILS_VERSION \
SDBUTILS_MAKE_VERSION(SDBUTILS_VERSION_MAJOR, SDBUTILS_VERSION_MINOR, \
SDBUTILS_VERSION_PATCH)
#if defined (__WINDOWS__)
# if defined LIBSDBUTILS_STATIC
# define SDBUTILS_EXPORT
# elif defined LIBSDBUTILS_EXPORTS
# define SDBUTILS_EXPORT __declspec(dllexport)
# else
# define SDBUTILS_EXPORT __declspec(dllimport)
# endif
#else
# define SDBUTILS_EXPORT
#endif
/* Opaque class structures to allow forward references */
/* Public API classes */
/* SDBUTILS */
#include "sdbutils_err.h"
#include "sdbutils_core.h"
#endif
src/libs/libsdbutils/include/sdbutils_core.h
0 → 100644
View file @
95e8921e
/*
* Copyright (C) 2016 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU GPL, version 3 or any later version.
*/
#ifndef _SDBUTILS_CORE_H_
#define _SDBUTILS_CORE_H_
#ifdef __cplusplus
extern
"C"
{
#endif
/* Print device as ASCII */
sdbutils_err_e
sdbutils_list_device
(
struct
sdb_device
*
d
,
int
depth
,
int
base
,
int
opt_long
);
/* Print whole SDBFS as ASCII */
sdbutils_err_e
sdbutils_do_list
(
struct
sdbfs
*
fs
,
int
opt_long
);
/* Search for device name and print device */
sdbutils_err_e
sdbutils_do_cat_name
(
struct
sdbfs
*
fs
,
char
*
name
);
/* Search for device Vendor/ID and print device */
sdbutils_err_e
sdbutils_do_cat_id
(
struct
sdbfs
*
fs
,
uint64_t
vendor
,
uint32_t
dev
);
/* Return next device on current SDB position */
struct
sdb_device
*
sdbutils_next_device
(
struct
sdbfs
*
fs
);
#ifdef __cplusplus
}
#endif
#endif
src/libs/libsdbutils/include/sdbutils_err.h
0 → 100644
View file @
95e8921e
/*
* Copyright (C) 2016 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU GPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#ifndef _SDBUTILS_ERR_H_
#define _SDBUTILS_ERR_H_
#ifdef __cplusplus
extern
"C"
{
#endif
enum
_sdbutils_err_e
{
SDBUTILS_SUCCESS
=
0
,
/* No error */
SDBUTILS_ERR_ALLOC
,
/* Could not allocate memory */
SDBUTILS_ERR_OPEN
,
/* Could not open SDBFS */
SDBUTILS_ERR_UNK_REC
,
/* Unknown record type */
SDBUTILS_ERR_END
};
typedef
enum
_sdbutils_err_e
sdbutils_err_e
;
/* Convert enumeration type to string */
const
char
*
sdbutils_err_str
(
sdbutils_err_e
err
);
#ifdef __cplusplus
}
#endif
#endif
src/libs/libsdbutils/include/sdbutils_prelude.h
0 → 100644
View file @
95e8921e
/*
* Copyright (C) 2016 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU GPL, version 3 or any later version.
*/
#ifndef _SDBUTILS_PRELUDE_H_
#define _SDBUTILS_PRELUDE_H_
/* External dependencies */
#include <inttypes.h>
#include <sys/types.h>
#include <stdbool.h>
#endif
src/libs/libsdbutils/src/sdbutils_core.c
0 → 100644
View file @
95e8921e
/*
* Copyright (C) 2016 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU GPL, version 3 or any later version.
*/
#include "sdbutils.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label,
/* err_core */
...) \
ASSERT_HAL_TEST(test_boolean, HAL_UTILS, "[sdbutils:utils]", \
err_str, err_goto_label,
/* err_core */
__VA_ARGS__)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label,
/* err_core */
...) \
ASSERT_HAL_ALLOC(ptr, HAL_UTILS, "[sdbutils:utils]", \
sdbutils_err_str(SDBUTILS_ERR_ALLOC), \
err_goto_label,
/* err_core */
__VA_ARGS__)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, HAL_UTILS, "[sdbutils:utils]", \
sdbutils_err_str (err_type))
/*******************************************************************/
/********************* SDB Utilities functions ********************/
/*******************************************************************/
/* Copied from libsdbfs/tools/sdb-read, located at:
* git://ohwr.org/hdl-core-lib/fpga-config-space.git */
/* Boring ascii representation of a device */
sdbutils_err_e
sdbutils_list_device
(
struct
sdb_device
*
d
,
int
depth
,
int
base
,
int
opt_long
)
{
sdbutils_err_e
err
=
SDBUTILS_SUCCESS
;
struct
sdb_product
*
p
;
struct
sdb_component
*
c
;
struct
sdb_synthesis
*
s
;
unsigned
char
*
data
;
int
i
;
c
=
&
d
->
sdb_component
;
p
=
&
c
->
product
;
s
=
(
void
*
)
d
;
/* Different sdb items are listed in different ways */
switch
(
p
->
record_type
)
{
/* The following items are components, and are listed as such */
case
sdb_type_interconnect
:
case
sdb_type_device
:
case
sdb_type_bridge
:
if
(
!
opt_long
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%.19s
\n
"
,
p
->
name
);
return
SDBUTILS_SUCCESS
;
}
/* hack: show directory level looking at the internals */
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%016llx:%08x @ %08llx-%08llx "
,
(
long
long
)
ntohll
(
p
->
vendor_id
),
ntohl
(
p
->
device_id
),
(
long
long
)
base
+
ntohll
(
c
->
addr_first
),
(
long
long
)
base
+
ntohll
(
c
->
addr_last
));
for
(
i
=
0
;
i
<
depth
;
i
++
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
" "
);
}
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%.19s
\n
"
,
p
->
name
);
return
SDBUTILS_SUCCESS
;
/* A product, but not a component (no address range) */
case
sdb_type_integration
:
if
(
!
opt_long
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%.19s
\n
"
,
p
->
name
);
return
SDBUTILS_SUCCESS
;
}
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%016llx:%08x "
,
(
long
long
)
ntohll
(
p
->
vendor_id
),
ntohl
(
p
->
device_id
));
/* like above, show directory level */
for
(
i
=
0
;
i
<
depth
;
i
++
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
" "
);
}
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%.19s
\n
"
,
p
->
name
);
return
SDBUTILS_SUCCESS
;
/* Just a string */
case
sdb_type_repo_url
:
if
(
opt_long
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"repo-url: %.63s
\n
"
,
((
struct
sdb_repo_url
*
)
d
)
->
repo_url
);
}
return
SDBUTILS_SUCCESS
;
/* Some metadata */
case
sdb_type_synthesis
:
if
(
!
opt_long
)
{
return
SDBUTILS_SUCCESS
;
}
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"synthesis-name: %.16s
\n
"
,
s
->
syn_name
);
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
" commit-id: "
);
for
(
i
=
0
;
i
<
(
int
)
sizeof
(
s
->
commit_id
);
i
++
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%02x"
,
s
->
commit_id
[
i
]);
}
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"
\n
"
);
/* Some of the following fields are sometimes empty */
if
(
s
->
tool_name
[
0
]
&&
s
->
tool_name
[
0
]
!=
' '
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
" tool-name: %.8s
\n
"
,
s
->
tool_name
);
}
if
(
s
->
tool_version
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
" tool-version: 0x%08x
\n
"
,
ntohl
(
s
->
tool_version
));
}
if
(
s
->
date
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
" build-date: %08x
\n
"
,
ntohl
(
s
->
date
));
}
if
(
s
->
user_name
[
0
]
&&
s
->
tool_name
[
0
]
!=
' '
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
" build-user: %.15s
\n
"
,
s
->
user_name
);
}
return
SDBUTILS_SUCCESS
;
case
sdb_type_empty
:
return
SDBUTILS_SUCCESS
;
default:
break
;
}
/* Unknown record type */
if
(
p
->
record_type
&
0x80
)
{
err
=
SDBUTILS_SUCCESS
;
}
else
{
err
=
SDBUTILS_ERR_UNK_REC
;
}
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_WARN
,
"Unknown record type 0x%02x
\n
"
,
p
->
record_type
);
if
(
!
opt_long
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"Unknown-record
\n
"
);
return
err
;
}
/* long listing of unknown record */
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"Unknown-record:
\n
"
);
data
=
(
void
*
)
d
;
for
(
i
=
0
;
i
<
(
int
)
sizeof
(
struct
sdb_empty
);
i
++
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%s%02x%c"
,
(
i
&
0xf
)
==
0
?
" "
:
""
,
data
[
i
],
(
i
&
0xf
)
==
0xf
?
'\n'
:
' '
);
}
return
err
;
}
sdbutils_err_e
sdbutils_do_list
(
struct
sdbfs
*
fs
,
int
opt_long
)
{
sdbutils_err_e
err
=
SDBUTILS_SUCCESS
;
struct
sdb_device
*
d
;
int
new
=
1
;
while
(
(
d
=
sdbfs_scan
(
fs
,
new
))
!=
NULL
)
{
err
=
sdbutils_list_device
(
d
,
fs
->
depth
,
fs
->
base
[
fs
->
depth
],
opt_long
);
ASSERT_TEST
(
err
==
SDBUTILS_SUCCESS
,
"Could not list device"
,
err_list_device
,
SDBUTILS_ERR_ALLOC
);
new
=
0
;
}
err_list_device:
return
err
;
}
sdbutils_err_e
sdbutils_do_cat_name
(
struct
sdbfs
*
fs
,
char
*
name
)
{
sdbutils_err_e
err
=
SDBUTILS_SUCCESS
;
char
buf
[
4096
];
int
i
;
i
=
sdbfs_open_name
(
fs
,
name
);
if
(
i
<
0
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_WARN
,
"%s: %s
\n
"
,
name
,
strerror
(
-
i
));
err
=
SDBUTILS_ERR_OPEN
;
goto
err_open_name
;
}
while
(
(
i
=
sdbfs_fread
(
fs
,
-
1
,
buf
,
sizeof
(
buf
)))
>
0
)
{
/* Convert bytes to C-string */
const
int
namesize
=
i
;
char
name
[
namesize
+
1
];
memcpy
(
name
,
buf
,
i
);
name
[
namesize
]
=
'\0'
;
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%s
\n
"
,
name
);
}
sdbfs_close
(
fs
);
err_open_name:
return
err
;
}
sdbutils_err_e
sdbutils_do_cat_id
(
struct
sdbfs
*
fs
,
uint64_t
vendor
,
uint32_t
dev
)
{
sdbutils_err_e
err
=
SDBUTILS_SUCCESS
;
char
buf
[
4096
];
int
i
;
i
=
sdbfs_open_id
(
fs
,
htonll
(
vendor
),
htonl
(
dev
));
if
(
i
<
0
)
{
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_WARN
,
"%016"
PRIx64
"-%08x: %s
\n
"
,
vendor
,
dev
,
strerror
(
-
i
));
err
=
SDBUTILS_ERR_OPEN
;
goto
err_open_id
;
}
while
(
(
i
=
sdbfs_fread
(
fs
,
-
1
,
buf
,
sizeof
(
buf
)))
>
0
)
{
/* Convert bytes to C-string */
const
int
namesize
=
i
;
char
name
[
namesize
+
1
];
memcpy
(
name
,
buf
,
i
);
name
[
namesize
]
=
'\0'
;
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"%s
\n
"
,
name
);
}
sdbfs_close
(
fs
);
err_open_id:
return
err
;
}
struct
sdb_device
*
sdbutils_next_device
(
struct
sdbfs
*
fs
)
{
struct
sdb_device
*
d
;
struct
sdb_product
*
p
;
struct
sdb_component
*
c
;
/* Search for the next device and return it */
while
((
d
=
sdbfs_scan
(
fs
,
0
))
!=
NULL
)
{
c
=
&
d
->
sdb_component
;
p
=
&
c
->
product
;
if
(
p
->
record_type
==
sdb_type_device
)
{
int
base
=
fs
->
base
[
fs
->
depth
];
/* hack: show directory level looking at the internals */
DBE_DEBUG
(
DBG_HAL_UTILS
|
DBG_LVL_INFO
,
"[sdbutils] Device
\"
%.19s
\"
found:
\n
"
"
\t
%016llx:%08x @ %08llx-%08llx "
,
p
->
name
,
(
long
long
)
ntohll
(
p
->
vendor_id
),
ntohl
(
p
->
device_id
),
(
long
long
)
base
+
ntohll
(
c
->
addr_first
),
(
long
long
)
base
+
ntohll
(
c
->
addr_last
));
return
d
;
}
}
return
NULL
;
}
src/libs/libsdbutils/src/sdbutils_err.c
0 → 100644
View file @
95e8921e
/*
* Copyright (C) 2016 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU GPL, version 3 or any later version.
*/
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#include "sdbutils.h"
static
const
char
*
sdbutils_err
[
SDBUTILS_ERR_END
]
=
{
[
SDBUTILS_SUCCESS
]
=
"Success"
,
[
SDBUTILS_ERR_ALLOC
]
=
"Could not allocate memory"
,
[
SDBUTILS_ERR_OPEN
]
=
"Could not open SDBFS"
,
[
SDBUTILS_ERR_UNK_REC
]
=
"Unknown record type"
};
/* Convert enumeration type to string */
const
char
*
sdbutils_err_str
(
sdbutils_err_e
err
)
{
return
sdbutils_err
[
err
];
}
src/libs/libsdbutils/version.sh
0 → 100755
View file @
95e8921e
#!/usr/bin/env sh
#
# This script extracts the version from the project header file
#
# This script is based on CZMQ version.sh script located at:
# https://github.com/zeromq/czmq/blob/master/version.sh
project
=
$1
appendix
=
"_classes"
if
[
!
-f
include/
$project$appendix
.h
]
;
then
echo
"version.sh: error: could not open file include/
$project$appendix
.h"
1>&2
exit
1
fi
MAJOR
=
`
egrep
'^#define .*_VERSION_MAJOR +[0-9]+$'
include/
$project$appendix
.h
`
MINOR
=
`
egrep
'^#define .*_VERSION_MINOR +[0-9]+$'
include/
$project$appendix
.h
`
PATCH
=
`
egrep
'^#define .*_VERSION_PATCH +[0-9]+$'
include/
$project$appendix
.h
`
if
[
-z
"
$MAJOR
"
-o
-z
"
$MINOR
"
-o
-z
"
$PATCH
"
]
;
then
echo
"version.sh: error: could not extract version from include/
$project$appendix
.h"
1>&2
exit
1
fi
MAJOR
=
`
echo
$MAJOR
|
awk
'{ print $3 }'
`
MINOR
=
`
echo
$MINOR
|
awk
'{ print $3 }'
`
PATCH
=
`
echo
$PATCH
|
awk
'{ print $3 }'
`
echo
$MAJOR
.
$MINOR
.
$PATCH
|
tr
-d
'\n'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment