Lines Matching +full:- +full:- +full:graph
4 * SPDX-License-Identifier: Apache-2.0
14 * data are written as address-data combinations. The size of such a combination
27 * The representation of the EEPROM on flash is shown in the next graph.
29 * |-----------------------------------------------------------------------|
30 * ||----------------------| |----------------------| |-------------------||
31 * || EEPROM data | | | |-Flash page--------||
34 * ||----------------------| |----------------------| ... |
39 * ||--EEPROM page 0-------| |--EEPROM page 1-------| |
40 * |------------------------------------------------------------Partition--|
70 /* EEPROM is read-only */
112 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_flash_read()
114 return flash_read(dev_config->flash_dev, dev_config->flash_offset + in eeprom_emu_flash_read()
124 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_flash_write()
127 rc = flash_write(dev_config->flash_dev, dev_config->flash_offset + in eeprom_emu_flash_write()
139 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_flash_erase()
142 rc = flash_erase(dev_config->flash_dev, dev_config->flash_offset + in eeprom_emu_flash_erase()
152 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_page_invalidate()
153 uint8_t buf[dev_config->flash_cbs]; in eeprom_emu_page_invalidate()
159 offset += (dev_config->page_size - sizeof(buf)); in eeprom_emu_page_invalidate()
169 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_get_address()
172 blk += dev_config->flash_cbs / 2; in eeprom_emu_get_address()
174 if (2 * i == dev_config->flash_cbs) { in eeprom_emu_get_address()
192 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_set_change()
194 for (int i = 0; i < (dev_config->flash_cbs / 2); i++) { in eeprom_emu_set_change()
198 for (int i = 0; i < (dev_config->flash_cbs / 2); i++) { in eeprom_emu_set_change()
214 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_is_word_used()
216 for (int i = 0; i < dev_config->flash_cbs; i++) { in eeprom_emu_is_word_used()
233 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_word_read()
234 const struct eeprom_emu_data *dev_data = dev->data; in eeprom_emu_word_read()
235 uint8_t buf[dev_config->flash_cbs]; in eeprom_emu_word_read()
239 direct_address = dev_data->page_offset + address; in eeprom_emu_word_read()
251 offset = dev_data->write_offset; in eeprom_emu_word_read()
252 while (((!mc1) || (!mc2)) && (offset > dev_config->size)) { in eeprom_emu_word_read()
253 offset -= sizeof(buf); in eeprom_emu_word_read()
255 rc = eeprom_emu_flash_read(dev, dev_data->page_offset + offset, in eeprom_emu_word_read()
282 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_flash_get()
283 off_t address = ctx->address + ctx->len - ctx->rlen; in eeprom_emu_flash_get()
284 uint8_t *data8 = (uint8_t *)(ctx->data); in eeprom_emu_flash_get()
285 uint8_t buf[dev_config->flash_cbs]; in eeprom_emu_flash_get()
286 const off_t addr_jmp = address & (sizeof(buf) - 1); in eeprom_emu_flash_get()
290 data8 += (ctx->len - ctx->rlen); in eeprom_emu_flash_get()
291 len = MIN((sizeof(buf) - addr_jmp), ctx->rlen); in eeprom_emu_flash_get()
292 rc = eeprom_emu_word_read(dev, address - addr_jmp, buf); in eeprom_emu_flash_get()
298 ctx->rlen -= len; in eeprom_emu_flash_get()
311 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_compactor()
312 struct eeprom_emu_data *dev_data = dev->data; in eeprom_emu_compactor()
317 (ptrdiff_t)dev_data->page_offset); in eeprom_emu_compactor()
319 next_page_offset = dev_data->page_offset + dev_config->page_size; in eeprom_emu_compactor()
320 if (next_page_offset >= dev_config->flash_size) { in eeprom_emu_compactor()
324 if (!dev_config->partitionerase) { in eeprom_emu_compactor()
327 dev_config->page_size); in eeprom_emu_compactor()
331 dev_config->flash_size); in eeprom_emu_compactor()
340 if (dev_config->rambuf && (ctx != NULL)) { in eeprom_emu_compactor()
342 dev_config->rambuf, in eeprom_emu_compactor()
343 dev_config->size); in eeprom_emu_compactor()
348 ctx->rlen = 0; in eeprom_emu_compactor()
351 uint8_t buf[dev_config->flash_cbs]; in eeprom_emu_compactor()
355 ctx->rlen = ctx->len; in eeprom_emu_compactor()
359 while (rd_offset < dev_config->size) { in eeprom_emu_compactor()
366 if ((ctx != NULL) && (ctx->len) && in eeprom_emu_compactor()
367 (rd_offset > (ctx->address - sizeof(buf)))) { in eeprom_emu_compactor()
369 uint8_t *data8 = (uint8_t *)(ctx->data); in eeprom_emu_compactor()
373 address = ctx->address + ctx->len - ctx->rlen; in eeprom_emu_compactor()
374 addr_jmp = address & (sizeof(buf) - 1); in eeprom_emu_compactor()
375 len = MIN((sizeof(buf) - addr_jmp), ctx->rlen); in eeprom_emu_compactor()
376 data8 += (ctx->len - ctx->rlen); in eeprom_emu_compactor()
378 ctx->rlen -= len; in eeprom_emu_compactor()
397 if ((dev_config->partitionerase) && (next_page_offset == 0)) { in eeprom_emu_compactor()
402 rc = eeprom_emu_page_invalidate(dev, dev_data->page_offset); in eeprom_emu_compactor()
406 dev_data->write_offset = dev_config->size; in eeprom_emu_compactor()
407 dev_data->page_offset = next_page_offset; in eeprom_emu_compactor()
419 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_word_write()
420 struct eeprom_emu_data *dev_data = dev->data; in eeprom_emu_word_write()
421 uint8_t buf[dev_config->flash_cbs], tmp[dev_config->flash_cbs]; in eeprom_emu_word_write()
425 direct_address = dev_data->page_offset + address; in eeprom_emu_word_write()
456 rc = eeprom_emu_flash_write(dev, dev_data->page_offset + in eeprom_emu_word_write()
457 dev_data->write_offset, tmp, in eeprom_emu_word_write()
463 dev_data->write_offset += sizeof(buf); in eeprom_emu_word_write()
464 if ((dev_data->write_offset + sizeof(buf)) >= in eeprom_emu_word_write()
465 dev_config->page_size) { in eeprom_emu_word_write()
484 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_flash_set()
485 off_t address = ctx->address + ctx->len - ctx->rlen; in eeprom_emu_flash_set()
486 uint8_t *data8 = (uint8_t *)(ctx->data); in eeprom_emu_flash_set()
487 uint8_t buf[dev_config->flash_cbs]; in eeprom_emu_flash_set()
488 const off_t addr_jmp = address & (sizeof(buf) - 1); in eeprom_emu_flash_set()
492 data8 += (ctx->len - ctx->rlen); in eeprom_emu_flash_set()
493 len = MIN((sizeof(buf) - addr_jmp), ctx->rlen); in eeprom_emu_flash_set()
494 rc = eeprom_emu_word_read(dev, address - addr_jmp, buf); in eeprom_emu_flash_set()
500 rc = eeprom_emu_word_write(dev, address - addr_jmp, buf, ctx); in eeprom_emu_flash_set()
505 if (ctx->rlen) { in eeprom_emu_flash_set()
506 ctx->rlen -= len; in eeprom_emu_flash_set()
515 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_range_is_valid()
517 if ((address + len) <= dev_config->size) { in eeprom_emu_range_is_valid()
527 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_read()
528 struct eeprom_emu_data *dev_data = dev->data; in eeprom_emu_read()
544 return -EINVAL; in eeprom_emu_read()
547 if (!device_is_ready(dev_config->flash_dev)) { in eeprom_emu_read()
549 return -EIO; in eeprom_emu_read()
554 k_mutex_lock(&dev_data->lock, K_FOREVER); in eeprom_emu_read()
557 if (dev_config->rambuf) { in eeprom_emu_read()
558 memcpy(data, dev_config->rambuf + address, len); in eeprom_emu_read()
570 k_mutex_unlock(&dev_data->lock); in eeprom_emu_read()
578 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_write()
579 struct eeprom_emu_data *dev_data = dev->data; in eeprom_emu_write()
595 return -EINVAL; in eeprom_emu_write()
598 if (dev_config->readonly) { in eeprom_emu_write()
599 LOG_ERR("attempt to write to read-only device"); in eeprom_emu_write()
600 return -EACCES; in eeprom_emu_write()
603 if (!device_is_ready(dev_config->flash_dev)) { in eeprom_emu_write()
605 return -EIO; in eeprom_emu_write()
611 k_mutex_lock(&dev_data->lock, K_FOREVER); in eeprom_emu_write()
614 if (dev_config->rambuf) { in eeprom_emu_write()
615 memcpy(dev_config->rambuf + address, data, len); in eeprom_emu_write()
627 k_mutex_unlock(&dev_data->lock); in eeprom_emu_write()
634 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_size()
636 return dev_config->size; in eeprom_emu_size()
641 const struct eeprom_emu_config *dev_config = dev->config; in eeprom_emu_init()
642 struct eeprom_emu_data *dev_data = dev->data; in eeprom_emu_init()
644 uint8_t buf[dev_config->flash_cbs]; in eeprom_emu_init()
647 k_mutex_init(&dev_data->lock); in eeprom_emu_init()
648 if (!device_is_ready(dev_config->flash_dev)) { in eeprom_emu_init()
650 return -ENODEV; in eeprom_emu_init()
654 dev_data->page_offset = 0U; in eeprom_emu_init()
655 dev_data->write_offset = dev_config->page_size - sizeof(buf); in eeprom_emu_init()
656 while (dev_data->page_offset < dev_config->flash_size) { in eeprom_emu_init()
657 offset = dev_data->page_offset + dev_data->write_offset; in eeprom_emu_init()
667 dev_data->page_offset += dev_config->page_size; in eeprom_emu_init()
670 if (dev_data->page_offset == dev_config->flash_size) { in eeprom_emu_init()
672 return -EINVAL; in eeprom_emu_init()
675 dev_data->write_offset = dev_config->size; in eeprom_emu_init()
678 while ((dev_data->write_offset + sizeof(buf)) < dev_config->page_size) { in eeprom_emu_init()
679 offset = dev_data->page_offset + dev_data->write_offset; in eeprom_emu_init()
689 dev_data->write_offset += sizeof(buf); in eeprom_emu_init()
692 /* dev_data->write_offset reaches last possible location, compaction in eeprom_emu_init()
694 * only in case we are using a write-enabled eeprom in eeprom_emu_init()
696 if ((!dev_config->readonly) && in eeprom_emu_init()
697 ((dev_data->write_offset + sizeof(buf)) >= dev_config->page_size)) { in eeprom_emu_init()
706 if (dev_config->rambuf) { in eeprom_emu_init()
708 while (offset < dev_config->size) { in eeprom_emu_init()
714 memcpy(dev_config->rambuf + offset, buf, sizeof(buf)); in eeprom_emu_init()
746 (size % cbs) ? ((size + cbs - 1) & ~(cbs - 1)) : size