SD Cache Loader Program
Dave Hein
Posts: 6,347
I'm trying to write a program that does the same thing as sd_cache_loader, but runs as a user program. Basically, I want to prompt the user to enter his SD pin configuration, save it to EEPROM and then start up an XMMC program that's on the SD card. I've looked at the sd_cache_loader program in the sdloader directory, but I can't figure out exactly how to do this. Does anybody have any suggestion? Steve? David?
Comments
What is in the info structure? Do I need to populate that before I start the cache driver? Where does the 8K of cache reside in memory -- start, end or somewhere in the middle. Does the sd cache loader code take up any space after it starts up the XMMC program, or is it all available to the XMMC program except for the 8K cache?
That's all the questions I can think of right now. Thanks.
So, you want to run an XMMC program from SD card that is booted from a monitor program stored in EEPROM? SD XMMC is a little slow. There is a faster micro-SD plug-in alternative coming of course Will SD card be mandantory?
Will the cache driver be stored on SD card too? What about other types of XMMC programs? Will you support that too? I'm guessing that one could put some of the simpler .cfg files on SD card and parse them to support all types.
Most Forth developers don't use PropGCC, so I need a way to provide the cache loader and XMMC binaries, which can then be configured for their particular SD pin connections. My plan was to adapt David's SD cache loader to do this, but I can't quite figure out how to do this. I'm sure I can figure it out eventially, but I was hoping to save some time.
At some point I want to run XMMC programs under spinix also. In that case the cache loader program would be a file on the SD card. This could be more flexible and use .cfg files to allow execution from other types of memory, such as flash or RAM. However, the EEPROM boot program is my more immediate need, and the OS version of the loader could be done later.
Yes. I downloaded it today to try and understand the issue better. Looks like a nice piece of work so far.
Makes sense.
Thanks. I figured people didn't need to move their sd cards around all the time risking breaking things. It uses a propeller-load feature written by David Betz.
It's a nice idea to not depend on the developer to make specials for everyone. GCC does that to a point now, and it looks like our cache driver design decisions make it even more important and useful in this case. It would be great if we can easily extend that idea further in a user feature.
It looks like you can just stuff some of the values in the main program (propgcc/loader/src/sd_loader.c line 88). I could be wrong of course.
The meanings of these parameters are in various cache files and David's propeller-load document. I don't see the cache-param1/2 fields explained for sd card - presumably because they can take on various meanings. The parameters are in propgcc/loader/spin/sd_cache.spin.
Haven't looked at spinix lately. I always liked it. Do you have any other ideas for improvements? Maybe GCC programs can be used on it later for hardware abstraction.
1) Cache parameters (size, param1-4)
2) The load target. This determines whether the .pex file is loaded into RAM at 0x20000000 or flash at 0x30000000
3) The cache driver itself
4) SD SPI parameters
5) The SD card driver
Once it patches all of that into the sd_loader.spin binary image it downloads it either to hub memory or EEPROM.
When the sd_loader runs, it
1) loads the sd card driver and initializes the filesystem code
2) opens the autorun.pex file
3) loads and starts the XMM kernel from the .pex file (the kernel is idle at start)
4) loads the user program to either RAM or flash
5) stops the COG running the sd driver
6) chains to a secondary loader (vm_start)
7) the secondary loader initializes hub memory
8) the secondary loader tells the kernel COG to start and then stops itself
The use of the secondary loader allows the user program to have full access to all of hub memory except what is used by the cache driver.
Ray
So I have only been focusing on sd_cache_loader. I've ignored the sd_loader program. Do I need to run sd_loader before running sd_cache_loader?
No, you don't need the sd_loader if you're using the sd_cache_loader. They are mutually exclusive.
So what you want to do at this point is modify the sd_cache_loader so that instead of using SD SPI settings from a .cfg file, it instead puts up some sort of UI to allow the user to select these values? Will the UI use the serial connection to the Propeller or TV/VGA and keyboard?
Ray
What I have done so far is to run make in the propgcc/loader/sdloader directory. I then cd into the include directory and run "propeller-load -b c3 sd_cache_loader.elf -r -t". It doesn't get past the first step of "Initializing cache driver". I assume it's sitting in the "while (xmm_mbox[0]);" loop. I'm guessing that I need to patch a location with something -- maybe it needs the SD pin configuration at this point. I'll look at the Spin file that provides the SD driver to see if I can patch that.
EDIT: I'm guessing I need to initialize the SdLoaderInfo struct before starting up the cache driver. I assume cache_size is 8192. What should I put in cache_param1 - 4, and also the flags variable. Where do I put the SD pin configuration? Do I need to put the address of xmm_mbox in hub location $6? Are there any other hardwired addresses I need to set up?
Here is what I will attempt:
1) make propeller-load able to write out a .binary file already patched with .cfg file entries for a specified board.
2) add code to sd_cache_loader.c to use the serial port to prompt for SD pin configuration using the defaults from the selected board configuration.
3) patch the sd cache driver with the selected SPI pins.
4) start the cache driver
5) mount the filesystem
6) setup to run the file "autorun.pex" using the sd cache
7) load the kernel and the user program and start it
Is that what you want? What about the name of the program to run? Should I also prompt for that?
This wrote a file called sd_cache_loader.binary which I was able to load into a C3 and it successfully started the file autorun.pex on the C3's SD card.
Of course, this isn't really what you want because it doesn't prompt for SD pins when it starts. I'm mulling over how to handle this. The problem as you've already noticed is that you can't just load sd_cache_loader.elf because it doesn't have a cache driver patched into it and hence won't work. Either the sd cache driver needs to be linked in directly rather than being patched or propeller-load or some other tool needs to be able to patch the cache driver into the modified verison of sd_cache_loader.
The problem is, this idea of just linking in the cache driver violates the model used by propeller-load where board-specific stuff is not included in the .elf files but instead merged at load time from a board configuration file. I'm not sure how to handle this yet. I'll think about it...
It seems like what is needed is a program that includes the cache driver DAT file, and knows where the SD pin descriptor needs to be patched into the DAT file. This should be a predicable location since I am only interested in the SD cache driver. After the program prompts the user for the SD pins, it then patches the DAT file, and then starts the SD cog. It then should be able to run the rest of the sd_cache_loader program at that point, correct?