rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
WINBONT_N25Q

Functions

void snor_device_init (SNORDriver *devp)
 
flash_error_t snor_device_read (SNORDriver *devp, flash_offset_t offset, size_t n, uint8_t *rp)
 
flash_error_t snor_device_program (SNORDriver *devp, flash_offset_t offset, size_t n, const uint8_t *pp)
 
flash_error_t snor_device_start_erase_all (SNORDriver *devp)
 
flash_error_t snor_device_start_erase_sector (SNORDriver *devp, flash_sector_t sector)
 
flash_error_t snor_device_verify_erase (SNORDriver *devp, flash_sector_t sector)
 
flash_error_t snor_device_query_erase (SNORDriver *devp, uint32_t *msec)
 
flash_error_t snor_device_read_sfdp (SNORDriver *devp, flash_offset_t offset, size_t n, uint8_t *rp)
 
void snor_activate_xip (SNORDriver *devp)
 
void snor_reset_xip (SNORDriver *devp)
 

Variables

flash_descriptor_t snor_descriptor
 Flash descriptor.
 
const wspi_command_t snor_memmap_read
 Fast read command for memory mapped mode.
 

Detailed Description

Function Documentation

◆ snor_activate_xip()

void snor_activate_xip ( SNORDriver *  devp)

Definition at line 581 of file hal_flash_device.c.

581 {
582 (void)devp;
583#if 0
584 static const uint8_t flash_status_xip[1] = {
585 (JEDEC_READ_DUMMY_CYCLES << 4U) | 0x07U
586 };
587
588 /* Activating XIP mode in the device.*/
589 jedec_write_enable(devp, 1);
590 bus_cmd_send(devp, JEDEC_CMD_WRITE_V_CONF_REGISTER,
591 1, flash_status_xip);
592#endif
593}
static void jedec_write_enable(SNORDriver *devp, int enable)
Here is the call graph for this function:

◆ snor_device_init()

void snor_device_init ( SNORDriver *  devp)

Definition at line 264 of file hal_flash_device.c.

264 {
265 int i;
266 uint8_t cfg;
267 uint8_t parameter_headers_n;
268 /* use as temp buffer, should be at least 64 bytes */
269 uint8_t *buf = (uint8_t *)sfdpbuf;
270 uint32_t *sfdp = sfdpbuf;
271 /* offset in sfdp area */
272 flash_offset_t offset = 0;
273 const uint8_t sfdp_sign[4] = {0x53, 0x46, 0x44, 0x50}; /* "SFDP" */
274
275#if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
276 /* Attempting a reset of the XIP mode, it could be in an unexpected state
277 because a CPU reset does not reset the memory too.*/
278 //snor_reset_xip(devp);
279
280 /* Attempting a reset of the device, it could be in an unexpected state
281 because a CPU reset does not reset the memory too.*/
282 jedec_reset_memory(devp);
283#endif /* SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI */
284
285 /* SST26VF specific: adjust configuration register */
286 cfg = jedec_get_config(devp);
287 /* disable WP and HOLD */
288 cfg |= (1 << 1);
289 /* WP# disable */
290 cfg &= ~(1 << 7);
291 jedec_set_config(devp, cfg);
292
293 /* Global Block Protection Unlock */
294 jedec_write_enable(devp, 1);
295 bus_cmd(devp, JEDEC_CMD_GLOBAL_BLOCK_PROTECTION_UNLOCK);
296
297 /* Reading SFDP Header. */
298 snor_device_read_sfdp(devp, offset, 8, buf);
299
300 /* Checking if the device supports SFDP. */
301 osalDbgAssert(memcmp(sfdp_sign, buf, 4) == 0,
302 "chip does not support SFDP");
303
304 /* Find JEDEC Flash Parameter Header */
305 parameter_headers_n = buf[6];
306 for (i = 0; i < parameter_headers_n; i++) {
307 int length;
308 /* each header is 8 bytes lont + 8 bytes of SFDP header */
309 offset = 8 + (i * 8);
310
311 snor_device_read_sfdp(devp, offset, 8, buf);
312 if (buf[0] != 0x00) {
313 /* vendor-specific header - skip. */
314 continue;
315 }
316
317 /* get Parameter Table Pointer */
318 offset = buf[4] | (buf[5] << 8) | (buf[6] << 16);
319 /* and length */
320 length = buf[3] * 4; /* in DWORDs */
321
322 if (length != 0x40)
323 continue;
324
325 snor_device_read_sfdp(devp, offset, length, buf);
326
327 break;
328 }
329
330 osalDbgAssert(i != parameter_headers_n,
331 "JEDEC SFDP parameters block not found");
332
333 /* Setting up the device sizes.*/
334 /* Chip density defined in bits */
335 if (sfdp[1] & 0x80000000)
336 /* more than 4 gigabits */
337 snor_descriptor.size = (size_t)(1 << ((sfdp[1] & 0x7fffffff) - 3));
338 else
339 snor_descriptor.size = (size_t)((sfdp[1] + 1) >> 3);
340 /* Use sector size 1, assume smalest */
341 snor_descriptor.sectors_size = (size_t)1 << (sfdp[7] & 0xff);
342 snor_descriptor.sectors_count = snor_descriptor.size /
343 snor_descriptor.sectors_size;
344
345 /* Fastest read command */
346 /* TODO: add 4-4-4 and 2-2-2 support */
347 if (sfdp[0] & (1 << 21)) {
348 /* 1-4-4 */
350 WSPI_CFG_CMD_MODE_ONE_LINE | WSPI_CFG_CMD_SIZE_8 |
351 WSPI_CFG_ADDR_MODE_FOUR_LINES |
352 WSPI_CFG_DATA_MODE_FOUR_LINES,
353 (sfdp[2] >> 8) & 0xff, (sfdp[2] >> 5) & 0x07, (sfdp[2] >> 0) & 0x1f);
354 } else if (sfdp[0] & (1 << 22)) {
355 /* 1-1-4 */
357 WSPI_CFG_CMD_MODE_ONE_LINE | WSPI_CFG_CMD_SIZE_8 |
358 WSPI_CFG_ADDR_MODE_ONE_LINE |
359 WSPI_CFG_DATA_MODE_FOUR_LINES,
360 (sfdp[2] >> 24) & 0xff, (sfdp[2] >> 21) & 0x07, (sfdp[2] >> 16) & 0x1f);
361 } else if (sfdp[0] & (1 << 20)) {
362 /* 1-2-2 */
364 WSPI_CFG_CMD_MODE_ONE_LINE | WSPI_CFG_CMD_SIZE_8 |
365 WSPI_CFG_ADDR_MODE_TWO_LINES |
366 WSPI_CFG_DATA_MODE_TWO_LINES,
367 (sfdp[3] >> 24) & 0xff, (sfdp[3] >> 21) & 0x07, (sfdp[3] >> 16) & 0x1f);
368 } else if (sfdp[0] & (1 << 16)) {
369 /* 1-1-2 */
371 WSPI_CFG_CMD_MODE_ONE_LINE | WSPI_CFG_CMD_SIZE_8 |
372 WSPI_CFG_ADDR_MODE_ONE_LINE |
373 WSPI_CFG_DATA_MODE_TWO_LINES,
374 (sfdp[3] >> 8) & 0xff, (sfdp[3] >> 5) & 0x07, (sfdp[3] >> 0) & 0x1f);
375 }
376 if (1) {
377 /* Fallback to 1-1-1 */
379 WSPI_CFG_CMD_MODE_ONE_LINE | WSPI_CFG_CMD_SIZE_8 |
380 WSPI_CFG_ADDR_MODE_ONE_LINE |
381 WSPI_CFG_DATA_MODE_ONE_LINE,
382 JEDEC_CMD_FAST_READ, 0, 8);
383 }
384
385 /* TODO: get from SFDP */
387 WSPI_CFG_CMD_MODE_ONE_LINE | WSPI_CFG_CMD_SIZE_8 |
388 WSPI_CFG_ADDR_MODE_ONE_LINE,
389 JEDEC_CMD_SUBSECTOR_ERASE, 0, 0);
390
392 WSPI_CFG_CMD_MODE_ONE_LINE | WSPI_CFG_CMD_SIZE_8 |
393 WSPI_CFG_ADDR_MODE_ONE_LINE |
394 WSPI_CFG_DATA_MODE_ONE_LINE,
395 JEDEC_CMD_PAGE_PROGRAM, 0, 0);
396
397 /* TODO: how to check addressing in SFDP? */
398 if (1) {
399 jedec_cmd_read.cfg |= WSPI_CFG_ADDR_SIZE_24;
400 jedec_cmd_erase.cfg |= WSPI_CFG_ADDR_SIZE_24;
401 jedec_cmd_program.cfg |= WSPI_CFG_ADDR_SIZE_24;
402 } else {
403 jedec_cmd_read.cfg |= WSPI_CFG_ADDR_SIZE_32;
404 jedec_cmd_erase.cfg |= WSPI_CFG_ADDR_SIZE_32;
405 jedec_cmd_program.cfg |= WSPI_CFG_ADDR_SIZE_32;
406 }
407}
static void snor_device_fill_cmd(wspi_command_t *cmd, uint32_t cfg, uint8_t opcode, uint8_t mode_clocks, uint8_t dummy_clocks)
static void jedec_reset_memory(SNORDriver *devp)
flash_error_t snor_device_read_sfdp(SNORDriver *devp, flash_offset_t offset, size_t n, uint8_t *rp)
static void jedec_set_config(SNORDriver *devp, uint8_t val)
static wspi_command_t jedec_cmd_read
static wspi_command_t jedec_cmd_program
static uint8_t jedec_get_config(SNORDriver *devp)
static wspi_command_t jedec_cmd_erase
flash_descriptor_t snor_descriptor
Flash descriptor.
static uint32_t sfdpbuf[64/4]
uint16_t offset
Definition tunerstudio.h:0
Here is the call graph for this function:

◆ snor_device_program()

flash_error_t snor_device_program ( SNORDriver *  devp,
flash_offset_t  offset,
size_t  n,
const uint8_t *  pp 
)

Definition at line 428 of file hal_flash_device.c.

429 {
430 /* Data is programmed page by page.*/
431 while (n > 0U) {
432 flash_error_t err;
433
434 /* Data size that can be written in a single program page operation.*/
435 size_t chunk = (size_t)(((offset | (snor_descriptor.page_size - 1)) + 1U) - offset);
436 if (chunk > n)
437 chunk = n;
438
439 /* send through non-cached buffer */
440 memcpy(tmpbuf, pp, chunk);
441
442 /* Enabling write operation.*/
443 jedec_write_enable(devp, 1);
444
445 /* Page program command.*/
447 wspiSend(devp->config->busp, &jedec_cmd_program, chunk, tmpbuf);
448
449 /* Wait for status and check errors.*/
450 err = jedec_poll_status(devp);
451 if (err != FLASH_NO_ERROR) {
452 return err;
453 }
454
455 /* Next page.*/
456 offset += chunk;
457 pp += chunk;
458 n -= chunk;
459 }
460
461 return FLASH_NO_ERROR;
462}
static flash_error_t jedec_poll_status(SNORDriver *devp)
Here is the call graph for this function:

◆ snor_device_query_erase()

flash_error_t snor_device_query_erase ( SNORDriver *  devp,
uint32_t *  msec 
)

Definition at line 524 of file hal_flash_device.c.

524 {
525 uint8_t sts;
526
527 /* Read status command.*/
528 bus_cmd_receive(devp, JEDEC_CMD_READ_STATUS_REGISTER,
529 1, tmpbuf);
530 sts = tmpbuf[0];
531
532 /* Busy?.*/
533 if ((sts & JEDEC_FLAGS_STS_BUSY) != 0U) {
534 /* Recommended time before polling again, this is a simplified
535 implementation.*/
536 if (msec != NULL) {
537 *msec = 1U;
538 }
539
540 return FLASH_BUSY_ERASING;
541 }
542
543 return FLASH_NO_ERROR;
544}

◆ snor_device_read()

flash_error_t snor_device_read ( SNORDriver *  devp,
flash_offset_t  offset,
size_t  n,
uint8_t *  rp 
)

Definition at line 409 of file hal_flash_device.c.

410 {
411 while (n) {
412 size_t chunk = n < sizeof(tmpbuf) ? n : sizeof(tmpbuf);
413
414 jedec_cmd_read.addr = offset;
415 /* read through non-cached buffer */
416 if (wspiReceive(devp->config->busp, &jedec_cmd_read, chunk, tmpbuf))
417 return FLASH_ERROR_READ;
418
419 memcpy(rp, tmpbuf, chunk);
420 offset += chunk;
421 rp += chunk;
422 n -= chunk;
423 }
424
425 return FLASH_NO_ERROR;
426}

◆ snor_device_read_sfdp()

flash_error_t snor_device_read_sfdp ( SNORDriver *  devp,
flash_offset_t  offset,
size_t  n,
uint8_t *  rp 
)

Definition at line 546 of file hal_flash_device.c.

547 {
548 /* JEDEC SFDP read command.*/
549 wspi_command_t jedec_cmd_read_sfdp = {
550 .cmd = JEDEC_CMD_READ_DISCOVERY_PARAMETER,
551 .cfg = WSPI_CFG_CMD_MODE_ONE_LINE |
552 WSPI_CFG_CMD_SIZE_8 |
553 WSPI_CFG_ADDR_MODE_ONE_LINE |
554 WSPI_CFG_ADDR_SIZE_24 |
555 WSPI_CFG_ALT_MODE_NONE |
556 WSPI_CFG_DATA_MODE_ONE_LINE,
557 .addr = 0,
558 .alt = 0,
559 .dummy = 8 /* cycles, not bytes! */
560 };
561
562 while (n) {
563 size_t chunk = n < sizeof(tmpbuf) ? n : sizeof(tmpbuf);
564
565 jedec_cmd_read_sfdp.addr = offset;
566 /* read through non-cached buffer */
567 if (wspiReceive(devp->config->busp, &jedec_cmd_read_sfdp, chunk, tmpbuf))
568 return FLASH_ERROR_HW_FAILURE;
569
570 memcpy(rp, tmpbuf, chunk);
571
572 offset += chunk;
573 rp += chunk;
574 n -= chunk;
575 }
576
577 return FLASH_NO_ERROR;
578}

Referenced by snor_device_init().

Here is the caller graph for this function:

◆ snor_device_start_erase_all()

flash_error_t snor_device_start_erase_all ( SNORDriver *  devp)

Definition at line 464 of file hal_flash_device.c.

464 {
465
466 /* Enabling write operation.*/
467 jedec_write_enable(devp, 1);
468
469 /* Bulk erase command.*/
470 bus_cmd(devp, JEDEC_CMD_BULK_ERASE);
471
472 return FLASH_NO_ERROR;
473}
Here is the call graph for this function:

◆ snor_device_start_erase_sector()

flash_error_t snor_device_start_erase_sector ( SNORDriver *  devp,
flash_sector_t  sector 
)

Definition at line 475 of file hal_flash_device.c.

476 {
477 flash_offset_t offset = (flash_offset_t)(sector * snor_descriptor.sectors_size);
478
479 /* Enabling write operation.*/
480 jedec_write_enable(devp, 1);
481
482 /* Sector erase command.*/
483 jedec_cmd_erase.addr = offset;
484 wspiCommand(devp->config->busp, &jedec_cmd_erase);
485
486 return FLASH_NO_ERROR;
487}
Here is the call graph for this function:

◆ snor_device_verify_erase()

flash_error_t snor_device_verify_erase ( SNORDriver *  devp,
flash_sector_t  sector 
)

Definition at line 489 of file hal_flash_device.c.

490 {
491 flash_offset_t offset;
492 size_t n;
493
494 /* Read command.*/
495 offset = (flash_offset_t)(sector * snor_descriptor.sectors_size);
496 n = snor_descriptor.sectors_size;
497 while (n > 0U) {
498 size_t i;
499 size_t chunk = n < sizeof(tmpbuf) ? n : sizeof(tmpbuf);
500
501 jedec_cmd_read.addr = offset;
502 /* read through non-cached buffer */
503 if (wspiReceive(devp->config->busp, &jedec_cmd_read, chunk, tmpbuf)) {
504 return FLASH_ERROR_READ;
505 }
506
507 /* Checking for erased state of current buffer.*/
508 for (i = 0; i < chunk; i++) {
509 if (tmpbuf[i] != 0xFFU) {
510 /* Ready state again.*/
511 devp->state = FLASH_READY;
512
513 return FLASH_ERROR_VERIFY;
514 }
515 }
516
517 offset += chunk;
518 n -= chunk;
519 }
520
521 return FLASH_NO_ERROR;
522}

◆ snor_reset_xip()

void snor_reset_xip ( SNORDriver *  devp)

Definition at line 595 of file hal_flash_device.c.

595 {
596 (void)devp;
597#if 0
598 static const uint8_t flash_conf[1] = {
599 (JEDEC_READ_DUMMY_CYCLES << 4U) | 0x0FU
600 };
601 wspi_command_t cmd;
602 uint8_t buf[1];
603
604 /* Resetting XIP mode by reading one byte without XIP confirmation bit.*/
605 cmd.cmd = 0U;
606 cmd.alt = 0xFFU;
607 cmd.addr = 0U;
608 cmd.dummy = JEDEC_READ_DUMMY_CYCLES - 2U;
609 cmd.cfg = WSPI_CFG_CMD_MODE_NONE |
610 WSPI_CFG_ADDR_SIZE_24 |
611#if JEDEC_BUS_MODE == JEDEC_BUS_MODE_WSPI1L
612 WSPI_CFG_ADDR_MODE_ONE_LINE |
613 WSPI_CFG_DATA_MODE_ONE_LINE |
614#elif JEDEC_BUS_MODE == JEDEC_BUS_MODE_WSPI2L
615 WSPI_CFG_ADDR_MODE_TWO_LINES |
616 WSPI_CFG_DATA_MODE_TWO_LINES |
617#elif JEDEC_BUS_MODE == JEDEC_BUS_MODE_WSPI4L
618 WSPI_CFG_ADDR_MODE_FOUR_LINES |
619 WSPI_CFG_DATA_MODE_FOUR_LINES |
620#else
621 WSPI_CFG_ADDR_MODE_EIGHT_LINES |
622 WSPI_CFG_DATA_MODE_EIGHT_LINES |
623#endif
624 WSPI_CFG_ALT_MODE_FOUR_LINES | /* Always 4 lines, note.*/
625 WSPI_CFG_ALT_SIZE_8;
626 wspiReceive(devp->config->busp, &cmd, 1, buf);
627
628 /* Enabling write operation.*/
629 jedec_write_enable(devp, 1);
630 /* Rewriting volatile configuration register.*/
631 bus_cmd_send(devp, JEDEC_CMD_WRITE_V_CONF_REGISTER,
632 1, flash_conf);
633#endif
634}

Referenced by snor_device_init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ snor_descriptor

flash_descriptor_t snor_descriptor
extern

Flash descriptor.

Flash descriptor.

Definition at line 39 of file hal_flash_device.c.

39 {
40 .attributes = FLASH_ATTR_ERASED_IS_ONE | FLASH_ATTR_REWRITABLE |
41 FLASH_ATTR_SUSPEND_ERASE_CAPABLE,
42 .page_size = 256U,
43 .sectors_count = 0U, /* It is overwritten.*/
44 .sectors = NULL,
45 .sectors_size = 0U, /* It is overwritten.*/
46 .address = 0U,
47 .size = 0U /* It is overwritten.*/
48};

Referenced by snor_device_init(), snor_device_program(), snor_device_start_erase_sector(), and snor_device_verify_erase().

◆ snor_memmap_read

const wspi_command_t snor_memmap_read
extern

Fast read command for memory mapped mode.

Definition at line 56 of file hal_flash_device.c.

56 {
57 .cmd = JEDEC_CMD_READ,
58 .addr = 0,
59 .dummy = 0, //JEDEC_READ_DUMMY_CYCLES,
60 .cfg = WSPI_CFG_ADDR_SIZE_24 |
61#if JEDEC_BUS_MODE == JEDEC_BUS_MODE_WSPI1L
62 WSPI_CFG_CMD_MODE_ONE_LINE |
63 WSPI_CFG_ADDR_MODE_ONE_LINE |
64 WSPI_CFG_DATA_MODE_ONE_LINE |
65#elif JEDEC_BUS_MODE == JEDEC_BUS_MODE_WSPI2L
66 WSPI_CFG_CMD_MODE_TWO_LINES |
67 WSPI_CFG_ADDR_MODE_TWO_LINES |
68 WSPI_CFG_DATA_MODE_TWO_LINES |
69#else
70 WSPI_CFG_CMD_MODE_FOUR_LINES |
71 WSPI_CFG_ADDR_MODE_FOUR_LINES |
72 WSPI_CFG_DATA_MODE_FOUR_LINES |
73#endif
74 WSPI_CFG_ALT_MODE_NONE
75};