-
Notifications
You must be signed in to change notification settings - Fork 23
Add support for reading from a raw fru dump #28
base: feature/fru-reader
Are you sure you want to change the base?
Conversation
2496dce to
5395299
Compare
|
Fixed custom fields: |
6101093 to
eb44561
Compare
|
Fixed time decoding: |
|
I think, the only thing left to do for now is JSON dump. |
eb44561 to
edbda15
Compare
|
I think, it's ready for review. Basic command usage
fugen-static -j -z example.json example.bin
frugen-static -r -z example.bin > example2.json
frugen-static -r -z example.bin | jq
More involved example: parse FRU dump, replace one of the fields and save to JSON file frugen-static -r -z example.bin | jq '.board.file.data |= "otherexample.json"' > otherexample.jsonMotivation
As may be seen from the examples above, dumping parsed data to stdout is more flexible than just using FRU dump in new dump generation:
Further workInternal area and multi-record parsers are not implemented yet. |
|
It's not very convenient to use functions defined in |
7be4aac to
ba93e3c
Compare
|
Refactored decoder functions a bit for better library API |
fc5dddf to
8a11d16
Compare
AlexanderAmelkin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thank you for the effort! Then, there are some things I'd like to improve.
| #endif | ||
| } | ||
| else if (use_binary) { | ||
| int fd = open(optarg, O_RDONLY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this and the above json block need to be extracted into separate functions like load_binary() and load_json() respectively. With a separate commit, as a refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that these functions belong to fru library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough
|
I've pushed edits, resolving most of the notes. Later, I will squash commits and split changed into separate commits, but first, library API and CLI arguments need to be thought over. |
5204a07 to
8a1691d
Compare
fru.c
Outdated
| uint32_t val; | ||
| uint8_t arr[4]; | ||
| } min_since_1996_big_endian; | ||
| min_since_1996_big_endian.val = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could as well add = { 0 }; at the end of the declaration above.
I don't insist though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to assign 0 to val after min_since_1996_big_endian = {0}, also please make it { 0 }.
|
|
fru.c
Outdated
| uint32_t val; | ||
| uint8_t arr[4]; | ||
| } min_since_1996_big_endian; | ||
| min_since_1996_big_endian.val = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to assign 0 to val after min_since_1996_big_endian = {0}, also please make it { 0 }.
fru.c
Outdated
|
|
||
| field = (fru_field_t*)data; | ||
| if (!fru_decode_data(field, &product_out->mfg, | ||
| sizeof(product_out->mfg.val))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this second line aligned to? I don't see it.
If this is not an alignment, then please use tabs.
When mixing indentation with alignment (like here), please use tabs for indentation and spaces for alignment. That way it wont visually break in editors that use a different tab size:
if (!fru_decode_data(field, &product_out->mfg,
sizeof(product_out->mfg.val)))This applies to the below cases as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, what you did is not exactly what I meant by 'tabs for indentation, spaces for alignment'.
If you change tab size, this is still going to break.
This is 1 level on indent, hence it must be just 1 tab. The rest must be spaces.
There are lots of other places like this too.
frugen.c
Outdated
| free(buffer); | ||
| } | ||
| else { | ||
| fatal("The requested input file format is not supported"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it looks more like "Please specify the input file format"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't actually resolve this, did you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this edit got lost during the commit split
|
I've updated the code according to your comments and split it into separate commits.
I propose to leave these improvements for the separate PR. |
frugen.c
Outdated
| free(buffer); | ||
| } | ||
| else { | ||
| fatal("The requested input file format is not supported"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't actually resolve this, did you?
I agree that those changes can go in separate PRs. |
|
Since there're a lot of indentation problems, maybe it would be better to add a formatting rules for clang-format or indent. |
As far as I'm aware, clang-format doesn't support the concept of 'tabs for indent, spaces for alignment', and I wouldn't like to use any less. If you know how to teach it that, please tell. I will look into |
I think it is using it: fru.c.txt |
cf7d75d to
9abaf70
Compare


This is a squashed and rebased PR #9.
It works for the most part, except for custom fields, time and
multi-records.Source file:
{ /* The internal use area, if specified, must list all the data as hex string, the length is calculated automatically */ "internal" : "010203040A0B0C0D", "chassis" : { "type": 10, "pn" : "CHAS-C00L-12", /* Fields may be given explicit types by setting to object with keys `type` and `data`*/ /* Supported types are: "bcdplus", "6bitascii" and "text" */ "serial": { "type": "bcdplus", "data": "45678" }, "custom" : [ { "data" : "Auto-typed text custom field" }, { "type" : "binary", "data": "B14A87" }, /* For explicit text types range is not checked, so be careful */ { "type" : "bcdplus", "data": "1234" }, { "type" : "6bitascii", "data": "1234" }, { "type" : "text", "data": "1234" } ] }, "board" : { /* The date, if not specified, will be taken automatically from * the current system time. You may specify the `-u` option to * `frugen` in order to leave the date 'Unspecified' */ /* "date" : "1/10/2016 3:00:45",*/ "mfg" : "Biggest International Corp.", "pname" : "Some Cool Product", "serial" : "123456", "pn" : "BRD-PN-345", "file" : "example1.json", "custom" : [ { "type" : "binary", "data" : "0123DEADBABE" }, { "type" : "auto", "data" : "This is a text custom field" }, { "type" : "auto", "data" : "This is test2" } ] }, "product" : { "lang": 1, "mfg" : "Super OEM Company", "pn" : "PRD-PN-1234", "pname" : "Label-engineered Super Product", "serial" : "OEM12345", "atag" : "Accounting Dept.", "ver" : "v1.1", "file" : "example2.json", "custom" : [ { "type" : "auto", "data" : "Product Custom 1" }, { "type" : "auto", "data" : "PRDCSTM" }, { "type" : "auto", "data" : "PRDCSTM2" }, { "type" : "binary", "data" : "C001BEEF" } ] }, "multirecord" : [ { "type" : "management", "subtype" : "uuid", "uuid" : "9bd70799-ccf0-4915-a7f9-7ce7d64385cf" } ] }Is converted using commands:
Output: