-
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.json Motivation
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
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.
@@ -674,6 +748,55 @@ int main(int argc, char *argv[]) | |||
fatal("JSON support was disabled at compile time"); | |||
#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:
Is converted using commands:
Output: