-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: small sram, non power of 2 RAM size, firmware XIP (iCE40 8K: TinyFPGA BX/HX8K) #417
Comments
Thanks @ewenmcneill for the detailed report/investigation. I will look at that and include targets for small boards in LiteX and Travis-CI to be sure to catch this more easily. |
For 1. i don't think there was a regression. Before, the internal value used for the decoder was rounded to 256MB, while now it's rounded to the next power or 2. With b02c233, rounding in hardware is indicated to user when happening and this rounded value is also used to do the internal checks. I'll look at 2. soon. |
Still for 1. if there was a regression, it has probably been fixed when introducing the new SoC Class. For example if we do: |
For 2., this is still supported and the behavior has been made similar to |
Yes, I believe that's how it worked before: the exact value was provided to the linker (software) so the software was laid out correctly in the actual RAM available, but the address decoding used a larger chunk. It sounds like good news that a newer commit has re-introduced this support (with the SoC classes, which I think is 6baa07a); I found that commit earlier, but couldn't tell from patch inspection whether or not the size in the linker table was still being rounded up. litex-buildenv is still pinned to an older litex, from 2019-11-18, so it's currently only got the "rounds up to power of 2 before linker output' version. I did try updating the litex submodule independently, but ran into a different problem (which I think was added to work around the way linking worked previously, by trying to place the
so the TinyFPGA BX target in litex-buildenv will need some more refactoring until I can test it with the newer litex. The relevant code is at https://github.com/timvideos/litex-buildenv/blob/d6cffe26a17af015821142a8b199fc6460f149d8/targets/tinyfpga_bx/base.py#L96-L102, and seems to be trying to use I'll try to find some time this week to update the TinyFPGA BX target to work with the newer litex API, and test this.
Thanks for investigating. It looks like that's already been done in newer litex-buildenv than I was testing (eg, https://github.com/timvideos/litex-buildenv/blob/master/targets/tinyfpga_bx/base.py#L102; I was testing around the commit where it broke). So providing we can sort out the RAM size handling part it sounds like with newer litex it should just boot again. Ewen
|
Thanks for the feedback. I'm was planning to work a bit on the icebreaker in the next days which has similar constraints so will look at that and try to provide an up to date solution. |
FWIW, it looks like the TinyFPGA BX does try to set So I'll need to do some more digging into what's changed in the API. FWIW, the iCEBreaker has been working throughout -- it's a slightly different iCE40 FPGA, with more internal RAM, so it's got a different memory setup. Looks like it's got 128kB of custom RAM built from SPRAM: which obviously is positively gigantic in comparison to the iCE40 8K part :-) Ewen |
Also FTR, it seems like the 0x8000 (32kB) ROM size is coming from litex-buildenv make.py argument parsing defaults, although I've not yet figured out where that default argument is coming from...
It looks like that didn't used to be set by default, but now it is set by default. So platforms relying on overriding the default (but not a manually set value) probably need some refactoring. I get much closer if I just unconditionally set the also doesn't work any longer. (I'm not sure if it's even necessary now everything has switched from arachne-pnr to nextpnr.) Ewen |
Unfortunately it looks like the result of doing that is that the BIOS isn't built (I suspect because FWIW, for this TinyFPGA BX special case (remapping Ewen |
Hi @ewenmcneill, i tried to work yesterday to improve support for small iCE40 FPGAs and tried to create a minimal icebreaker target in https://github.com/enjoy-digital/litex/blob/master/litex/boards/targets/icebreaker.py. In this target, the The BIOS is now built if:
I hope it will help. The main difference with the TinyFPGA BX now is the SRAM. |
Thanks very much for that. It's definitely useful to have a "known working" example to compare against. With the latest litex/litex/soc/cores/cpu/lm32/core.py Lines 26 to 33 in 846a272
But it doesn't seem to have (meaningfully) changed in the last year or so, so it's not immediately obvious what's changed that's causing it not to link. Ewen |
It looks like the https://github.com/enjoy-digital/litex/blob/master/litex/soc/software/common.mak#L66 which includes FTR, this is the linking error I'm getting (with
Ewen |
The change i can think of here is: https://github.com/enjoy-digital/litex/pull/401/files. Could you try with software before this PR? |
Yes, that's the same change that I found added If I just revert the The SRAM has been forced down to 4kB, but it seems like that's happening because the It looks to me like with something to handle appropriate/no Ewen
|
For completeness, if I unconditionally have the target set My very hacky test edit of Ewen
|
FTR, Since linking is invoked via litex/litex/soc/cores/cpu/lm32/core.py Lines 26 to 33 in 846a272
Possibly these per-CPU flags need to be split into "compile flags" and "link flags"? (Or at least "common flags" and "compile only" flags?) Ewen
|
It seems LTO is not yet fully working with all configurations, so it's better reverting the changes for now. - cause issues with LM32 available compilers. - seems to cause issues with min/lite variant of VexRiscv. - seems to cause issues with some litex-buildenv configurations. (see #417).
In general I think that LTO is a great idea, especially for smaller/more RAM constrained targets (which have the most to benefit from removing any unnecessary code, etc). It just seems like the patch adding it needs a wee bit more tweaking to more carefully separate "compile time" LTO flags and "link time" LTO flags, so they don't get mixed together. (And to avoid accidentally passing compile time flags to Possibly just having a "build without LTO flags being added" option would provide a sufficient work around for those targets where it doesn't work? To allow #401 to be reintegrated again and get more testing. Ewen |
Of note, reading the revert (979f98e) it looks to me like the BIOS The build issue that I was seeing I think was in the (a) providing a way to force (b) updating the definition of Ewen |
@enjoy-digital, out of interest (found while trying to figure out how to handle this new API better in the tinyfpga BX target), why is litex/litex/soc/integration/soc_core.py Lines 68 to 70 in b5bddc2
but set to 32kB explicitly later when the arguments parsing is set up? litex/litex/soc/integration/soc_core.py Lines 261 to 265 in b5bddc2
Is that intentional or an oversight? ( FWIW, it seems to me that it'd be better to have a "default defaults" table somewhere else, and set the default Ewen |
@ewenmcneill: it is probably different to avoid regression on some designs that were relying on the default values, but i agree with you, we should probably defines a default table and use it for both. |
Progress update: I've been able to build, from So I think all the regressions have been resolved (the last set by reverting #401, and reopening #139), and I'm closing this issue. Any further discussion is likely to be in timvideos/litex-buildenv#277 and/or timvideos/litex-buildenv#366 about how to update WIP versions of my changes for https://github.com/ewenmcneill/litex-buildenv/tree/refactor-tinyfpga-bx and the one tiny change for the MicroPython port (remove old cached litex https://github.com/ewenmcneill/fupy-micropython/tree/modern-litex if anyone wants to follow along at home. On the SRAM size overrides, the main change is to set the default SRAM size for the TinyFPGA target from the Thanks very much for your help in getting this far. Ewen
|
Thanks for the patience. In the future i'll try to do more tests with small targets and micropython/circuitpython to ensure things are not broken and provide examples if changes are required. |
TL;DR: Regressions/questions:
Is
sram
(or other memory regions) that are of a size that is not a power of 2 still supported? This used to work (see below), but since September 2019 seems to have been implicitly rounded up in size in a way that causes the software linker to try to, eg, use RAM that doesn't actually exist. If only powers of 2 are supported, there should probably be a build failure when trying to pass any non-power-of-2 memory region size, rather than implicitly changing the size and hoping it works out.Is XIP (execute in place) of the firmware still supported? The BIOS boot support for this still seems to be in the BIOS source (eg, https://github.com/enjoy-digital/litex/blob/master/litex/soc/software/bios/boot.c#L361), but the triggering compiler define (
FLASH_BOOT_ADDRESS
) doesn't seem to have been exported since the changes in September 2019 (eg,8be5824#diff-d35fa8f6bd2523ded61b8e55c30cf6c2L68-L74). Was
FLASH_BOOT_ADDRESS
/ XIP firmware deliberately removed, or is this a regression that can be fixed (I think it just needs theFLASH_BOOT_ADDRESS
value exported out to the compiler defines again).More detail below. These a huge amount of debugging of the issues in timvideos/litex-buildenv#277 where I was tracking my progress debugging what changed to break the TinyFPGA BX/HX8K.
Personally I think it'd be nice to again support non-power-of-2 memory regions -- as far as the compiler is concerned -- and just require the address decoding to be at powers of 2 boundaries so that the memory map itself was easy to handle. Ie, that there might be gaps which are not covered by any memory, that the compiler knows not to use, but that the RTL might think exists. I think that is implicitly how it used to work before (ie, prior to September 2019).
I also think it'd be very useful to continue to support the firmware being executed in place out of SPI flash. Otherwise these tiny FPGA targets (iCE 40 8K) basically can't be used to do anything meaningful with litex, as they're too light on RAM to have the application stored anywhere else.
litex-buildenv has build targets for a couple of small iCE40 8K targets, the TinyFPGA BX and the HX8K EVN board. These have worked with litex-buildenv/litex for a couple of years, including running MIcroPython.
Both boards have no external RAM (
main_ram
), and so are reliant on RAM blocks inside the iCE40 8k itself. As a result the port to them was done with a pretty small RAM size and reliant on both the BIOS and the firmware (MicroPython) being XIP (execute in place) out of thespiflash
. This isn't particularly quick, but up through September 2019 it did work if one was patient enough to wait several seconds for the BIOS/MicroPython boot (there's also no CPU cache, for the same RAM constraints).One of the side effects of this tension between "maximum user RAM" and "small FPGA" was that the boards were defined with a
sram
size of 0x2800 (10kB):https://github.com/timvideos/litex-buildenv/blob/d6cffe26a17af015821142a8b199fc6460f149d8/targets/tinyfpga_bx/base.py#L68-L69
https://github.com/timvideos/litex-buildenv/blob/d6cffe26a17af015821142a8b199fc6460f149d8/targets/ice40_hx8k_b_evn/base.py#L60-L61
which worked through September 2019.
As of late October 2019 (found independently by @niklasnisbeth and myself around December 2019/January 2020), when litex-buildenv pulled in the July to October litex changes in timvideos/litex-buildenv@3a9127d, these two boards stopped working. In particular, with some minor changes the gateware could be built and the BIOS could be built, but there was never any serial console output from the boards, not even the LiteX opening banner after this set of changes.
After a lot of debugging I identified the first litex commit that didn't work any more, 8be5824, and then figured out what about that change was causing problems, ie that the
sram
size was being changed from 0x2800 (10kB) to 0x4000 (16kB) after it had been defined. (See timvideos/litex-buildenv#277 (comment) and timvideos/litex-buildenv#277 (comment).) This new size was being exported out to the linker, which I believe was then trying to use the expanded RAM range (eg, for the stack at the top), which was failing miserably. (Thelm32
"exception handler" is mostly just hanging the CPU in a tight loop, so an exception early on would cause a lockup; and I suspect trying to read from the memory bus at a non-mapped address would also potentially just hang.)I was able to get the TinyFPGA BX booting as far as litex BIOS, by forcing the
sram
size down to 0x2000 (8kB), which is the next lowest power of 2 (rather than the next highest power of 2 that litex was rounding up to. See timvideos/litex-buildenv#277 (comment).But the firmware application is not found, because on these boards it's in the spiflash, and intended to be executed in place, but the
FLASH_BOOT_ADDRESS
variable used to trigger that is no longer exported to the BIOS build; see timvideos/litex-buildenv#277 (comment). (It was removed by 8be5824#diff-d35fa8f6bd2523ded61b8e55c30cf6c2L68-L74, and I don't see it being put back anywhere since.)So there are two regressions/things not supported, as per the list at the top.
I'm happy to provide any more information that might be useful. If you want to try to replicate this, the https://github.com/timvideos/litex-buildenv/wiki/HowTo-FuPy-on-iCE40-Boards guide is what I've been following to build/test, on a TinyFPGA BX, with the serial port connected up to a USB serial device. And then fiddling with litex-buildenv and litex checkout versions as described in the later messages in timvideos/litex-buildenv#277.
Ewen
PS: AFAICT the BIOS XIP (execute in place) still works, as it's controlled by different compiler defines, and those do still seem to be exported.
/cc @mithro
The text was updated successfully, but these errors were encountered: