From: Ye Li Date: Sun, 6 Oct 2024 00:30:04 +0000 (+0800) Subject: misc: fuse: Fix FSB redundancy fuse word check and clear res X-Git-Url: http://git.dujemihanovic.xyz/html/%7B%7B%20%24image.RelPermalink%20%7D%7D?a=commitdiff_plain;h=b1fc93b95effbac073bc5b5bc6544ebd590241f7;p=u-boot.git misc: fuse: Fix FSB redundancy fuse word check and clear res There is a bug when checking fuse word with redundancy fuse in FSB table. The redundancy fuses are combined into 4 words, so we can't directly use word index to do the check, otherwise the high 4 words will fail to match. And When calling ELE API, res parameter will pass to ELE API to get ELE response value for failure. So most of usage does not initialize this variable and print it after calling ELE API. However, when ELE API returns failure, we can't ensure this res is always set because there may be other failure like MU failure. Reviewed-by: Peng Fan Signed-off-by: Ye Li Signed-off-by: Peng Fan --- diff --git a/drivers/misc/imx_ele/fuse.c b/drivers/misc/imx_ele/fuse.c index d12539c8aa..47880d8aee 100644 --- a/drivers/misc/imx_ele/fuse.c +++ b/drivers/misc/imx_ele/fuse.c @@ -138,8 +138,7 @@ static s32 map_fsb_fuse_index(u32 bank, u32 word, bool *redundancy) /* map the fuse from ocotp fuse map to FSB*/ for (i = 0; i < size; i++) { if (fsb_mapping_table[i].fuse_bank != -1 && - fsb_mapping_table[i].fuse_bank == bank && - fsb_mapping_table[i].fuse_words > word) { + fsb_mapping_table[i].fuse_bank == bank) { break; } @@ -150,8 +149,13 @@ static s32 map_fsb_fuse_index(u32 bank, u32 word, bool *redundancy) return -1; /* Failed to find */ if (fsb_mapping_table[i].redundancy) { + if ((fsb_mapping_table[i].fuse_words << 1) <= word) + return -2; /* Not valid word */ + *redundancy = true; return (word >> 1) + word_pos; + } else if (fsb_mapping_table[i].fuse_words <= word) { + return -2; /* Not valid word */ } *redundancy = false; @@ -204,7 +208,7 @@ int fuse_sense(u32 bank, u32 word, u32 *val) word_index = map_ele_fuse_index(bank, word); if (word_index >= 0) { u32 data[4]; - u32 res, size = 4; + u32 res = 0, size = 4; int ret; /* Only UID return 4 words */ @@ -257,7 +261,7 @@ int fuse_sense(u32 bank, u32 word, u32 *val) word_index = map_ele_fuse_index(bank, word); if (word_index >= 0) { u32 data; - u32 res, size = 1; + u32 res = 0, size = 1; int ret; ret = ele_read_common_fuse(word_index, &data, size, &res); @@ -282,7 +286,7 @@ int fuse_read(u32 bank, u32 word, u32 *val) int fuse_prog(u32 bank, u32 word, u32 val) { - u32 res; + u32 res = 0; int ret; bool lock = false;