openwrt/package/boot/arm-trusted-firmware-mediatek/patches/120-mt7622-bl2_boot_snand-skip-bad-blocks.patch

41 lines
930 B
Diff
Raw Normal View History

--- a/plat/mediatek/mt7622/bl2_boot_snand.c
+++ b/plat/mediatek/mt7622/bl2_boot_snand.c
@@ -21,6 +21,10 @@
#define FIP_BASE 0x80000
#define FIP_SIZE 0x200000
+#ifndef NMBM
+#define SNAND_MAX_BAD_BLOCK 3
+#endif
+
struct snfi_gpio_mux_info {
const uint32_t *pins;
uint32_t count;
@@ -45,12 +49,26 @@ static size_t snand_read_range(int lba,
size_t sizeremain = size, chunksize;
uint64_t off = lba * cinfo.pagesize;
uint8_t *ptr = (uint8_t *)buf;
+ struct mtk_snand_chip_info info;
+ unsigned int bad_blocks = 0;
int ret = 0;
if (!snf)
return 0;
+ ret = mtk_snand_get_chip_info(snf, &info);
+ if (ret)
+ return 0;
+
while (sizeremain) {
+ while (mtk_snand_block_isbad(snf, off)) {
+ if (bad_blocks > SNAND_MAX_BAD_BLOCK)
+ return size - sizeremain;
+
+ off += info.blocksize;
+ ++bad_blocks;
+ }
+
chunksize = cinfo.pagesize;
if (chunksize > sizeremain)
chunksize = sizeremain;