2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mx25l.cの事

Last updated at Posted at 2025-12-17

sys/dev/flashにSPI flashサポートのmx25l.cというコードがあるのですが、おそらくこれは勘違いがあります。

FL_ERASE_4Kというフラグがあるのですが、これが指定されていると4Kイレース用のコマンドが使われるのですが、チップ全部4Kということはあり得ません。

一般的なSPI flashは64Kセクタでこのサイズでイレースするのですが、パラメータなど小さいデータの保存用に4Kイレースが用意されてるチップがあります。

なので64Kの通常のセクターを書くのに4Kイレースコマンドを実行されるとデータが壊れます。

flashに書き込みすることはあまりなく、おそらくほとんどテストしてなかったんだと思います。

私はSPI flashの更新(reupgrade)ために書き込みを行うことがあるので、気が付きました。

それとこのソースの中に"mx25ll64"という定義があるのですが、パーツ名は"mx25l64"です。

また

        { "mx25ll128",  0xc2, 0x2018, 64 * 1024, 256, FL_ERASE_4K | FL_ERASE_32K
 },

という定義があるのですが、

        if (sc->sc_flags & FL_ERASE_4K)
                sc->sc_erasesize = 4 * 1024;
        else if (sc->sc_flags & FL_ERASE_32K)
                sc->sc_erasesize = 32 * 1024;

とかしちゃってます。もしもどうしてもこの処理が必要ならばFL_ERASE_32KをサポートしているものはFL_ERASE_4KもサポートしているのでFL_ERASE_32Kを先にすべきです。

突っ込みどころ満載です。

自分のレポジトリだけはいじろうと思うのですが、はてどうするのがいいかな。

こうしました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?