On 7/27/22 01:50, Jae Hyun Yoo wrote:
Add product info area parsing support.
Signed-off-by: Jae Hyun Yoo <[email protected]>
---
common/fru_ops.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++-
include/fru.h | 22 ++++++++
2 files changed, 155 insertions(+), 1 deletion(-)
diff --git a/common/fru_ops.c b/common/fru_ops.c
index 0c5e264226ed..93d4970620f4 100644
--- a/common/fru_ops.c
+++ b/common/fru_ops.c
@@ -218,6 +218,57 @@ static int fru_parse_board(unsigned long addr)
return 0;
}
+static int fru_parse_product(unsigned long addr)
+{
+ u8 i, type;
+ int len;
+ u8 *data, *term, *limit;
+
+ memcpy(&fru_data.prd.ver, (void *)addr, 6);
+ addr += 3;
+ data = (u8 *)&fru_data.prd.manufacturer_type_len;
+
+ /* Record max structure limit not to write data over allocated space */
+ limit = (u8 *)&fru_data.prd + sizeof(struct fru_product_data);
+
+ for (i = 0; ; i++, data += FRU_BOARD_MAX_LEN) {
+ len = fru_check_type_len(*(u8 *)addr, fru_data.prd.lang_code,
+ &type);
+ /*
+ * Stop cature if it end of fields
+ */
+ if (len == -EINVAL)
+ break;
+
+ /* Stop when amount of chars is more then fields to record */
+ if (data + len > limit)
+ break;
+ /* This record type/len field */
+ *data++ = *(u8 *)addr;
+
+ /* Add offset to match data */
+ addr += 1;
+
+ /* If len is 0 it means empty field that's why skip writing */
+ if (!len)
+ continue;
+
+ /* Record data field */
+ memcpy(data, (u8 *)addr, len);
+ term = data + (u8)len;
+ *term = 0;
+ addr += len;
+ }
+
+ if (i < FRU_PRODUCT_AREA_TOTAL_FIELDS) {
+ printf("Product area require minimum %d fields\n",
+ FRU_PRODUCT_AREA_TOTAL_FIELDS);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
__weak int fru_parse_multirec(unsigned long addr)
{
u8 hdr_len = sizeof(struct fru_multirec_hdr);
@@ -265,6 +316,9 @@ int fru_capture(unsigned long addr)
if (hdr->off_board)
fru_parse_board(addr + fru_cal_area_len(hdr->off_board));
+ if (hdr->off_product)
+ fru_parse_product(addr + fru_cal_area_len(hdr->off_product));
+
if (hdr->off_multirec)
fru_parse_multirec(addr + fru_cal_area_len(hdr->off_multirec));
@@ -352,6 +406,78 @@ static int fru_display_board(struct fru_board_data *brd, int verbose)
return 0;
}
+static int fru_display_product(struct fru_product_data *prd, int verbose)
+{
+ u8 type;
+ int len;
+ u8 *data;
+ static const char * const typecode[] = {
+ "Binary/Unspecified",
+ "BCD plus",
+ "6-bit ASCII",
+ "8-bit ASCII",
+ "2-byte UNICODE"
+ };
This should be generic for all records and should be shared.
Thanks,
Michal