Skip to content

Commit

Permalink
[xfel]change some tips for splwrite command
Browse files Browse the repository at this point in the history
  • Loading branch information
jianjunjiang committed Dec 15, 2021
1 parent edb1fc3 commit c826bbd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ For 64-bits windows, you can using `x86_64-w64-mingw32-` instead of `i686-w64-mi
```shell
xfel(v1.2.2) - https://github.com/xboot/xfel
usage:
xfel version - Show chip version
xfel hexdump <address> <length> - Dumps memory region in hex
xfel dump <address> <length> - Binary memory dump to stdout
xfel exec <address> - Call function address
xfel read32 <address> - Read 32-bits value from device memory
xfel write32 <address> <value> - Write 32-bits value to device memory
xfel read <address> <length> <file> - Read memory to file
xfel write <address> <file> - Write file to memory
xfel reset - Reset device using watchdog
xfel sid - Show sid information
xfel jtag - Enable jtag debug
xfel ddr [type] - Initial ddr controller with optional type
xfel spinor - Detect spi nor flash
xfel spinor read <address> <length> <file> - Read spi nor flash to file
xfel spinor write <address> <file> - Write file to spi nor flash
xfel spinand - Detect spi nand flash
xfel spinand read <address> <length> <file> - Read spi nand flash to file
xfel spinand write <address> <file> - Write file to spi nand flash
xfel spinand splwrite <valid-page-size> <address> <file> - Write file to spi nand flash with spl mode
xfel version - Show chip version
xfel hexdump <address> <length> - Dumps memory region in hex
xfel dump <address> <length> - Binary memory dump to stdout
xfel exec <address> - Call function address
xfel read32 <address> - Read 32-bits value from device memory
xfel write32 <address> <value> - Write 32-bits value to device memory
xfel read <address> <length> <file> - Read memory to file
xfel write <address> <file> - Write file to memory
xfel reset - Reset device using watchdog
xfel sid - Show sid information
xfel jtag - Enable jtag debug
xfel ddr [type] - Initial ddr controller with optional type
xfel spinor - Detect spi nor flash
xfel spinor read <address> <length> <file> - Read spi nor flash to file
xfel spinor write <address> <file> - Write file to spi nor flash
xfel spinand - Detect spi nand flash
xfel spinand read <address> <length> <file> - Read spi nand flash to file
xfel spinand write <address> <file> - Write file to spi nand flash
xfel spinand splwrite <split-size> <address> <file> - Write file to spi nand flash with split support
```

## Links
Expand Down
44 changes: 22 additions & 22 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,25 @@ static void usage(void)
{
printf("xfel(v1.2.2) - https://github.com/xboot/xfel\r\n");
printf("usage:\r\n");
printf(" xfel version - Show chip version\r\n");
printf(" xfel hexdump <address> <length> - Dumps memory region in hex\r\n");
printf(" xfel dump <address> <length> - Binary memory dump to stdout\r\n");
printf(" xfel exec <address> - Call function address\r\n");
printf(" xfel read32 <address> - Read 32-bits value from device memory\r\n");
printf(" xfel write32 <address> <value> - Write 32-bits value to device memory\r\n");
printf(" xfel read <address> <length> <file> - Read memory to file\r\n");
printf(" xfel write <address> <file> - Write file to memory\r\n");
printf(" xfel reset - Reset device using watchdog\r\n");
printf(" xfel sid - Show sid information\r\n");
printf(" xfel jtag - Enable jtag debug\r\n");
printf(" xfel ddr [type] - Initial ddr controller with optional type\r\n");
printf(" xfel spinor - Detect spi nor flash\r\n");
printf(" xfel spinor read <address> <length> <file> - Read spi nor flash to file\r\n");
printf(" xfel spinor write <address> <file> - Write file to spi nor flash\r\n");
printf(" xfel spinand - Detect spi nand flash\r\n");
printf(" xfel spinand read <address> <length> <file> - Read spi nand flash to file\r\n");
printf(" xfel spinand write <address> <file> - Write file to spi nand flash\r\n");
printf(" xfel spinand splwrite <valid-page-size> <address> <file> - Write file to spi nand flash with spl mode\r\n");
printf(" xfel version - Show chip version\r\n");
printf(" xfel hexdump <address> <length> - Dumps memory region in hex\r\n");
printf(" xfel dump <address> <length> - Binary memory dump to stdout\r\n");
printf(" xfel exec <address> - Call function address\r\n");
printf(" xfel read32 <address> - Read 32-bits value from device memory\r\n");
printf(" xfel write32 <address> <value> - Write 32-bits value to device memory\r\n");
printf(" xfel read <address> <length> <file> - Read memory to file\r\n");
printf(" xfel write <address> <file> - Write file to memory\r\n");
printf(" xfel reset - Reset device using watchdog\r\n");
printf(" xfel sid - Show sid information\r\n");
printf(" xfel jtag - Enable jtag debug\r\n");
printf(" xfel ddr [type] - Initial ddr controller with optional type\r\n");
printf(" xfel spinor - Detect spi nor flash\r\n");
printf(" xfel spinor read <address> <length> <file> - Read spi nor flash to file\r\n");
printf(" xfel spinor write <address> <file> - Write file to spi nor flash\r\n");
printf(" xfel spinand - Detect spi nand flash\r\n");
printf(" xfel spinand read <address> <length> <file> - Read spi nand flash to file\r\n");
printf(" xfel spinand write <address> <file> - Write file to spi nand flash\r\n");
printf(" xfel spinand splwrite <split-size> <address> <file> - Write file to spi nand flash with split support\r\n");
}

int main(int argc, char * argv[])
Expand Down Expand Up @@ -388,14 +388,14 @@ int main(int argc, char * argv[])
{
argc -= 1;
argv += 1;
uint32_t pagesz = strtoul(argv[0], NULL, 0);
uint32_t splitsz = strtoul(argv[0], NULL, 0);
uint64_t addr = strtoull(argv[1], NULL, 0);
uint64_t len;
void * buf = file_load(argv[2], &len);
if(buf)
{
if(!spinand_splwrite(&ctx, pagesz, addr, buf, len))
printf("Can't write spi nand flash with spl mode\r\n");
if(!spinand_splwrite(&ctx, splitsz, addr, buf, len))
printf("Can't write spi nand flash with split support\r\n");
free(buf);
}
}
Expand Down
22 changes: 11 additions & 11 deletions spinand.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ int spinand_write(struct xfel_ctx_t * ctx, uint64_t addr, void * buf, uint64_t l
return 0;
}

int spinand_splwrite(struct xfel_ctx_t * ctx, uint32_t pagesz, uint64_t addr, void * buf, uint64_t len)
int spinand_splwrite(struct xfel_ctx_t * ctx, uint32_t splitsz, uint64_t addr, void * buf, uint64_t len)
{
struct spinand_pdata_t pdat;
struct progress_t p;
Expand All @@ -504,9 +504,9 @@ int spinand_splwrite(struct xfel_ctx_t * ctx, uint32_t pagesz, uint64_t addr, vo
{
esize = pdat.info.page_size * pdat.info.pages_per_block;
emask = esize - 1;
if((pagesz <= 0) || (pagesz > pdat.info.page_size))
pagesz = pdat.info.page_size;
if(pagesz & 0x3ff)
if((splitsz <= 0) || (splitsz > pdat.info.page_size))
splitsz = pdat.info.page_size;
if(splitsz & 0x3ff)
{
printf("The valid page size is not 1k alignable and thus not supported\r\n");
return 0;
Expand All @@ -523,7 +523,7 @@ int spinand_splwrite(struct xfel_ctx_t * ctx, uint32_t pagesz, uint64_t addr, vo
printf("The spl size is too large, please check!\r\n");
return 0;
}
uint32_t tsplsz = (splsz * pdat.info.page_size / pagesz + esize) & ~emask;
uint32_t tsplsz = (splsz * pdat.info.page_size / splitsz + esize) & ~emask;
if(addr >= tsplsz)
{
int copies = 0;
Expand All @@ -540,10 +540,10 @@ int spinand_splwrite(struct xfel_ctx_t * ctx, uint32_t pagesz, uint64_t addr, vo
uint8_t * pb = buf;
uint8_t * pnb = nbuf;
memset(pnb, 0xff, nlen);
for(int i = 0; i < splsz; i += pagesz)
for(int i = 0; i < splsz; i += splitsz)
{
memcpy(pnb, pb, pagesz);
pb += pagesz;
memcpy(pnb, pb, splitsz);
pb += splitsz;
pnb += pdat.info.page_size;
}
for(int i = 1; i < copies; i++)
Expand All @@ -564,10 +564,10 @@ int spinand_splwrite(struct xfel_ctx_t * ctx, uint32_t pagesz, uint64_t addr, vo
uint8_t * pb = buf;
uint8_t * pnb = nbuf;
memset(pnb, 0xff, nlen);
for(int i = 0; i < splsz; i += pagesz)
for(int i = 0; i < splsz; i += splitsz)
{
memcpy(pnb, pb, pagesz);
pb += pagesz;
memcpy(pnb, pb, splitsz);
pb += splitsz;
pnb += pdat.info.page_size;
}
}
Expand Down
2 changes: 1 addition & 1 deletion spinand.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C" {
int spinand_detect(struct xfel_ctx_t * ctx, char * name, uint64_t * capacity);
int spinand_read(struct xfel_ctx_t * ctx, uint64_t addr, void * buf, uint64_t len);
int spinand_write(struct xfel_ctx_t * ctx, uint64_t addr, void * buf, uint64_t len);
int spinand_splwrite(struct xfel_ctx_t * ctx, uint32_t pagesz, uint64_t addr, void * buf, uint64_t len);
int spinand_splwrite(struct xfel_ctx_t * ctx, uint32_t splitsz, uint64_t addr, void * buf, uint64_t len);

#ifdef __cplusplus
}
Expand Down

0 comments on commit c826bbd

Please sign in to comment.