libfru 2.1
FRU Manupulation Library
Loading...
Searching...
No Matches
Macros | Functions | Variables
frugen.c File Reference

FRU generator utility. More...

#include <getopt.h>
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <limits.h>
#include <ctype.h>
#include "fru.h"
#include "fru-errno.h"
#include "frugen.h"
#include "smbios.h"
Include dependency graph for frugen.c:

Macros

#define VERSION   "BROKEN"
 
#define COPYRIGHT_YEARS   "2016-2025"
 
#define MAX_FILE_SIZE   1L * 1024L * 1024L
 
#define _GNU_SOURCE
 
#define debug_dump(level, data, len, fmt, args...)
 
#define DATEBUF_SZ   20
 
#define FRU_FIELD_NOT_PRESENT   (-1)
 

Functions

fru_mr_mgmt_type_t fru_mr_mgmt_type_by_name (const char *name)
 
char * fru_mr_mgmt_name_by_type (fru_mr_mgmt_type_t type)
 
bool datestr_to_tv (const char *datestr, struct timeval *tv)
 
void tv_to_datestr (char *datestr, const struct timeval *tv)
 
fieldopt_t arg_to_fieldopt (char *arg)
 
void load_from_binary_file (const char *fname, const struct frugen_config_s *config, struct frugen_fruinfo_s *info)
 
void load_fromfile (const char *fname, const struct frugen_config_s *config, struct frugen_fruinfo_s *info)
 
void save_to_text_file (FILE **fp, const char *fname, const struct frugen_fruinfo_s *info, const struct frugen_config_s *config)
 
void save_to_binary_file (const char *fname, struct frugen_fruinfo_s *info, const struct frugen_config_s *config)
 
int main (int argc, char *argv[])
 

Variables

volatile int debug_level = 0
 

Detailed Description

FRU generator utility.

Copyright (C) 2016-2024 Alexander Amelkin alexa.nosp@m.nder.nosp@m.@amel.nosp@m.kin..nosp@m.msk.r.nosp@m.u SPDX-License-Identifier: GPL-2.0-or-later OR Apache-2.0

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

◆ COPYRIGHT_YEARS

#define COPYRIGHT_YEARS   "2016-2025"

◆ DATEBUF_SZ

#define DATEBUF_SZ   20

◆ debug_dump

#define debug_dump (   level,
  data,
  len,
  fmt,
  args... 
)
Value:
do { \
debug(level, fmt, ##args); \
if (level <= debug_level) fhexdump(stderr, "DEBUG: ", data, len); \
} while(0)
volatile int debug_level
Definition frugen.c:39

◆ FRU_FIELD_NOT_PRESENT

#define FRU_FIELD_NOT_PRESENT   (-1)

◆ MAX_FILE_SIZE

#define MAX_FILE_SIZE   1L * 1024L * 1024L

◆ VERSION

#define VERSION   "BROKEN"

Function Documentation

◆ arg_to_fieldopt()

fieldopt_t arg_to_fieldopt ( char *  arg)

Split a --set command line option argument string into fields.

The argument format is expected to be:

[<encoding>:]<area>.<field>=

Works for string fields only (i.e. not chassis.type or board.date)

Examples: 6bitascii:product.pn=ABCDEF123 // Force 6-bit ASCII if possible text:procuct.name=SOMEPRODUCT // Force plain text, prevent 6-bit board.serial=Whatever // Autodetect encoding product.custom=Sometext // Autodetect, request addition product.custom.1=Sometext // Autodetect, request replacement of field 1

Returns field_opt_t structure. Terminates the program on parsing failure.

WARNING: Modifies the input string.

References fieldopt_t::area, fieldopt_t::custom_index, debug, fatal, fieldopt_t::field, fru_enc_name_by_type(), fru_enc_type_by_name(), FRU_FIELD_CUSTOM, FRU_FIELD_NOT_PRESENT, fieldopt_t::index, fieldopt_t::type, and fieldopt_t::value.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ datestr_to_tv()

bool datestr_to_tv ( const char *  datestr,
struct timeval *  tv 
)

Convert local date/time string to UTC time in seconds for FRU

Referenced by load_from_json_file(), and main().

Here is the caller graph for this function:

◆ fru_mr_mgmt_name_by_type()

char * fru_mr_mgmt_name_by_type ( fru_mr_mgmt_type_t  type)

Get Multirecord Area Record name by its type

Reverse of fru_mr_mgmt_type_by_name(). Returns an allocated copy of the name string, don't forget to free it.

References fatal, and MGMT_TYPE_ID.

◆ fru_mr_mgmt_type_by_name()

fru_mr_mgmt_type_t fru_mr_mgmt_type_by_name ( const char *  name)

Find a Management Access record subtype by its short name

Takes a short name of the subtype from the following list and returs the ID as per Table 18-6.

Terminates the program on failure.

Parameters
[in]nameThe short name of the type: surl = System URL sname = System Name spingaddr = System ping address curl = Component URL cname = Component name cpingaddr = Component ping address uuid = System UUID
Returns
The ID of the subtype as per Table 18-6 of IPMI FRU Spec
Return values
1..7The subtype ID

References fatal.

◆ load_from_binary_file()

void load_from_binary_file ( const char *  fname,
const struct frugen_config_s config,
struct frugen_fruinfo_s info 
)

◆ load_fromfile()

void load_fromfile ( const char *  fname,
const struct frugen_config_s config,
struct frugen_fruinfo_s info 
)

References fatal, frugen_config_s::format, FRUGEN_FMT_BINARY, FRUGEN_FMT_JSON, load_from_binary_file(), and load_from_json_file().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ save_to_binary_file()

void save_to_binary_file ( const char *  fname,
struct frugen_fruinfo_s info,
const struct frugen_config_s config 
)

Save the encoded FRU from info into a binary file specified by fname.

Parameters
[in]fnameFilename to open when *fp is NULL, may be NULL otherwise
[in]infoThe FRU information structure to get the FRU data from
[in]configVarious frugen configuration settings structure

References frugen_fruinfo_s::areas, debug, debug_dump, fatal, frugen_fruinfo_s::fru, fru_create(), fru_encode_board_info(), fru_encode_chassis_info(), fru_encode_internal_use_area(), fru_encode_mr_area(), fru_encode_product_info(), fru_errno, fru_strerr(), frugen_fruinfo_s::has_bdate, frugen_fruinfo_s::has_board, frugen_fruinfo_s::has_chassis, frugen_fruinfo_s::has_internal, frugen_fruinfo_s::has_multirec, frugen_fruinfo_s::has_product, and frugen_config_s::no_curr_date.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_to_text_file()

void save_to_text_file ( FILE **  fp,
const char *  fname,
const struct frugen_fruinfo_s info,
const struct frugen_config_s config 
)

Save the decoded FRU from info into a text file specified by *fp or fname.

Parameters
[in,out]fpPointer to the file pointer to use for output. If *fp is NULL, fname will be opened, and the pointer to it will be stored in *fp.
[in]fnameFilename to open when *fp is NULL, may be NULL otherwise
[in]infoThe FRU information structure to get the FRU data from
[in]configVarious frugen configuration settings structure

References frugen_fruinfo_s::areas, fatal, frugen_fruinfo_s::fru, fru_enc_name_by_type(), fru_encode_internal_use_area(), fru_errno, fru_strerr(), frugen_fruinfo_s::has_board, frugen_fruinfo_s::has_chassis, frugen_fruinfo_s::has_internal, frugen_fruinfo_s::has_multirec, frugen_fruinfo_s::has_product, and tv_to_datestr().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tv_to_datestr()

void tv_to_datestr ( char *  datestr,
const struct timeval *  tv 
)

Convert FRU time (in UTC) to a local date/time string

Referenced by save_to_json_file(), and save_to_text_file().

Here is the caller graph for this function:

Variable Documentation

◆ debug_level

volatile int debug_level = 0

Referenced by main().