// SPDX-License-Identifier: GPL-2.0
/*
- * (C) Copyright 2019 - 2020 Xilinx, Inc.
+ * (C) Copyright 2019 - 2022, Xilinx, Inc.
+ * (C) Copyright 2022 - 2023, Advanced Micro Devices, Inc.
*/
#include <common.h>
{
int len;
- if (type_len == FRU_TYPELEN_EOF)
- return -EINVAL;
-
*type = (type_len & FRU_TYPELEN_CODE_MASK) >> FRU_TYPELEN_TYPE_SHIFT;
len = type_len & FRU_TYPELEN_LEN_MASK;
{
u8 i, type;
int len;
- u8 *data, *term, *limit;
+ u8 *data, *term, *limit, *next_addr, *eof;
memcpy(&fru_data.brd.ver, (void *)addr, 6);
+
+ /*
+ * eof marks the last data byte (without checksum). That's why checksum
+ * is address length - 1 and last data byte is length - 2.
+ */
+ eof = (u8 *)(fru_data.brd.len * 8 + addr - 2);
+
addr += 6;
data = (u8 *)&fru_data.brd.manufacturer_type_len;
for (i = 0; ; i++, data += FRU_BOARD_MAX_LEN) {
len = fru_check_type_len(*(u8 *)addr, fru_data.brd.lang_code,
&type);
+ next_addr = (u8 *)addr + 1;
+
+ if ((u8 *)addr >= eof) {
+ debug("Reach EOF record: addr %lx, eof %lx\n", addr,
+ (unsigned long)eof);
+ break;
+ }
+
/*
- * Stop cature if it end of fields
+ * Stop capture if the type is ASCII and valid field length
+ * is 1 (0xc1) and next FRU data is less than 0x20 (space " ")
+ * or it is 0x7f (delete 'DEL').
*/
- if (len == -EINVAL)
+ if (type == FRU_TYPELEN_TYPE_ASCII8 && len == 1 &&
+ (*next_addr < 0x20 || *next_addr == 0x7F))
break;
/* Stop when amount of chars is more then fields to record */
for (u8 i = 0; i < (sizeof(boardinfo) / sizeof(*boardinfo)); i++) {
len = fru_check_type_len(*data++, brd->lang_code,
&type);
- if (len == -EINVAL) {
- printf("**** EOF for Board Area ****\n");
- break;
+
+ /* Empty record has no len/type filled */
+ if (!len) {
+ debug("%s not found\n", boardinfo[i]);
+ continue;
}
if (type <= FRU_TYPELEN_TYPE_ASCII8 &&
else
debug("Type code: %s\n", typecode[type + 1]);
- if (!len) {
- debug("%s not found\n", boardinfo[i]);
- continue;
- }
-
switch (type) {
case FRU_TYPELEN_TYPE_BINARY:
debug("Length: %d\n", len);