Coder Social home page Coder Social logo

frugen's Introduction

frugen / libfru

License

This work is dual-licensed under Apache 2.0 and GPL 2.0 (or any later version) for the frugen utility, or under Apache 2.0 and Lesser GPL 2.0 (or any later version) for the fru library.

You can choose between one of them if you use this work.

SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later

Introduction

This project was incepted to eventually create a universal, full-featured IPMI FRU Information generator / editor library and command line tool, written in full compliance with IPMI FRU Information Storage Definition v1.0, rev. 1.3., see http://www.intel.com/content/www/us/en/servers/ipmi/ipmi-platform-mgt-fru-infostorage-def-v1-0-rev-1-3-spec-update.html

libfru

So far supported in libfru:

  • Data encoding into all the defined formats (binary, BCD plus, 6-bit ASCII, language code specific text). The exceptions are:

    • all text is always encoded as if the language code was English (ASCII, 1 byte per character)
    • encoding is selected automatically based on value range of the supplied data, only binary format can be enforced by specifying the length other than LEN_AUTO.
  • Data decoding from all the declared formats. Exception: Unicode is not supported

  • Internal use area creation, with the following limitations:

    • Only from file
    • Only automatic sizing, all data must be specified in the input template file
  • Chassis information area creation

  • Board information area creation

  • Product information area creation

  • Multirecord area creation with the following record types:

    • Management Access Record with the following subtypes:

      • System UUID
  • FRU file creation (in a memory buffer)

NOT supported:

  • Internal use area creation/modification from the command line
  • Miltirecord area record types other than listed above

frugen

The frugen tool supports the following (limitations imposed by the libfru library):

  • Board area creation (including custom fields)
  • Product area creation (including custom fields)
  • Chassis area creation (including custom fields)
  • Multirecord area creation (see libfru supported types above)

The limitations:

  • All data fields (except custom) are always treated as ASCII text, and the encoding is automatically selected based on the byte range of the provided data. Custom fields may be forced to be binary using --binary option.
  • Internal use area is not supported
  • You should specify the UUID and the custom fields in either the template file OR in the command line. The command line does NOT override the template file in that regard, but creates an additional UUID or custom record, which may be undesirable

For the most up-to-date information on the frugen tool invocation and options, please use frugen -h, below is an example of the output of that command:

FRU Generator v1.3.2.g1429f89 (c) 2016-2021, Alexander Amelkin <[email protected]>

Usage: frugen [options] <filename>

Options:

	-h, --help
		Display this help.

	-v, --verbose
		Increase program verbosity (debug) level.

	-b, --binary
		Mark the next --*-custom option's argument as binary.
		Use hex string representation for the next custom argument.

		Example: frugen --binary --board-custom 0012DEADBEAF

		There must be an even number of characters in a 'binary' argument.

	-I, --ascii
		Disable auto-encoding on all fields, force ASCII.
		Out of ASCII range data will still result in binary encoding.

	-j, --json
		Set input text file format to JSON (default). Specify before '--from'.

	-z, --from <argument>
		Load FRU information from a text file.

	-t, --chassis-type <argument>
		Set chassis type (hex). Defaults to 0x02 ('Unknown').

	-a, --chassis-pn <argument>
		Set chassis part number.

	-c, --chassis-serial <argument>
		Set chassis serial number.

	-C, --chassis-custom <argument>
		Add a custom chassis information field, may be used multiple times.

	-n, --board-pname <argument>
		Set board product name.

	-m, --board-mfg <argument>
		Set board manufacturer name.

	-d, --board-date <argument>
		Set board manufacturing date/time, use "DD/MM/YYYY HH:MM:SS" format.
		By default the current system date/time is used unless -u is specified.

	-u, --board-date-unspec
		Don't use current system date/time for board mfg. date, use 'Unspecified'.

	-p, --board-pn <argument>
		Set board part number.

	-s, --board-serial <argument>
		Set board serial number.

	-f, --board-file <argument>
		Set board FRU file ID.

	-B, --board-custom <argument>
		Add a custom board information field, may be used multiple times.

	-N, --prod-name <argument>
		Set product name.

	-G, --prod-mfg <argument>
		Set product manufacturer name.

	-M, --prod-modelpn <argument>
		Set product model / part number.

	-V, --prod-version <argument>
		Set product version.

	-S, --prod-serial <argument>
		Set product serial number.

	-F, --prod-file <argument>
		Set product FRU file ID.

	-A, --prod-atag <argument>
		Set product Asset Tag.

	-P, --prod-custom <argument>
		Add a custom product information field, may be used multiple times.

	-U, --mr-uuid <argument>
		Set System Unique ID (UUID/GUID).

Example:
	frugen --board-mfg "Biggest International Corp." \
	       --board-pname "Some Cool Product" \
	       --board-pn "BRD-PN-123" \
	       --board-date "10/1/2017 12:58:00" \
	       --board-serial "01171234" \
	       --board-file "Command Line" \
	       --binary --board-custom "01020304FEAD1E" \
	       fru.bin

JSON

Dependency: json-c library (https://github.com/json-c/json-c)

The frugen tool supports JSON files. You may specify all the FRU info fields (mind the general tool limitations) in a file and use it as an input for the tool:

frugen --json --from=example.json fru.bin

An example file 'example.json' is provided for your reference.

NOTE: The JSON file for frugen is allowed to have C-style comments (/* comment */), which is an extension to the standard JSON format.

Building

Linux

cmake .
make

Windows (cross-compiled on Linux)

You will need a MingW32 toolchain. This chapter is written in assumption you're using x86_64-w64-mingw32.

First of all you will need to create a x86_64-w64-mingw32-toolchain.cmake file describing your cross-compilation toolchain.

This file assumes that you use $HOME/mingw-install as an installation prefix for all mingw32-compiled libraries (e.g., libjson-c).

# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)

SET(MINGW32_INSTALL_DIR $ENV{HOME}/mingw-install)

# which compilers to use for C and C++
SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)

# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32/ ${MINGW32_INSTALL_DIR})

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search 
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# let the compiler find the includes and linker find the libraries
# MinGW linker doesn't accept absolute library paths found
# by find_library()
include_directories(BEFORE ${MINGW32_INSTALL_DIR}/include)
set(CMAKE_LIBRARY_PATH ${MINGW32_INSTALL_DIR}/lib ${MINGW32_INSTALL_DIR}/usr/lib ${CMAKE_LIBRARY_PATH})

Once you have that file, build the tool as follows:

cmake -DCMAKE_TOOLCHAIN_FILE=x86\_64-w64-mingw32-toolchain.cmake  .
make

Contact information

Should you have any questions or proposals, please feel free to:

frugen's People

Contributors

alexanderamelkin avatar osenft avatar rupan avatar wen00072 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

frugen's Issues

Inconsistent output from 32-bit vs 64-bit builds

After writing the generated data out to a real FRU and running "ipmitool fru print" against it, I noticed that some data looked corrupted or was missing. Long story short, it appears that frugen doesn't produce consistent output. See, for example, two files produced from "example.json". The command line used was ./frugen --from example.json x{86|64}.out. The only difference was that x86.out was produced using a 32-bit build while x64.out was produced using a 64-bit build. I haven't dug into why this is happening, but there is a clear and reproducible difference in the outputs.

Linker errors on Centos 7 build

Was trying to build an RPM of version 1.3 for Centos 7, but got stuck on a linker error before I could even get that far. Any idea what might be causing this?

Starting with the cmake output.

[root@centos7-worker01-aus ~]# cmake3 --version
cmake3 version 3.17.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@centos7-worker01-aus frugen]# cmake3 .
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Using JSON Library found at /usr/lib64/libjson-c.so
-- Configuring done
-- Generating done
-- Build files have been written to: /root/frugen

And the errors from make:

[root@centos7-worker01-aus frugen]# make VERBOSE=1
/usr/bin/cmake3 -S/root/frugen -B/root/frugen --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake3 -E cmake_progress_start /root/frugen/CMakeFiles /root/frugen/CMakeFiles/progre
ss.marks
make  -f CMakeFiles/Makefile2 all   
make[1]: Entering directory `/root/frugen'
make  -f CMakeFiles/fru-shared.dir/build.make CMakeFiles/fru-shared.dir/depend
make[2]: Entering directory `/root/frugen'
cd /root/frugen && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /root/frugen /root/frugen
 /root/frugen /root/frugen /root/frugen/CMakeFiles/fru-shared.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/root/frugen'
make  -f CMakeFiles/fru-shared.dir/build.make CMakeFiles/fru-shared.dir/build
make[2]: Entering directory `/root/frugen'
[ 12%] Building C object CMakeFiles/fru-shared.dir/fru.c.o
/usr/bin/cc -DVERSION=\"v1.2.4.g3bad90e.dirty\" -D__HAS_JSON__ -Dfru_shared_EXPORTS  -fPIC   -o CMakeFiles/fru-shared.dir/fru.c.o   -c /root/frugen/fru.c
/root/frugen/fru.c:25:0: warning: "_BSD_SOURCE" redefined [enabled by default]
 #define _BSD_SOURCE
 ^
In file included from /usr/include/stdint.h:25:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stdint.h:9,
                 from /root/frugen/fru.h:12,
                 from /root/frugen/fru.c:8:
/usr/include/features.h:188:0: note: this is the location of the previous definition
 # define _BSD_SOURCE 1
 ^
[ 25%] Linking C shared library libfru.so
/usr/bin/cmake3 -E cmake_link_script CMakeFiles/fru-shared.dir/link.txt --verbose=1
/usr/bin/cc -fPIC    -shared -Wl,-soname,libfru.so -o libfru.so CMakeFiles/fru-shared.dir/fru.c.o
make[2]: Leaving directory `/root/frugen'
[ 25%] Built target fru-shared
make  -f CMakeFiles/fru-static.dir/build.make CMakeFiles/fru-static.dir/depend
make[2]: Entering directory `/root/frugen'
cd /root/frugen && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /root/frugen /root/frugen /root/frugen /root/frugen /root/frugen/CMakeFiles/fru-static.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/root/frugen'
make  -f CMakeFiles/fru-static.dir/build.make CMakeFiles/fru-static.dir/build
make[2]: Entering directory `/root/frugen'
[ 37%] Building C object CMakeFiles/fru-static.dir/fru.c.o
/usr/bin/cc -DVERSION=\"v1.2.4.g3bad90e.dirty\" -D__HAS_JSON__   -o CMakeFiles/fru-static.dir/fru.c.o   -c /root/frugen/fru.c
/root/frugen/fru.c:25:0: warning: "_BSD_SOURCE" redefined [enabled by default]
 #define _BSD_SOURCE
 ^
In file included from /usr/include/stdint.h:25:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stdint.h:9,
                 from /root/frugen/fru.h:12,
                 from /root/frugen/fru.c:8:
/usr/include/features.h:188:0: note: this is the location of the previous definition
 # define _BSD_SOURCE 1
 ^
[ 50%] Linking C static library libfru.a
/usr/bin/cmake3 -P CMakeFiles/fru-static.dir/cmake_clean_target.cmake
/usr/bin/cmake3 -E cmake_link_script CMakeFiles/fru-static.dir/link.txt --verbose=1
/usr/bin/ar qc libfru.a  CMakeFiles/fru-static.dir/fru.c.o
/usr/bin/ranlib libfru.a
make[2]: Leaving directory `/root/frugen'
[ 50%] Built target fru-static
make  -f CMakeFiles/frugen-static.dir/build.make CMakeFiles/frugen-static.dir/depend
make[2]: Entering directory `/root/frugen'
cd /root/frugen && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /root/frugen /root/frugen /root/frugen /root/frugen /root/frugen/CMakeFiles/frugen-static.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/root/frugen'
make  -f CMakeFiles/frugen-static.dir/build.make CMakeFiles/frugen-static.dir/build
make[2]: Entering directory `/root/frugen'
[ 62%] Building C object CMakeFiles/frugen-static.dir/frugen.c.o
/usr/bin/cc -DVERSION=\"v1.2.4.g3bad90e.dirty\" -D__HAS_JSON__   -o CMakeFiles/frugen-static.dir/frugen.c.o   -c /root/frugen/frugen.c
[ 75%] Linking C executable frugen-static
/usr/bin/cmake3 -E cmake_link_script CMakeFiles/frugen-static.dir/link.txt --verbose=1
/usr/bin/cc     -rdynamic CMakeFiles/frugen-static.dir/frugen.c.o  -o frugen-static  libfru.a -static -ljson-c -static 
/usr/bin/ld: cannot find -ljson-c
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make[2]: *** [frugen-static] Error 1
make[2]: Leaving directory `/root/frugen'
make[1]: *** [CMakeFiles/frugen-static.dir/all] Error 2
make[1]: Leaving directory `/root/frugen'
make: *** [all] Error 2

Here's the rpm-qa output from the build VM I tried this on, so we have all package versioning. I can provide any other relevant output as well if needed.

Ascii encoding failure of field with single dash '-'

I'm not sure if this is a bug or a byproduct of FRU encoding, but the following command fails with Failed to encode custom field. Memory allocation or field length problem.:

frugen --ascii --chassis-custom - out.fru

Using an empty field "", two, or three dashes works.

Add support for GUID record in MultiRecord area

IPMI FRU Information Storage specification 1.0 contains description for a number of record types for MultiRecord area.
Among those types there is "Management Access Record" (type 0x03) that has a subrecord id 0x07 ("System Unique ID").

Support for that record must be added into frugen in order to support system GUIDs for Intel-based systems

Need a way to force specific encoding on standard and custom fields

Currently all standard fields as well as text (non-binary) custom fields are encoded using automatic optimizer that chooses the encoding based on the field data range so that the encoded data occupies least space. That is not always the desired behavior as some FRU decoders may not support or properly support compressed encodings like BCD+ or 6-bit ASCII.

It is thus desirable to have an ability to specify the field encodings explicitly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.