Porting FSRW SD Reading routines to P2: Now boots from SD!
Rayman
Posts: 14,768
I've been working on this for fun, although I think others could do it better.
Almost finished.
This will eventually load images (or maybe boot code) from SD to HUB RAM
Right now, it does everything that "mount_explicit" does in FSRW.
What's left isn't very complicated.
This is rigged for P123-A9 with the uSD card on my 4.3" LCD adapter board, but setttings can be changed.
It outputs a lot of info about the SD and FAT over serial interface.
I'm thinking that once I remove the serial stuff, the whole file loading code can fit in one cog, we'll see...
Update: See post on 24Dec15 for fully functional boot from SD code.
Almost finished.
This will eventually load images (or maybe boot code) from SD to HUB RAM
Right now, it does everything that "mount_explicit" does in FSRW.
What's left isn't very complicated.
This is rigged for P123-A9 with the uSD card on my 4.3" LCD adapter board, but setttings can be changed.
It outputs a lot of info about the SD and FAT over serial interface.
I'm thinking that once I remove the serial stuff, the whole file loading code can fit in one cog, we'll see...
Update: See post on 24Dec15 for fully functional boot from SD code.
Comments
Your displays arrived - thanks. Took me a little while to find that micro sd socket. Its neatly hidden
Almost there... This version lists the contents of the root directory.
(also I added CRC reading for blocks, which new cards seem to require).
Still fits in one cog, but running out of room... Have to remove serial output stuff soon...
https://technet.microsoft.com/en-us/library/cc776720(v=ws.10).aspx
Doesn't look like it'd be too hard to support long filenames. But, so close to having it fit in a cog that won't touch it for now...
I'm cheating here and not using FAT though. This one assumes that file is in consecutive sectors, which may not be true, except for freshly formatted disks.
Still fits in one cog.
Good job!!
On my need to try list.
I think I have a plan for FAT... There can only be 64 sectors at most in a 512kB file.
So, I'll just use LUT to create a list of sectors used by the file.
Will then just load from those sectors until filesize is reached.
Think I can still squeeze this into one cog, but it's going to be close.
Glad you are doing the FSRW version.
I am tackling Kye's version (pasm code only) on P1 at the moment, trying to minimise code space and simplify, plus understand the boot procedure too. Then I can convert to P2 and see how it compares.
With, P2 there's plenty of room to include those functions, so it would be great to have it ported to P2.
It does support two SPI speeds.
BTW I am only looking at the PASM routine which provides minimal SPI support plus initialisation commands and read/write blocks. It uses the whole cog space but I am currently shrinking that code at the slight expense of speed.
But now, I just looked at his appnote and his code and there is no mention of long filenames.
Actually, there is no mention of 8.3 limit either.
But, I guess you know better as you're looking at the code.
It's pretty trivial to add long filename support, btw.
Does that include support for spaces in file names ?
8.3 is (just) tolerable, but if it can fit, a more tolerant file system would save a lot of novice issues & be great.
Excellent news! Not that I am concerned with supporting long filenames, just that I didn't believe a patent should have been granted on this. It is like being able to patent a 128-bit processor. It is just a logical step.
The boot file could be a long filename in a subdirectory.
What I posted is probably the most minimal thing that would work. It takes about 2 kB of ROM, maybe a bit less. Heard the ROM is 16kB.
But, infringement consists of creating a file, it does not appear to be related to reading a file.
Before we include any support beyond 8.3, more work should be done to verify and perhaps clarify the above.
Given code length, I still much prefer either Peter's method or a partition. Code length is a small fraction of any filesystem support. Heck, including both doesn't even move the needle, and it's robust. Once we've got a couple really basic things sorted, it's gonna always work. Just saying...
But for boot purpose in the rom I do not see the need to support long filenames. The name of the boot file has to be in ROM so it will be static. So something like p2boot.bin would do it.
Enjoy!
Mike
In that case, being a little smarter is very useful.
Of course, this presumes the feature can fit into a COG
I thought it was hidden...
Then your program has to decide if it overwrites/reuses the RAM locations or not.
Enjoy!
Mike
Sure wish we could write lock the lower 16K so it is harder to trash.
If it's just 16k out of 512kB, seems just as easy to load your own SD code...
Any other use means just loading your own code.
ROM gets copied to RAM. Then booting happens. Once boot is done, user code does whatever the user wants.
In the current iteration @chip said that 16k are possible/planned. Some people talk about a build in assembler or even spin compiler. @Chip mentioned a lot of time the wish for a self hosted system.
But IMHO that would make more sense with some real executable ROM available always. Since we have hubexec we could jump into any ROM routine from any COG. What about objects that would reuse the ROM in RAM like @jmg mentioned? Say jump into the monitor or use encryption for own purposes?
They will fail if the lower 16k are used for other purposes. So nobody really can use the space for other purposes. Not without the risk of not being able to use object xyz from the OBEX.
Sure you might be able to say 'I do not use encryption' and can reuse that part of the ROM in RAM as buffer or for variables. But what a pain for the programmer or compiler writer to handle this?
OBEX object x can not be used with object y because it uses lower HUB routines RAM space and object y also?
Either we have some very small boot code in RAM not needed after boot/secure boot or we need real ROM to reuse some of the code in ROM.
Or all ROM code is able to relocate and there is some instruction to load a block of ROM to some given HUB location.
Enjoy!
Mike
That leads to the question of what code size impact does relocatable code cause ?
But building a code library to load blocks of code somewhere via a instruction just to use it is a pain also.
IMHO real ROM would make more sense to me.
At least some way to write protect the lower 16k and some way to find out if write attempts are made.
Enjoy!
Mike
Agreed.
Not sure what you meant ?
The ROM is real ROM - or did you mean memory mapped ROM ?
I think that structure is harder to compile and meet speed/size specs on, whilst the planned small serial ROM is an OnSemi IP block, tightly optimised for size and likely top-mask changeable.
I was thinking, since COG ID is where some chip configuration is done, like fuse access, etc, maybe it could also write mask that 16k for the "treat it like ROM" use case.
Ram copy is fine, but can get trashed pretty easy.