@@ -68,8 +68,10 @@ int dhara_nand_is_bad(const struct dhara_nand *n, dhara_block_t b)
6868
6969 ESP_GOTO_ON_ERROR (read_page_and_wait (dev , first_block_page , NULL ), fail , TAG , "" );
7070
71+ uint16_t column_addr = dev -> page_size ;
72+ column_addr += 4096 * (b % 2 );
7173 // Read the first 2 bytes on the OOB of the first page in the block. This should be 0xFFFF for a good block
72- ESP_GOTO_ON_ERROR (spi_nand_read (dev -> config .device_handle , (uint8_t * ) & bad_block_indicator , dev -> page_size , 2 ),
74+ ESP_GOTO_ON_ERROR (spi_nand_read (dev -> config .device_handle , (uint8_t * ) & bad_block_indicator , column_addr , 2 ),
7375 fail , TAG , "" );
7476
7577 ESP_LOGD (TAG , "is_bad, block=%" PRIu32 ", page=%" PRIu32 ",indicator = %04x" , b , first_block_page , bad_block_indicator );
@@ -138,13 +140,15 @@ int dhara_nand_prog(const struct dhara_nand *n, dhara_page_t p, const uint8_t *d
138140 esp_err_t ret ;
139141 uint8_t status ;
140142 uint16_t used_marker = 0 ;
143+ uint32_t column_addr = 0 ;
144+ column_addr += 4096 * ((p / (1 << dev -> dhara_nand .log2_ppb )) % 2 );
141145
142146 ESP_GOTO_ON_ERROR (read_page_and_wait (dev , p , NULL ), fail , TAG , "" );
143147 ESP_GOTO_ON_ERROR (spi_nand_write_enable (dev -> config .device_handle ), fail , TAG , "" );
144- ESP_GOTO_ON_ERROR (spi_nand_program_load (dev -> config .device_handle , data , 0 , dev -> page_size ),
148+ ESP_GOTO_ON_ERROR (spi_nand_program_load (dev -> config .device_handle , data , column_addr , dev -> page_size ),
145149 fail , TAG , "" );
146150 ESP_GOTO_ON_ERROR (spi_nand_program_load (dev -> config .device_handle , (uint8_t * )& used_marker ,
147- dev -> page_size + 2 , 2 ),
151+ column_addr + dev -> page_size + 2 , 2 ),
148152 fail , TAG , "" );
149153 ESP_GOTO_ON_ERROR (program_execute_and_wait (dev , p , & status ), fail , TAG , "" );
150154
@@ -167,8 +171,11 @@ int dhara_nand_is_free(const struct dhara_nand *n, dhara_page_t p)
167171 uint16_t used_marker ;
168172
169173 ESP_GOTO_ON_ERROR (read_page_and_wait (dev , p , NULL ), fail , TAG , "" );
174+ uint16_t column_addr = dev -> page_size + 2 ;
175+ column_addr += 4096 * ((p / (1 << dev -> dhara_nand .log2_ppb )) % 2 );
176+
170177 ESP_GOTO_ON_ERROR (spi_nand_read (dev -> config .device_handle , (uint8_t * )& used_marker ,
171- dev -> page_size + 2 , 2 ),
178+ column_addr , 2 ),
172179 fail , TAG , "" );
173180
174181 ESP_LOGD (TAG , "is free, page=%" PRIu32 ", used_marker=%04x," , p , used_marker );
@@ -200,7 +207,10 @@ int dhara_nand_read(const struct dhara_nand *n, dhara_page_t p, size_t offset, s
200207 return -1 ;
201208 }
202209
203- ESP_GOTO_ON_ERROR (spi_nand_read (dev -> config .device_handle , data , offset , length ), fail , TAG , "" );
210+ uint16_t column_addr = offset ;
211+ column_addr += 4096 * ((p / (1 << dev -> dhara_nand .log2_ppb )) % 2 );
212+
213+ ESP_GOTO_ON_ERROR (spi_nand_read (dev -> config .device_handle , data , column_addr , length ), fail , TAG , "" );
204214
205215 return 0 ;
206216fail :
0 commit comments