Skip to content

[WIP] Add support for reading from a raw fru dump #9

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

aneeshdurg
Copy link

@aneeshdurg aneeshdurg commented Jul 20, 2020

The motivation for this is to use ipmitool to dump the current fru contents and then modify/add fields before writing it back.

frugen.c Outdated Show resolved Hide resolved
frugen.c Outdated Show resolved Hide resolved
frugen.c Outdated Show resolved Hide resolved
frugen.c Outdated Show resolved Hide resolved
frugen.c Outdated
Comment on lines 586 to 592
struct tm tm_1996 = {
.tm_year = 96,
.tm_mon = 0,
.tm_mday = 1
};
// The argument to mktime is zoneless
board.tv.tv_sec = mktime(&tm_1996) + 60 * min_since_1996;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a very similar piece of code in fru.c, please think about some function that would allow to get rid of repetitions.

@AlexanderAmelkin
Copy link
Collaborator

Thank you for your effort.

fru.c Outdated
*/
static unsigned char *fru_decode_6bit(const fru_field_t *field)
static bool fru_decode_6bit(uint8_t typelen, //<[in] typelen of encoded buffer
const uint8_t *data, //< [in] buffer containing encoded 6bit ascii
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for ditching the fru_field_t in favor of separate typelen and data ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid an extra memcpy. It does make things a bit messier, so I guess I'm not entirely convinced it's worth it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't exactly get how ditching fru_field_t helps in avoiding any extra memcpy.
I can see how changing from internal to external allocation helps in that, but not the fru_field_t.

fru.c Outdated
Comment on lines 305 to 315
if (out_len < (FRU_FIELDDATALEN(typelen) + 1))
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks very strange here

fru.c Outdated Show resolved Hide resolved
fru.c Outdated
if (custom_field == NULL)
return false;

// Create a NUL terminated verion of the data for encoding
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verSion. a typo.

fru.c Outdated
Comment on lines 611 to 613
const uint8_t *curr_data = area->data;
typelen = curr_data[0];
curr_data++;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use fru_field_t here? It was specifically created for this.

fru_reader.c Show resolved Hide resolved
fatal.h Show resolved Hide resolved
fru.c Outdated Show resolved Hide resolved

free(product_raw);
has_product = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're losing the "internal use" and "multi-record" areas here. The output file won't have them even if the original raw file did. That may defeat the purpose of your change as I understand it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need those right now. If it's alright, I'd like to omit support for multirec and internal in the output for now. The internal area is pretty straightforward, but the multirec area seems to require some parsing, which I'd prefer to not have to implement for this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok because libfru initially didn't support creating those areas, but please specify in the help that users may lose their pre-existing areas when using --raw, and also please update the README.md with the information about the new feature and its limitations.


free(raw_fru);
close(fd);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, that code block is large enough for a separate function.

fru.c Outdated
*/
static unsigned char *fru_decode_6bit(const fru_field_t *field)
static bool fru_decode_6bit(uint8_t typelen, //<[in] typelen of encoded buffer
const uint8_t *data, //< [in] buffer containing encoded 6bit ascii
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't exactly get how ditching fru_field_t helps in avoiding any extra memcpy.
I can see how changing from internal to external allocation helps in that, but not the fru_field_t.

fru.c Outdated Show resolved Hide resolved
fru.c Outdated
uint8_t typelen;

chassis_out->type = area->langtype;
const uint8_t *curr_data = area->data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The declaration still needs to be moved to the declarations block, before the code starts.


free(product_raw);
has_product = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok because libfru initially didn't support creating those areas, but please specify in the help that users may lose their pre-existing areas when using --raw, and also please update the README.md with the information about the new feature and its limitations.

@aneeshdurg aneeshdurg changed the title Add support for reading from a raw fru dump [WIP] Add support for reading from a raw fru dump Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants