• I also believe these is a restriction of 1mb max, and that this is in the espurino core rather than the esp8266 implementation.

    Well, it's not a restriction in Espruino itself - maybe just something about getFlash?

  • I also believe these is a restriction of 1mb max, and that this is in the espurino core rather than the esp8266 implementation.
    Well, it's not a restriction in Espruino itself - maybe just something about getFlash?

    I was going by this comment:
    https://github.com/espruino/Espruino/blob/master/targets/esp8266/jshardware.c line 48

    The restriction seems to be here:

    // Save-to-flash uses 12KB at 0x78000
    // The jshFlash functions use memory-mapped reads to access the first 1MB
    // of flash and refuse to go beyond that. Writing uses the SDK functions and is also
    // limited to the first MB.
    

    #define FLASH_MAX (1024*1024)
    #define FLASH_MMAP 0x40200000
    #define FLASH_PAGE_SHIFT 12 // 4KB
    #define FLASH_PAGE (1<<FLASH_PAGE_SHIFT)

    Looking at the fetch:

    void jshFlashRead(
        void *buf,     //!< buffer to read into
        uint32_t addr, //!< Flash address to read from
        uint32_t len   //!< Length of data to read
      ) {
      //os_printf("jshFlashRead: dest=%p, len=%ld flash=0x%lx\n", buf, len, addr);
    
      // make sure we stay with the flash address space
      if (addr >= FLASH_MAX) return;
      if (addr + len > FLASH_MAX) len = FLASH_MAX - addr;
      addr += FLASH_MMAP;
    

    So really #define FLASH_MAX (1024*1024) should be determined by the type of Flash chip in the esp8266 board.

    https://github.com/espruino/Espruino/blob/master/targets/esp8266/jswrap_esp8266.c

    JsVar *jswrap_ESP8266_getFreeFlash() {
      JsVar *jsFreeFlash = jsvNewArray(NULL, 0);
      // Area reserved for EEPROM
      addFlashArea(jsFreeFlash, 0x77000, 0x1000);
    
      // need 1MB of flash to have more space...
      extern uint16_t espFlashKB; // in user_main,c
      if (espFlashKB > 512) {
        addFlashArea(jsFreeFlash, 0x80000, 0x1000);
        if (espFlashKB > 1024) {
          addFlashArea(jsFreeFlash, 0xf7000, 0x9000);
        } else {
          addFlashArea(jsFreeFlash, 0xf7000, 0x5000);
        }
      }
    

    So this could be used rather than the #define:
    extern uint16_t espFlashKB; // in user_main,c

About

Avatar for Wilberforce @Wilberforce started