flash_mock.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "SpiFlash.h"
  2. #include "esp_spi_flash.h"
  3. #include "esp_partition.h"
  4. #include "esp_err.h"
  5. #include "rom/spi_flash.h"
  6. static SpiFlash spiflash = SpiFlash();
  7. esp_rom_spiflash_chip_t g_rom_flashchip;
  8. extern "C" void _spi_flash_init(size_t chip_size, size_t block_size, size_t sector_size, size_t page_size, const char* partitions_bin)
  9. {
  10. spiflash.init(chip_size, block_size, sector_size, page_size, partitions_bin);
  11. g_rom_flashchip.chip_size = chip_size;
  12. g_rom_flashchip.block_size = block_size;
  13. g_rom_flashchip.sector_size = sector_size;
  14. g_rom_flashchip.page_size = page_size;
  15. }
  16. esp_err_t spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_memory_t memory,
  17. const void** out_ptr, spi_flash_mmap_handle_t* out_handle)
  18. {
  19. *out_handle = 0;
  20. *out_ptr = (void*)spiflash.get_memory_ptr(src_addr);
  21. return ESP_OK;
  22. }
  23. void spi_flash_munmap(spi_flash_mmap_handle_t handle)
  24. {
  25. return;
  26. }
  27. esp_rom_spiflash_result_t esp_rom_spiflash_read(uint32_t target, uint32_t *dest, int32_t len)
  28. {
  29. return spiflash.read(target, dest, len);
  30. }
  31. esp_rom_spiflash_result_t esp_rom_spiflash_erase_block(uint32_t block)
  32. {
  33. return spiflash.erase_block(block);
  34. }
  35. esp_rom_spiflash_result_t esp_rom_spiflash_erase_sector(uint32_t sector)
  36. {
  37. return spiflash.erase_sector(sector);
  38. }
  39. esp_rom_spiflash_result_t esp_rom_spiflash_erase_page(uint32_t page)
  40. {
  41. return spiflash.erase_page(page);
  42. }
  43. esp_rom_spiflash_result_t esp_rom_spiflash_write(uint32_t target, const uint32_t *src, int32_t len)
  44. {
  45. return spiflash.write(target, src, len);
  46. }
  47. esp_rom_spiflash_result_t esp_rom_spiflash_write_encrypted(uint32_t flash_addr, uint32_t *data, uint32_t len)
  48. {
  49. return spiflash.write(flash_addr, data, len);
  50. }