[PATCH v2 06/11] rockchip: idb: add randomizer option
Johan Jonker
jbx6244 at gmail.com
Sat Jul 9 11:49:57 PDT 2022
Add randomizer option as on some NAND chip all data writen by
Rockchip tools after the IDB blocks is scrambled.
Signed-off-by: Johan Jonker <jbx6244 at gmail.com>
---
optional
---
arch/arm/mach-rockchip/rockchip_idb.c | 56 +++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/arch/arm/mach-rockchip/rockchip_idb.c b/arch/arm/mach-rockchip/rockchip_idb.c
index 37fe6ff2..39eb458a 100644
--- a/arch/arm/mach-rockchip/rockchip_idb.c
+++ b/arch/arm/mach-rockchip/rockchip_idb.c
@@ -190,6 +190,7 @@ struct rk_idb {
u32 boot_blks;
u32 boot_ecc;
u32 pages_per_blk;
+ u32 randomizer;
struct idb idblock[5];
u32 blk_counter;
u32 idb_need_write_back;
@@ -206,6 +207,41 @@ struct rk_idb {
char uuid_disk_str[UUID_STR_LEN + 1];
};
+u16 random_seed[] = {
+ 0x576a, 0x05e8, 0x629d, 0x45a3,
+ 0x649c, 0x4bf0, 0x2342, 0x272e,
+ 0x7358, 0x4ff3, 0x73ec, 0x5f70,
+ 0x7a60, 0x1ad8, 0x3472, 0x3612,
+ 0x224f, 0x0454, 0x030e, 0x70a5,
+ 0x7809, 0x2521, 0x48f4, 0x5a2d,
+ 0x492a, 0x043d, 0x7f61, 0x3969,
+ 0x517a, 0x3b42, 0x769d, 0x0647,
+ 0x7e2a, 0x1383, 0x49d9, 0x07b8,
+ 0x2578, 0x4eec, 0x4423, 0x352f,
+ 0x5b22, 0x72b9, 0x367b, 0x24b6,
+ 0x7e8e, 0x2318, 0x6bd0, 0x5519,
+ 0x1783, 0x18a7, 0x7b6e, 0x7602,
+ 0x4b7f, 0x3648, 0x2c53, 0x6b99,
+ 0x0c23, 0x67cf, 0x7e0e, 0x4d8c,
+ 0x5079, 0x209d, 0x244a, 0x747b,
+ 0x350b, 0x0e4d, 0x7004, 0x6ac3,
+ 0x7f3e, 0x21f5, 0x7a15, 0x2379,
+ 0x1517, 0x1aba, 0x4e77, 0x15a1,
+ 0x04fa, 0x2d61, 0x253a, 0x1302,
+ 0x1f63, 0x5ab3, 0x049a, 0x5ae8,
+ 0x1cd7, 0x4a00, 0x30c8, 0x3247,
+ 0x729c, 0x5034, 0x2b0e, 0x57f2,
+ 0x00e4, 0x575b, 0x6192, 0x38f8,
+ 0x2f6a, 0x0c14, 0x45fc, 0x41df,
+ 0x38da, 0x7ae1, 0x7322, 0x62df,
+ 0x5e39, 0x0e64, 0x6d85, 0x5951,
+ 0x5937, 0x6281, 0x33a1, 0x6a32,
+ 0x3a5a, 0x2bac, 0x743a, 0x5e74,
+ 0x3b2e, 0x7ec7, 0x4fd2, 0x5d28,
+ 0x751f, 0x3ef8, 0x39b1, 0x4e49,
+ 0x746b, 0x6ef6, 0x44be, 0x6db7,
+};
+
struct nand_para_info nand_para_tbl[] = {
{6, {0x2c, 0x64, 0x44, 0x4b, 0xa9, 0x00}, 4, 1, 16, 256, 2, 2, 2048, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
{6, {0x2c, 0x44, 0x44, 0x4b, 0xa9, 0x00}, 4, 1, 16, 256, 2, 2, 1064, 0x01df, 3, 17, 40, 32, 1, 0, 1, 0, 0, {0, 0, 0, 0, 0}},
@@ -640,6 +676,15 @@ void rk_idb_read_page_op(struct rk_idb *plat, int page, int col)
writeb(page >> 8, bank_base + BANK_ADDR);
writeb(page >> 16, bank_base + BANK_ADDR);
writeb(NAND_CMD_READSTART, bank_base + BANK_CMD);
+
+ u32 seed = random_seed[page & 0x7F];
+
+ if (plat->randomizer) {
+ if (!(page < plat->pages_per_blk * plat->boot_blks))
+ seed |= 0xC0000000;
+ }
+
+ writel(seed, regs + plat->cfg->randmz_off);
}
void rk_idb_write_page_op_begin(struct rk_idb *plat, int page, int col)
@@ -653,6 +698,15 @@ void rk_idb_write_page_op_begin(struct rk_idb *plat, int page, int col)
writeb(page, bank_base + BANK_ADDR);
writeb(page >> 8, bank_base + BANK_ADDR);
writeb(page >> 16, bank_base + BANK_ADDR);
+
+ u32 seed = random_seed[page & 0x7F];
+
+ if (plat->randomizer) {
+ if (!(page < plat->pages_per_blk * plat->boot_blks))
+ seed |= 0xC0000000;
+ }
+
+ writel(seed, regs + plat->cfg->randmz_off);
}
void rk_idb_write_page_op_end(struct rk_idb *plat)
@@ -1277,6 +1331,8 @@ int rk_idb_probe(struct udevice *dev)
return -ENODEV;
}
+ plat->randomizer = (plat->info->operation_opt >> 7) & 1;
+
rk_idb_block_align(plat, plat->info->page_per_blk);
rk_idb_build_page_table(plat, plat->info->lsb_mode);
--
2.20.1
More information about the Linux-rockchip
mailing list