Skip to content

Commit

Permalink
imx6ull-flash: add mmap() checks in flashdrv
Browse files Browse the repository at this point in the history
JIRA: DTR-353
  • Loading branch information
Lukasz Kosinski committed Nov 10, 2022
1 parent a08fc00 commit 8a8a687
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion storage/imx6ull-flash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Analogue to flashdrv_write, but ignores metadata.
Analogue to flashdrv_read, but ignores metadata.


extern void flashdrv_init(void);
extern int flashdrv_init(void);

Library and NAND controler initialization.

43 changes: 37 additions & 6 deletions storage/imx6ull-flash/flashdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,13 +1043,42 @@ static void setup_flash_info(void)
}


void flashdrv_init(void)
int flashdrv_init(void)
{
flashdrv_common.dma = mmap(NULL, 2 * _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE, OID_PHYSMEM, 0x1804000);
flashdrv_common.gpmi = mmap(NULL, 2 * _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE, OID_PHYSMEM, 0x1806000);
flashdrv_common.bch = mmap(NULL, 4 * _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE, OID_PHYSMEM, 0x1808000);
flashdrv_common.mux = mmap(NULL, 4 * _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE, OID_PHYSMEM, 0x20e0000);
flashdrv_common.uncached_buf = mmap(NULL, 2 * _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_UNCACHED, OID_CONTIGUOUS, 0);
flashdrv_common.dma = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE, OID_PHYSMEM, 0x1804000);
if (flashdrv_common.dma == MAP_FAILED) {
return -ENOMEM;
}

flashdrv_common.gpmi = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE, OID_PHYSMEM, 0x1806000);
if (flashdrv_common.gpmi == MAP_FAILED) {
munmap((void *)flashdrv_common.dma, _PAGE_SIZE);
return -ENOMEM;
}

flashdrv_common.bch = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE, OID_PHYSMEM, 0x1808000);
if (flashdrv_common.bch == MAP_FAILED) {
munmap((void *)flashdrv_common.gpmi, _PAGE_SIZE);
munmap((void *)flashdrv_common.dma, _PAGE_SIZE);
return -ENOMEM;
}

flashdrv_common.mux = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_DEVICE, OID_PHYSMEM, 0x20e0000);
if (flashdrv_common.mux == MAP_FAILED) {
munmap((void *)flashdrv_common.bch, _PAGE_SIZE);
munmap((void *)flashdrv_common.gpmi, _PAGE_SIZE);
munmap((void *)flashdrv_common.dma, _PAGE_SIZE);
return -ENOMEM;
}

flashdrv_common.uncached_buf = mmap(NULL, _PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_UNCACHED, OID_CONTIGUOUS, 0);
if (flashdrv_common.uncached_buf == MAP_FAILED) {
munmap((void *)flashdrv_common.mux, _PAGE_SIZE);
munmap((void *)flashdrv_common.bch, _PAGE_SIZE);
munmap((void *)flashdrv_common.gpmi, _PAGE_SIZE);
munmap((void *)flashdrv_common.dma, _PAGE_SIZE);
return -ENOMEM;
}

/* 16 bytes of user metadada + ECC16 * bits per parity level (13) / 8 = 26 bytes for ECC */
flashdrv_common.rawmetasz = 16 + 26;
Expand Down Expand Up @@ -1121,6 +1150,8 @@ void flashdrv_init(void)
*(flashdrv_common.bch + bch_flash0layout1) = (flashdrv_common.info.writesz + flashdrv_common.info.metasz) << 16 | 7 << 11 | 0 << 10 | 128;

interrupt(32 + 15, bch_irqHandler, NULL, flashdrv_common.bch_cond, &flashdrv_common.intbch);

return EOK;
}


Expand Down
6 changes: 5 additions & 1 deletion storage/imx6ull-flash/flashsrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,11 @@ static int flashsrv_nandInit(void)
storage_t *strg;

/* Initialize nand flash driver */
flashdrv_init();
err = flashdrv_init();
if (err < 0) {
LOG_ERROR("failed to initialize driver, err: %d", err);
return err;
}

strg = calloc(1, sizeof(storage_t));
if (strg == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion storage/imx6ull-flash/imx6ull-flashdrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extern int flashdrv_isbad(flashdrv_dma_t *dma, uint32_t paddr);
extern int flashdrv_markbad(flashdrv_dma_t *dma, uint32_t paddr);


extern void flashdrv_init(void);
extern int flashdrv_init(void);


extern const flashdrv_info_t *flashdrv_info(void);
Expand Down

0 comments on commit 8a8a687

Please sign in to comment.