NuttX的應用記錄 3

這麼久都沒有作者的迴應了,看起來他也是挺忙的。不等他了,自己動手。
可以肯定的是。扇區大小或者扇區的數量也不對。dev的幾個參數轉來轉去,還是卡在前面。啓動過程中的log顯示:

smart_setsectorsize: size = 1024

已經改過定義後仍舊這樣顯示,那還是要找 smart_setsectorsize 的麻煩:

static int smart_setsectorsize(FAR struct smart_struct_s *dev, uint16_t size)
{
  uint32_t  erasesize;
  uint32_t  totalsectors;
  uint32_t  allocsize;

  /* Validate the size isn't zero so we don't divide by zero below */

  /* 事實上,此時 size = 1024 */

  if (size == 0)
    {
      fwarn("Get size == 0; Set size = %d\n", CONFIG_MTD_SMART_SECTOR_SIZE);
      size = CONFIG_MTD_SMART_SECTOR_SIZE;
    }

  if (size == dev->sectorsize)
    {
      fwarn("Get size(%d) == dev->sectorsize(%d); Return\n", size, dev->sectorsize);
      finfo("size == dev->sectorsize == %d\n", size);
      return OK;
    }
  else
    {
      fwarn("Get size(%d) != dev->sectorsize(%d);\n", size, dev->sectorsize);
    }

  /*
   * smart_setsectorsize: Get size(1024) != dev->sectorsize(0);
   * 說明後面操作被執行了。
   */

  fwarn("dev->geo.erasesize = %d\n", dev->geo.erasesize);
  erasesize             = dev->geo.erasesize;

  fwarn("dev->geo.neraseblocks = %d\n", dev->geo.neraseblocks);
  dev->neraseblocks     = dev->geo.neraseblocks;

  fwarn("erasesize = %d\n", erasesize);
  dev->erasesize        = erasesize;

  fwarn("size = %d\n", size);
  dev->sectorsize       = size;

  fwarn("dev->sectorsize / dev->geo.blocksize = %d\n", dev->sectorsize / dev->geo.blocksize);
  dev->mtdBlksPerSector = dev->sectorsize / dev->geo.blocksize;

  /*
   * smart_setsectorsize: dev->geo.erasesize = 4096
   * smart_setsectorsize: dev->geo.neraseblocks = 16384
   * smart_setsectorsize: erasesize = 4096
   * smart_setsectorsize: size = 1024
   * smart_setsectorsize: dev->sectorsize / dev->geo.blocksize = 4
   *
   * 這說明設備的參數還是從dev裏來的,還要在往上。
   */

哦,我都忘記了,這個要往上走。去smart_scan。
它在開讀取了表頭。

          if (header.status != CONFIG_SMARTFS_ERASEDSTATE)
            {
              sectorsize = (header.status & SMART_STATUS_SIZEBITS) << 7;  // 此時等於1024,循環結束
              finfo("((header.status & SMART_STATUS_SIZEBITS) << 7) = %d\n", sectorsize);
              break;
            }

這裏讀到的是 0x00001000 左移7位是1024,爲啥是7位呢?之前沒注意這個7,現在要刨根問底了。那麼就要找到這個表頭創建的時候的寫入方法了。
我第一個想到的就是mksmartfs,查看代碼後哦,發現它適用了ioctl:

  ret = ioctl(fd, BIOC_LLFORMAT, sectorsize << 16);

那就去找 BIOC_LLFORMAT 好了。mx25rxx.c裏沒有找到,那就是smart.c裏了:

    case BIOC_LLFORMAT:

      /* Perform a low-level format on the flash */

      ret = smart_llformat(dev, arg);
      goto ok_out;

再去找smart_llformat函數。這是一個inline函數:

static int inline smart_llformat(FAR struct smart_struct_s *dev, unsigned long arg)
{
  FAR struct  smart_sect_header_s  *sectorheader;
  size_t      wrcount;
  int         x;
  int         ret;
  uint8_t     sectsize, prerelease;
  uint16_t    sectorsize;

  finfo("Entry\n");

  /* Get the sector size from the provided arg */

  sectorsize = arg >> 16; 			// 4096 >> 16 等於 0
  if (sectorsize == 0)
    {
      sectorsize = CONFIG_MTD_SMART_SECTOR_SIZE; 	// 這裏就將4096裝進來了。
    }

  /* Set the sector size for the device */

  ret = smart_setsectorsize(dev, sectorsize);
  if (ret != OK)
    {
      return ret;
    }

  /* Check for invalid format */

  if (dev->erasesize == 0 || dev->sectorsPerBlk == 0)
    {
      dev->erasesize = dev->geo.erasesize;

      ferr("ERROR:  Invalid geometery ... Sectors per erase block must be 1-256\n");
      ferr("        Erase block size    = %d\n", dev->erasesize);
      ferr("        Sector size         = %d\n", dev->sectorsize);
      ferr("        Sectors/erase block = %d\n", dev->erasesize / dev->sectorsize);

      return -EINVAL;
    }

  /* Erase the MTD device */

  ret = MTD_IOCTL(dev->mtd, MTDIOC_BULKERASE, 0); 		// 擦除整個flash
  if (ret < 0)
    {
      return ret;
    }

  /* Now construct a logical sector zero header to write to the device. */

  sectorheader = (FAR struct smart_sect_header_s *) dev->rwbuffer;
  memset(dev->rwbuffer, CONFIG_SMARTFS_ERASEDSTATE, dev->sectorsize);

#if SMART_STATUS_VERSION == 1
#ifdef CONFIG_MTD_SMART_ENABLE_CRC
  /* CRC enabled.  Using an 8-bit sequence number */

  sectorheader->seq = 0;
#else
  /* CRC not enabled.  Using a 16-bit sequence number */

  *((FAR uint16_t *) &sectorheader->seq) = 0;
#endif
#else   /* SMART_STATUS_VERSION == 1 */
  sectorheader->seq = 0;
#endif  /* SMART_STATUS_VERSION == 1 */

  /* Set the sector size of this sector */

  sectsize = (sectorsize >> 9) << 2;

  fwarn("sectsize = %x", sectsize);

  /*
   * (4096 >> 9 )<< 2   = 8'b0010'0000
   */

  /* Set the sector logical sector to zero and setup the header status */

#if ( CONFIG_SMARTFS_ERASEDSTATE == 0xff )
  *((FAR uint16_t *) sectorheader->logicalsector) = 0;
  sectorheader->status = (uint8_t) ~(SMART_STATUS_COMMITTED | SMART_STATUS_VERBITS |
          SMART_STATUS_SIZEBITS) | SMART_STATUS_VERSION |
          sectsize;

  /*
   * SMART_STATUS_COMMITTED = 8'b1000'0000
   * SMART_STATUS_VERBITS   = 8'b0000'0011
   * SMART_STATUS_SIZEBITS  = 8'b0001'1100
   * sectsize               = 8'b0010'0000
   * ~(SMART_STATUS_COMMITTED | SMART_STATUS_VERBITS | SMART_STATUS_SIZEBITS) = ~(8'b1001'1111) = 8'b0110'0000
   * sectorheader->status   = 8'b0110'0000
   */

  fwarn("sectorheader->status = %x", sectorheader->status);

#ifdef CONFIG_MTD_SMART_ENABLE_CRC
  sectorheader->status &= ~SMART_STATUS_CRC;
#endif  /* CONFIG_MTD_SMART_ENABLE_CRC */

#else   /* CONFIG_SMARTFS_ERASEDSTATE == 0xff */
  *((FAR uint16_t *) sectorheader->logicalsector) = 0xffff;
  sectorheader->status = (uint8_t) (SMART_STATUS_COMMITTED | SMART_STATUS_VERSION |
          sectsize);
#ifdef CONFIG_MTD_SMART_ENABLE_CRC
  sectorheader->status |= SMART_STATUS_CRC;
#endif  /* CONFIG_MTD_SMART_ENABLE_CRC */
#endif  /* CONFIG_SMARTFS_ERASEDSTATE == 0xff */

  /* Now add the format signature to the sector */

  dev->rwbuffer[SMART_FMT_POS1] = SMART_FMT_SIG1;
  dev->rwbuffer[SMART_FMT_POS2] = SMART_FMT_SIG2;
  dev->rwbuffer[SMART_FMT_POS3] = SMART_FMT_SIG3;
  dev->rwbuffer[SMART_FMT_POS4] = SMART_FMT_SIG4;

  dev->rwbuffer[SMART_FMT_VERSION_POS] = SMART_FMT_VERSION;
  dev->rwbuffer[SMART_FMT_NAMESIZE_POS] = CONFIG_SMARTFS_MAXNAMLEN;

  /* Record the number of root directory entries we have */

  dev->rwbuffer[SMART_FMT_ROOTDIRS_POS] = (uint8_t) (arg & 0xff);

#ifdef CONFIG_SMART_CRC_8
  sectorheader->crc8 = smart_calc_sector_crc(dev);
#elif defined(CONFIG_SMART_CRC_16)
  *((uint16_t *) sectorheader->crc16) = smart_calc_sector_crc(dev);
#elif defined(CONFIG_SMART_CRC_32)
  *((uint32_t *) sectorheader->crc32) = smart_calc_sector_crc(dev);
#endif

  /* Write the sector to the flash */

  wrcount = MTD_BWRITE(dev->mtd, 0, dev->mtdBlksPerSector,
          (FAR uint8_t *) dev->rwbuffer);
  if (wrcount != dev->mtdBlksPerSector)
    {
      /* The block is not empty!!  What to do? */

      ferr("ERROR: Write block 0 failed: %d.\n", wrcount);

      /* Unlock the mutex if we add one */

      return -EIO;
    }

  /* Now initialize our internal control variables */

  ret = smart_setsectorsize(dev, sectorsize);
  if (ret != OK)
    {
      return ret;
    }

  dev->formatstatus     = SMART_FMT_STAT_UNKNOWN;
  dev->freesectors      = dev->availSectPerBlk * dev->geo.neraseblocks - 1;
  dev->releasesectors   = 0;
#ifdef CONFIG_MTD_SMART_WEAR_LEVEL
  dev->uneven_wearcount = 0;
#endif

  /* Initialize the released and free counts */

  for (x = 0; x < dev->neraseblocks; x++)
    {
      /* Test for a geometry with 65536 sectors.  We allow this, though
       * we never use the last two sectors in this mode.
       */

      if (x == dev->neraseblocks && dev->totalsectors == 65534)
        {
          prerelease = 2;
        }
      else
        {
          prerelease = 0;
        }
#ifdef CONFIG_MTD_SMART_PACK_COUNTS
      smart_set_count(dev, dev->releasecount, x, prerelease);
      smart_set_count(dev, dev->freecount, x, dev->availSectPerBlk-prerelease);
#else
      dev->releasecount[x] = prerelease;
      dev->freecount[x] = dev->availSectPerBlk-prerelease;
#endif
    }

  /* Account for the format sector */

#ifdef CONFIG_MTD_SMART_PACK_COUNTS
  smart_set_count(dev, dev->freecount, 0, dev->availSectPerBlk - 1);
#else
  dev->freecount[0]--;
#endif

  /* Now initialize the logical to physical sector map */

#ifndef CONFIG_MTD_SMART_MINIMIZE_RAM
  dev->sMap[0] = 0;     /* Logical sector zero = physical sector 0 */
  for (x = 1; x < dev->totalsectors; x++)
    {
      /* Mark all other logical sectors as non-existant */

      dev->sMap[x] = -1;
    }
#endif

#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS

  /* Un-register any extra directory device entries */

  for (x = 2; x < 8; x++)
    {
      snprintf(dev->rwbuffer, 18, "/dev/smart%dd%d", dev->minor, x);
      unregister_blockdriver(dev->rwbuffer);
    }
#endif

  return OK;
}

這樣說起來。如果是4096的扇區大小。那麼status的三位上就不能讀取出來4096了。因爲溢出了。這裏是個BUG麼。。。注意力集中在這個arg上。照這個是mksmartfs的一個參數查找這個參數的定義。
apps/nshlib/nsh_command.c 中有所有命令的描述。

{ "mksmartfs",  cmd_mksmartfs,  2, 6, "[-s <sector-size>] [-f] <path> [<num-root-directories>]" },

看起來就是-s參數了。好,來強制4096格式化一次。

mksmartfs -s 4096 /dev/smart0

順便把這個問題發給作者,結果等我格式化過程中還在報錯。結束後就不報錯了。難道好了,重啓板子。沒有看到ERROR並且也能看到:smart_cache_lookup: dev->sectorsize = 0x1000
不說了,直接上操作記錄。

NuttShell (NSH)
nsh> mount -t smartfs /dev/smart0 /mnt
nsh> cd /mnt
nsh> ls
/mnt:
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 2
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
nsh> mkdir
nsh: mkdir: missing required argument(s)
nsh> mkdir a
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
nsh> ls
/mnt:
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
 a/
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
nsh> mkdir b
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 13
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 4
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
nsh> ls
/mnt:
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
 a/
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
 b/
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
nsh> echo "HAHA" >> /mnt/1.txt
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 5
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 5
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 5
smart_readsector: req->logsector = 14
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(14)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14
nsh> ls
/mnt:
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 5
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
 a/
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
 b/
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
 1.txt
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
nsh> cat 1.txt
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3
smart_readsector: req->count = 5
smart_readsector: req->logsector = 14
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(14)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 5
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 14
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(14)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 14
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(14)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14
HAHA

nsh>

這就好了?試試創建一個大一點的文件,要用dd的話,dev下只有null,肯定不行,打開zero。編譯下載。ls /dev 可以看到zero了。
試試看。help dd

dd usage:  dd if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]

那麼就有:

nsh> dd if=/dev/zero of=/mnt/1 bs=1024 count=1
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
nsh> hexdump /mnt/1
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
/mnt/1 at 00000000:
0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
/mnt/1 at 00000200:
0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
01f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
nsh>

看起來沒啥問題。再大一點。結果在count=4的時候出錯了。

nsh> dd if=/dev/zero of=/mnt/1 bs=1024 count=4
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_readsector: req->count = 4091
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x1
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x1000
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_readsector: req->count = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_readsector: ERROR: Error in logical sector 12 header, phys=26
smartfs_sync_internal: ERROR: Error -5 reading sector 12 data
nsh: dd: write failed: 1
smart_readsector: req->count = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12

而count=3的時候都是正常的,那麼試試bs=4000是否正常吧。結果是正常的。那就是這個問題了,一個sector的大小正好4096,文件大小不能超過一個頁。說明第二個頁出錯了。繼續分析。
讀取flash後檢查,發現這個扇區頭居然在一個奇怪的地方。

00002010:    00 00 00 00 00 00 00 00 00 00 57 00 61 53 4D 52 54 01 10 00 FF FF FF FF  ..........W.aSMRT.......
00002028:    FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF AA 00 00 00 FF FF FF  ........................

而在這之前就是一大堆0,就是從zero設備裏讀出來的。

那就換個方法,4096會溢出,那就用2048。
重新mksmartfs。

mksmartfs -s 2048 -f /dev/smart0
smart_setsectorsize: Get size(2048) != dev->sectorsize(4096);
smart_setsectorsize: dev->geo.erasesize = 4096
smart_setsectorsize: dev->geo.neraseblocks = 2048
smart_setsectorsize: erasesize = 4096
smart_setsectorsize: size = 2048
smart_setsectorsize: dev->sectorsize / dev->geo.blocksize = 8
smart_llformat: sectsize = 10
smart_llformat: sectorheader->status = 71
smart_setsectorsize: Get size(2048) == dev->sectorsize(2048); Return
smart_setsectorsize: Get size(2048) == dev->sectorsize(2048); Return
smart_readsector: req->count = 8
smart_readsector: req->logsector = 0
smart_readsector: req->offset = 28
smart_readsector: physsector = smart_cache_lookup(0)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 0
smart_readsector: req->count = 1024
smart_readsector: req->logsector = 0
smart_readsector: req->offset = 36
smart_readsector: physsector = smart_cache_lookup(0)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 3

71寫成2進制就是8'b0111'0001,代表這個扇區已經被提交了,沒有被釋放,CRC校驗啓用,扇區大小2048(10000 << 7),版本1。重啓再看一下。

cat /proc/fs/smartfs/smart0/status
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 2
smart_cache_lookup: If the entry wasn't found in the cache, then we must search the volume
                    for it and add it to the cache.
smart_cache_lookup: dev->availSectPerBlk = 0x2
smart_cache_lookup: dev->geo.neraseblocks = 0x800
smart_cache_lookup: dev->erasesize = 0x1000
smart_cache_lookup: dev->sectorsize = 0x800
Format version:    1
Name Len:          16
Total Sectors:     4096
Sector Size:       2048
Format Sector:     0
Dir Sector:        2
Free Sectors:      4094
Released Sectors:  0
Unused Sectors:    0
Block Erases:      0
Sectors Per Block: 2
Sector Utilization:100%
Uneven Wear Count: 0

計算總大小:4096 x 2048 = 0x800000
再來試試
結果還是不能寫入超過4k的文件。
但是這回扇區頭是在flash開頭了。
改一下flash的扇區配置文件

#define MX25R6435F_SECTOR_SIZE      (2048)
#define MX25R6435F_SECTOR_SHIFT     (11)
#define MX25R6435F_SECTOR_COUNT     (4096)
#define MX25R6435F_PAGE_SIZE        (256)
#define MX25R6435F_PAGE_SHIFT       (8)

但是再次運行的時候,smart初始化報錯。問題出在setsector裏。慢慢找找看。原因是。。。。我沒在menuconfig 裏設置sectorsize爲2048.

各種報錯,錯誤五花八門的。和作者通信後,他告訴我,這塊flash的最小頁就是4096,結果我一看文檔,還真是這樣。不能改2048。改回來把。

繞來繞去,決定分析一下超過4096後到底有什麼扇區沒找到導致報錯了。
smart_cache_lookup 裏添加調試信息。看看它到底要找哪個扇區。

static uint16_t smart_cache_lookup(FAR struct smart_struct_s *dev, uint16_t logical)
{
    ...
    for (x = 0; x < dev->cache_entries; x++)
    {
      fwarn("dev->sCache[x].logical = %d\n", dev->sCache[x].logical);
      if (dev->sCache[x].logical == logical)
        {
          /* Entry found in the cache.  Grab the physical mapping. */

          physical = dev->sCache[x].physical;
          break;
        }
    }
    ...
}

吃了個飯回來使用dd命令產生1M和4M的文件,同時比對兩個打印信息的不同處。
結果。
寫1k

nsh> dd if=/dev/zero of=/mnt/1 bs=1024 count=1
smart_readsector: req->count     = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: dev->sCache[x].logical = 3
smart_readsector: MTD_READ(dev->mtd, 16384, (FAR uint8_t *) &header)
smart_readsector: req->count     = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: dev->sCache[x].logical = 12
smart_readsector: MTD_READ(dev->mtd, 40960, (FAR uint8_t *) &header)
smart_readsector: req->count     = 4091
smart_readsector: req->logsector = 12
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_readsector: MTD_READ(dev->mtd, 40960, (FAR uint8_t *) &header)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: dev->sCache[x].logical = 12
smart_readsector: req->count     = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_readsector: MTD_READ(dev->mtd, 49152, (FAR uint8_t *) &header)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12

寫10k

nsh> dd if=/dev/zero of=/mnt/1 bs=1024 count=10
smart_readsector: req->count     = 4091
smart_readsector: req->logsector = 3
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(3)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: dev->sCache[x].logical = 3
smart_readsector: MTD_READ(dev->mtd, 16384, (FAR uint8_t *) &header)
smart_readsector: req->count     = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: dev->sCache[x].logical = 12
smart_readsector: MTD_READ(dev->mtd, 49152, (FAR uint8_t *) &header)
smart_readsector: req->count     = 4091
smart_readsector: req->logsector = 12
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_readsector: MTD_READ(dev->mtd, 49152, (FAR uint8_t *) &header)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 0
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 3
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: dev->sCache[x].logical = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_readsector: req->count     = 5
smart_readsector: req->logsector = 12
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(12)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_readsector: MTD_READ(dev->mtd, 57344, (FAR uint8_t *) &header)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 4
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: dev->sCache[x].logical = 12
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 4
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: dev->sCache[x].logical = 12
smart_cache_lookup: dev->sCache[x].logical = 13
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 13
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 13
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 13
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 13
smart_readsector: req->count     = 5
smart_readsector: req->logsector = 13
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(13)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 13
smart_readsector: MTD_READ(dev->mtd, 65536, (FAR uint8_t *) &header)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 13
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 5
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: dev->sCache[x].logical = 12
smart_cache_lookup: dev->sCache[x].logical = 13
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: First search for the entry in the cache
smart_cache_lookup: dev->cache_entries = 5
smart_cache_lookup: dev->sCache[x].logical = 3
smart_cache_lookup: dev->sCache[x].logical = 0
smart_cache_lookup: dev->sCache[x].logical = 12
smart_cache_lookup: dev->sCache[x].logical = 13
smart_cache_lookup: dev->sCache[x].logical = 14
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14
smart_readsector: req->count     = 5
smart_readsector: req->logsector = 14
smart_readsector: req->offset    = 0
smart_readsector: physsector = smart_cache_lookup(14)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14
smart_readsector: MTD_READ(dev->mtd, 69632, (FAR uint8_t *) &header)
smart_cache_lookup: Test if searching for the last sector used
smart_cache_lookup: logical == dev->cache_lastlog = 14

對比來對比去,我意識到一件事情,沒有ERROR了。那ERROR去哪裏了!!!出BUG不可怕,因爲還能做點什麼來修補。最可怕的是啥也沒幹BUG就消失了。先試一下創建一個1M的文件。

nsh> dd if=/dev/zero of=/mnt/1 bs=1024 count=1024
(此處省略超級長的調試信息。)
nsh> ls -l
(此處省略超級長的調試信息。)
 -rw-rw-rw- 1048576 1

1048576 / 1024 = 1024。1M的文件無疑。
hexdemp結果也是對的。
重啓試試,結果也是OK的。
這就見鬼了(手動捂臉笑)
重新打開esptool。編譯報錯system未定義。那就把gpio的控制重新寫一下。不用system函數了。參照gpio的例子。

IO0_fd = open(argv[2], O_RDWR);      // argv[2] = "/dev/gpout0"
  if (IO0_fd < 0)
  {
    gpioerr("ERROR: Failed to open %s: ", argv[2], errno);
  }

  LDO_fd = open(argv[3], O_RDWR); 	// argv[3] = "/dev/gpout1"
  if (LDO_fd < 0)
  {
    gpioerr("ERROR: Failed to open %s: ", argv[3], errno);
  }

  /* close gpio0 for close LDO */
  ret = ioctl(LDO_fd, GPIOC_WRITE, (unsigned long)false);

  /* close gpio1 for pull down IO0 at ESP8266 */
  ret = ioctl(IO0_fd, GPIOC_WRITE, (unsigned long)false);

  /* open gpio1 for open LDO */
  ret = ioctl(LDO_fd, GPIOC_WRITE, (unsigned long)true);
  
  close(IO0_fd);
  close(LDO_fd);

測試一下。

nsh> esptool
esptool v1.0
tx_pthread: SYNC OK
tx_pthread: 0x2000AB40: 0x3FF00050
tx_pthread: 0x2000AB40: 0x3FF00054
tx_pthread: 0x2000AB40: 0x3FF00058
tx_pthread: 0x2000AB40: 0x3FF0005C
tx_pthread: MAC: A020A61C1AFF

OK,明天就把這個空的文件寫到8266裏去。


重寫了發送接收結構體,但是忘記寫轉義判斷在裏面了,結果等於啥也沒幹,下週再繼續吧。
作者也回信了,說他修改了驅動,可以讓扇區大小小於4096,他已經測試過,沒有什麼問題目前。

有點卡,再開一篇新的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章