im-tomu / foboot

Bootloader for Fomu
Apache License 2.0
99 stars 32 forks source link

Replace PicoSoC XIP flash controller with LiteX version #12

Open mithro opened 5 years ago

xobs commented 5 years ago

This cannot be done until a solution has been found for adding write support to the LiteX SPI flash controller.

enjoy-digital commented 5 years ago

If you want to have memory-mapped reads and bitbanging write, you can use SpiFlashDualQuad or SpiFlashSingle (depending if you flash support Single/Dual/Quad SPI reads) and you can this to see how to do write accesses: https://github.com/enjoy-digital/litex/blob/master/litex/soc/software/bios/main.c#L312 https://github.com/enjoy-digital/litex/blob/master/litex/soc/software/libbase/spiflash.c

mithro commented 5 years ago

You can even test this in Renode emulation....

xobs commented 5 years ago

I think I see how it's supposed to work, and I've modified foboot to use the new SpiFlash-with-bitbang mode.

However, the latest litex (which is required to get this mode) doesn't work. Something has changed and the CPU isn't booting at all. I was hoping to get this in before we went to mass production, but it doesn't look like that'll happen.

mithro commented 5 years ago

Last status: The bug preventing CPU from booting has been fixed. Now just need to get SPI flash writing going with the new interface.

@xobs mentioned that the LiteX version seems to save ~100 LCs....

xobs commented 5 years ago

Additionally, I would like to find a path forward to enabling quad-writes. picorv32 supports bit-banging quad writes, but SpiFlash doesn't appear to support that. I'd like as-good-or-better support in an upgrade, especially since higher-performance writes are definitely a thing we'll want.

enjoy-digital commented 5 years ago

@mithro, @xobs i just created that: https://github.com/enjoy-digital/litex/issues/215 Do you see others improvements?

xobs commented 5 years ago

That's a good list of improvements!

If we're asking for a wishlist of features, then an entire spi state machine would be nice. A single csr that you can write to and it does a spi tx/rx. That would greatly speed up writes. For Fomu we'll appear as a fat filesystem, so faster writes will become important.

enjoy-digital commented 5 years ago

Something like this: https://github.com/enjoy-digital/litex/blob/master/litex/soc/cores/spi.py ? :) (but does not support Dual/Quad...)

xobs commented 5 years ago

Yes, something like that. Maybe there's a way to connect that FSM up to the bit bang pins to get the best of both worlds?

Plus, as you say, quad mode is an issue

enjoy-digital commented 5 years ago

Thanks for the feedback, i was just trying to list the possible improvements. Not sure i'll be able to do that very soon (maybe in August), so that's probably better keeping PicoSoC SPI flash module for now.

enjoy-digital commented 5 years ago

@xobs: are you sure supporting Quad mode for writes is really required in your case? It generally takes a lot longer to program the data in the flash than receiving it on the SPI bus so Quad mode seems only interesting for slow SPI clocks, from the winbond datasheet: "The Quad Page Program can improve performance for PROM Programmer and applications that have slow clock speeds <5MHz. Systems with faster clock speed will not realize much benefit for the Quad Page Program instruction since the inherent page program time is much greater than the time it take to clock-in the data."