Skip to content

Commit

Permalink
[spinor][spinand]fix calc erase start and end range
Browse files Browse the repository at this point in the history
  • Loading branch information
jianjunjiang committed Jun 3, 2022
1 parent a10d00c commit 8fa4c53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions spinand.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ static void spinand_helper_erase(struct xfel_ctx_t * ctx, struct spinand_pdata_t
esize = pdat->info.page_size * pdat->info.pages_per_block;
emask = esize - 1;
base = addr & ~emask;
cnt = ((addr + count + esize - 1) & ~emask) - base;
cnt = (addr & emask) + count;
cnt = (cnt + ((cnt & emask) ? esize : 0)) & ~emask;
while(cnt > 0)
{
pa = base / pdat->info.page_size;
Expand Down Expand Up @@ -439,7 +440,8 @@ int spinand_erase(struct xfel_ctx_t * ctx, uint64_t addr, uint64_t len)
esize = pdat.info.page_size * pdat.info.pages_per_block;
emask = esize - 1;
base = addr & ~emask;
cnt = ((addr + len + esize - 1) & ~emask) - base;
cnt = (addr & emask) + len;
cnt = (cnt + ((cnt & emask) ? esize : 0)) & ~emask;
progress_start(&p, cnt);
while(cnt > 0)
{
Expand Down Expand Up @@ -492,7 +494,8 @@ int spinand_write(struct xfel_ctx_t * ctx, uint64_t addr, void * buf, uint64_t l
esize = pdat.info.page_size * pdat.info.pages_per_block;
emask = esize - 1;
base = addr & ~emask;
cnt = ((addr + len + esize - 1) & ~emask) - base;
cnt = (addr & emask) + len;
cnt = (cnt + ((cnt & emask) ? esize : 0)) & ~emask;
progress_start(&p, cnt);
while(cnt > 0)
{
Expand Down
9 changes: 6 additions & 3 deletions spinor.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ static void spinor_helper_erase(struct xfel_ctx_t * ctx, struct spinor_pdata_t *
return;
emask = esize - 1;
base = addr & ~emask;
cnt = ((addr + count + esize - 1) & ~emask) - base;
cnt = (addr & emask) + count;
cnt = (cnt + ((cnt & emask) ? esize : 0)) & ~emask;
while(cnt > 0)
{
if((pdat->info.opcode_erase_256k != 0) && ((base & 0x3ffff) == 0) && (cnt >= 262144))
Expand Down Expand Up @@ -850,7 +851,8 @@ int spinor_erase(struct xfel_ctx_t * ctx, uint64_t addr, uint64_t len)
return 0;
emask = esize - 1;
base = addr & ~emask;
cnt = ((addr + len + esize - 1) & ~emask) - base;
cnt = (addr & emask) + len;
cnt = (cnt + ((cnt & emask) ? esize : 0)) & ~emask;
progress_start(&p, cnt);
while(cnt > 0)
{
Expand Down Expand Up @@ -912,7 +914,8 @@ int spinor_write(struct xfel_ctx_t * ctx, uint64_t addr, void * buf, uint64_t le
return 0;
emask = esize - 1;
base = addr & ~emask;
cnt = ((addr + len + esize - 1) & ~emask) - base;
cnt = (addr & emask) + len;
cnt = (cnt + ((cnt & emask) ? esize : 0)) & ~emask;
progress_start(&p, cnt);
while(cnt > 0)
{
Expand Down

0 comments on commit 8fa4c53

Please sign in to comment.