SD Card Test (Please test - may be used for boot code for the Prop2)
Cluso99
Posts: 18,069
Here is some code for testing SD cards using the Prop1. I am specifically interested in any failures.
You will need to change the SD pins if they are not P0-3. The xtal is set to 5MHz (but check as I often forget to set it back). It compiles with PropTool.
This code is based on Andy's (Ariba) code. We want to verify that it works on as many SD cards as possible, so that we can propose this as the base for the ROM SD Boot code to go into the Prop2. Please post on this thread the results (cut & paste from PST), plus the brand of SD card and size and if SDHC or SDXC. We are not interested in the actual formatting on the card. If the code fails there will be no further output after the "testing..." message.
Latest code (24Aug2012) - bigger buffer, displays $20-$7F ASCII characters only, displays Ptn types if MBR record.
SD_test_003 - Archive [Date 2012.08.24 Time 23.12].zip
SD_test_003.binary
(older) Updated code to make trace buffer bigger for slower cards
SD_test_002 - Archive [Date 2012.08.20 Time 17.20].zip
SD_test_002.binary
This code will not write to your SD card. It just initialises it and reads sector 0 (MBR)
Postedit:
For those interested in the output data.
I output 4 bytes per command. The first byte is the command cmdo (in hex) followed by the parameter cmdp (byte only in hex, so $AA is in fact $1AA). The next byte is the returned byte (in hex) and then follows $FF as a filler.
CMD0 = $00 GO_IDLE_STATE
CMD8 = $08 SEND_IF_COND
CMD55 = $37 APP_COMMAND
ACMD41 = $29 SD_SEND_OP_COND
CMD58 = $3A READ_OCR
CMD17 = $11 READ_SINGLE_BLOCK
You will need to change the SD pins if they are not P0-3. The xtal is set to 5MHz (but check as I often forget to set it back). It compiles with PropTool.
This code is based on Andy's (Ariba) code. We want to verify that it works on as many SD cards as possible, so that we can propose this as the base for the ROM SD Boot code to go into the Prop2. Please post on this thread the results (cut & paste from PST), plus the brand of SD card and size and if SDHC or SDXC. We are not interested in the actual formatting on the card. If the code fails there will be no further output after the "testing..." message.
Latest code (24Aug2012) - bigger buffer, displays $20-$7F ASCII characters only, displays Ptn types if MBR record.
SD_test_003 - Archive [Date 2012.08.24 Time 23.12].zip
SD_test_003.binary
(older) Updated code to make trace buffer bigger for slower cards
SD_test_002 - Archive [Date 2012.08.20 Time 17.20].zip
SD_test_002.binary
This code will not write to your SD card. It just initialises it and reads sector 0 (MBR)
Postedit:
For those interested in the output data.
I output 4 bytes per command. The first byte is the command cmdo (in hex) followed by the parameter cmdp (byte only in hex, so $AA is in fact $1AA). The next byte is the returned byte (in hex) and then follows $FF as a filler.
CMD0 = $00 GO_IDLE_STATE
CMD8 = $08 SEND_IF_COND
CMD55 = $37 APP_COMMAND
ACMD41 = $29 SD_SEND_OP_COND
CMD58 = $3A READ_OCR
CMD17 = $11 READ_SINGLE_BLOCK
Comments
SanDisk 2GB SD (microSD)
[code]
testing...
Parameters used...
00 00 01 FF 08 AA 01 FF 37 00 01 FF 29 00 01 FF
37 00 01 FF 29 00 01 FF 37 00 01 FF 29 00 01 FF
37 00 01 FF 29 00 01 FF 37 00 01 FF 29 00 01 FF
37 00 01 FF 29 00 01 FF 37 00 01 FF 29 00 01 FF
37 00 01 FF 29 00 00 FF 3A 00 00 FF 11 00 00 FF
FE FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
MBR sector 0...
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50 72 6F 70 65 6C 6C 65 72 49 49 00 00 06 00 00 PropellerII.....
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................
04 00 06 0A CA CA 81 00 00 00 7F AF 3B 00 00 00 ....
[code]
testing...
Parameters used...
00 00 01 FF 08 AA 01 FF 37 00 01 FF 29 00 01 FF
37 00 01 FF 29 00 00 FF 3A 00 00 FF 11 00 00 FF
FE FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
MBR sector 0...
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................
03 01 0B 75 F5 CA 00 20 00 00 00 58 77 00 00 00 ...u
I have 2 cards like this that are much slower and broke my first test code. and
Can I propose You add test for contiguous test of length of area after Sector 0 --- By testing for Byte "00" and report that to.
BTW the MBR should point to the Partition area so that can be calculated.
Yes and NO.
MBR -- Yes
But not to First usable space after Boot sector's information TO RAW moed of BOOT loader
Found one SDHC - SD in my spare-parts..
Ad that one are formated as FAT32 -- By my Kodak CAM.
If You look on attached picture it have 2 partition tables --- MASTER and SPARE and length of each one are C00-Hex
That give first free sector = 1800
Ah, I think you might be looking at the two Volume Boot Records at the start of the FAT partition. The Master Boot Record is always at block 0.
It is not volume info of start of FAT partition --- If You look carefully on picture It has address C00 hex --- and if You look top left You will see that first FAT 1 table starts at 6304 Hex.
Boot still Both boot sector's(2) instances don't have ant data in position of BOOT parameters.
My test program will just print the MBR (sector 0). In each of my SD cards (except 4GB which I am unsure), they are formatted either with FAT16 or FAT32.
A FAT table contains the cluster allocation map. And yes there is two such tables allowed for in a FAT volume. They exist inside the volume space.
The actual start of that partition/volume is at block 6 (byte $C00).
Sapieha,
this is the boot of the partition (the volume boot record) not the MBR
As I am aware of there is only ONE MBR starting at absolute 0x0000. In the MBR beside other data you have the "partition table" starting at 0x01BC. The partition table can hold informations for max 4 (primary) partitions: each info (lenght 16 bytes) contain the partition status (1 byte), the absolute start address (3 bytes), the partition type (1 byte), the absolute ending address (3 bytes), LBA (4 bytes) and number of sectors in partition (4 bytes).
When you follow the partition start address you find the volume boot record (relative 0 for the given partition) where in case of FAT volumes you have the master and slave cluster allocation map
Cluso has got it right, the pointer in the MBR is the solution, except that I'll pefere to make two primary partitions on the SD being the first the prop firmware. If you have more than one partition you know that at absolute SD address of 0x01C0 you find the "partition type" info for the first one and at addresses 0x01BD to 0x01BF its starting point (where to start reading the firmware given the partition info is correct). This will prevente any OS tool corrupt your firmware area and because per Cluso solution you have to change the pointer in the MBR each time you change the file in the FAT32 than is the same if you use the same tool to write the firmware binary directly to the firmware partition area thus hiding it from the FAT partition and protecting it also from the accidental SD writes from a novice developer, incorrect SD mount/dismount and finally also from possible bugs in the prop SD-FAT drivers.
@Cluso
On storages with only one partition you have not the MBR but instead you have directly the VBR (volume boot record) in the device absolute 0. It will be very unsafe to write the firmware starting pointer in this area since it can be changed by any disk analisis tool thinking to correct an error. So having more than one partition it seems safer. Why not reserve than the first one (like is done on the today PCs - the recovery partition) for the prop firmware ?
PEDIT: Regarding the various methods scanning the partition area for a given signature in the firmware file I thing they are dangerous because when you delete, overwrite the file the information change is done only in the fat and you can have two times the firmware in the disk but just one listed in the fat. What if you take the wrong one?
Same goes for the MBR, other OS tools have a habit of not understanding foreign structures. That doesn't mean the structures are at fault. The VBR is intended for, (as well as holding the various parameters), holding boot code. If the tools get that wrong they're not functioning correctly. I suggest avoid using them.
Partitions are viable as is. No need to force it mandatory.
Yep. If the official way is busted then the boot loader is prolly history.
Sorry Evanh, perhaps my english is not good enough. I mean that if the OS reconize wrong data in the VBR can try to correct them. The MBR will clearly identify the partition by its partition type information and if this parameter is not indicating one type supported by the OS it will leave the partition and its data untached.
I modified your test program: 1) my PCB applies power to the card through a pmosfet when p12 is low. I first tried making it low at the top of the spin code, but something later was making it high (or input) again and turning off power to the card. Bizarre results! After a brief look I didn't see anything doing that in either the spin or the pasm, but I found that I could make it work by adding another out[12]~ after the COGNEW to keep the card turned on. 2) There was still a bit of initial garbage coming from the serial port, cured by moving dbg.start and 0.1 s delays down to after COGNEW.
Remember, the default layout is with a MBR. If it's partitionless, then the system designer is the one who made it that way.
Andy
Andy
I'd doubt the card maker formatted it that way. Anyway, there is nothing wrong with VBR at block 0. There is no need for partitions at all and anything could boot that way just fine. Just like a floppy.
Here's another test. It's the same card I used in the two tests above:
16Gb SanDisk microSDHC; formatted as ext3
I think the potential of the prop II, with its larger memory, opens up the door for serious datalogging applications. Ones that would benefit from long filenames or ext2/3 files systems. Any boot-from-SD feature that couldn't work from an NON-FAT16/32 card isn't a complete solution in my mind.
format: unknown
format: FAT
format: raw
Format: FAT16
[code]
testing...
Parameters used...
00 00 01 FF 08 AA 05 FF 37 AA 01 FF 29 AA 01 FF
37 AA 01 FF 29 AA 00 FF 11 00 00 FF FE FF 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
MBR sector 0...
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................
39 00 06 1F FF DF F5 00 00 00 0B 83 1E 00 00 00 9..
p
If You have possibility to reformat it by that methode I desribed on Propeller II thread.
And see if it are both MAC compatible and readable -- that have be very nice.