6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 10:44 pm

All times are UTC




Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: FAT32?
PostPosted: Thu May 17, 2018 3:04 pm 
Offline

Joined: Mon Jun 24, 2013 8:18 am
Posts: 83
Location: Italy
I have 65C816 asm code for partitioning mass storage device (FAT16 partition), limited of course to 2Gb. I tried on some flash card and the new created FAT16 partition work fine in one Windows machine. Algorithm is based on rules described in the paper showed by BDD.
This code make MBR,PBR, FAT's tables and root directory on new partition (fast formatting). A full formatting (clear all cluster's) is frustating (long time).
Of course need of low level routines for read/write sector's and for identify device.

Marco

_________________
http://65xx.unet.bz/ - Hardware & Software 65XX family


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Thu May 17, 2018 5:46 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
ArnoldLayne wrote:
BigDumbDinosaur wrote:
BTW, here is a Microsoft technical paper on the FAT filesystem for those who don't have all the details.


Also worth noting Paul Stoffregen's page about FAT32 as he concentrates on the bare minimum you need to get started:
https://www.pjrc.com/tech/8051/ide/fat32.html

Helped me a great deal.

That's a nice link. Thanks.


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Fri May 18, 2018 4:51 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
granati wrote:
I have 65C816 asm code for partitioning mass storage device (FAT16 partition), limited of course to 2Gb. I tried on some flash card and the new created FAT16 partition work fine in one Windows machine. Algorithm is based on rules described in the paper showed by BDD.
This code make MBR,PBR, FAT's tables and root directory on new partition (fast formatting). A full formatting (clear all cluster's) is frustating (long time).
Of course need of low level routines for read/write sector's and for identify device.

Marco


That is very interesting! Do you plan to share the source?


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Sat May 19, 2018 9:59 am 
Offline

Joined: Mon Jun 24, 2013 8:18 am
Posts: 83
Location: Italy
Code is available at:

http://65xx.unet.bz/ - software section

direct link: http://65xx.unet.bz/mb01/B1606.zip

This code is a work in progress. Many pieces are incomplete, maybe full of bugs, but some sections are fully tested.
About FAT16 i'm developing a simple system for caching directory entries and accessed sector's for fast access. Traversing directories is still incomplete, but code for partitioning/formatting FAT16 is fully tested (also, work in floppy disk both 720K/1440K).
Look at F9/toscmd.asm for 'fdisk' implementation.

Note that low level routines for accessing ATA devices, USB devices (CH375/376 module) and floppy disk are in F8 directory. In this implementation ATA devices are accessed in DMA mode even if in the site is not showen the new ATA/DMA board i maded for my machine.

Marco

_________________
http://65xx.unet.bz/ - Hardware & Software 65XX family


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Thu Aug 02, 2018 7:58 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
dolomiah wrote:
whartung wrote:
That's pretty nice.


Thank you, means a lot from a long standing member of the forum. I agree the 376 is great bit of kit, and if I used it I could have saved ROM space for more features in the interpreter, but the geek in me did enjoy getting the SPI SD Card interface working and then deep diving in to FAT to support a PC compatible filesystem.

I read the manual, I couldn't see a command to format disks, but looks like block level access is possible - as you say, loads of possibilities.


After holidays and some Verilog to get a SPI DMA buffer, I am trying to get my head around this code. It looks like you are completely ignoring the CRC7 part of the command string for the SD Card. Isn't that needed to get stable SPI communication?

What kind of CRC are you using for the FAT32?


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Fri Aug 03, 2018 10:19 pm 
Offline

Joined: Wed Nov 18, 2015 8:36 am
Posts: 102
Location: UK
kakemoms, are you referring to my 6502 homebrew source on hackaday, or what granati posted? Reason I am slightly confused is your reference to FAT32 - my code only supports FAT16.

But in case you are referring to my source code, yes from what I read and what is working, the SD card doesn't seem to care about the CRC after the CMD0. Weird, but works according to the document I found on this (an application note from 2004 by F. Foust, published by the University of Michigan). 0x95 is the correct CRC for CMD0, so I then just send the same value with all subsequent commands (ignore the comments that say the checksum has to be right, it's a copy and paste error!)

Regarding FAT32 CRC, well that's where I am confused as my code only supports FAT16 and there is no CRC in that. I am not sure there is any CRC in FAT32 mind..


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Sun Aug 05, 2018 7:15 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
dolomiah wrote:
kakemoms, are you referring to my 6502 homebrew source on hackaday, or what granati posted? Reason I am slightly confused is your reference to FAT32 - my code only supports FAT16.

But in case you are referring to my source code, yes from what I read and what is working, the SD card doesn't seem to care about the CRC after the CMD0. Weird, but works according to the document I found on this (an application note from 2004 by F. Foust, published by the University of Michigan). 0x95 is the correct CRC for CMD0, so I then just send the same value with all subsequent commands (ignore the comments that say the checksum has to be right, it's a copy and paste error!)

Regarding FAT32 CRC, well that's where I am confused as my code only supports FAT16 and there is no CRC in that. I am not sure there is any CRC in FAT32 mind..


Sorry I got the code mixed up here (my brain is still in holiday mode). The FAT32 question was to the other coder with the SteckOS.

I still don't understand why CRC is not used. FAT seems to make double copies of the file allocation table as a redundancy.. and that indicates that CRC would probably be a good idea.

There are several places that lists command arguments and CRC, so it seems like a table is all that is needed for most commands.


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Sun Aug 05, 2018 11:32 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
Ok, since I couldn't find any CRC-7 for 6502, I made one myself:

Code:
; Calculation of CRC7 for SD Card communication
CMD0 = $40

*=$a000
        LDA     #CMD0      ; CMD0 command (no arguments)
        STA     crcdata
        LDA     #4
        LDX     #<crcdata
        LDY     #>crcdata
        JSR     crc7
        ASL     ; CRC for SPI in bit 7-1
        ORA     #1      ; bit0 always set
        STA     crcdata+5
        RTS

crcdata byte 0,0,0,0,0,0

; start of data is in X & Y
; length-1 is in A

crc7
        STX     $2
        STY     $3     
        STA     $4

        LDX     #0
        STX     $5      ;crc
        STX     $6      ; counter
crc7lp1
        LDY     $6
        LDA     ($2),Y          ; get ch
        LDX     #7
crc7lp2
        TAY
        ASL     $5      ; shift CRC
        EOR     $5      ; CH XOR CRC
        AND     #$80
        BEQ     crc7mp1 ; if (CH XOR CRC) AND $80 = 0
        LDA     $5
        EOR     #$09
        STA     $5      ; CRC = CRC XOR $09
crc7mp1
        TYA             ; CH
        ASL             ; shift CH
        DEX
        BPL     crc7lp2         ; loop 7 times
        LDA     $5
        AND     #$7f
        STA     $5      ; CRC = CRC AND $7F
        INC     $6
        DEC     $4
        BPL     crc7lp1
        LDA     $5      ; CRC
        RTS


Probably not the fastest way, but it seems to work.


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Mon Aug 06, 2018 9:33 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
I'm not sure that you really need a CRC7 routine. The series of commands you send to initialise the SC card are always the same so the CRC7 bytes can be pre-computed. Later when accessing the card to read/write blocks the CRC16 values are optional.

I can't find the 6502 code I wrote for my SBC when I was playing with this last year. I'll try to dig it up later.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Wed Aug 08, 2018 10:11 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
Heres the listing of the code I wrote that initialises an SD card and read/dumps a 512 byte sector. One day I'll get back to it.
Attachment:
boot-65c02.zip [11.45 KiB]
Downloaded 170 times

This was for my SB-6502 board and its virtual SPI65 interface. All the CRC7 values are fixed in the initialisation data.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Thu Aug 09, 2018 10:36 am 
Offline

Joined: Sun Dec 28, 2014 11:04 pm
Posts: 82
Location: Munich, Germany
kakemoms wrote:
Sorry I got the code mixed up here (my brain is still in holiday mode). The FAT32 question was to the other coder with the SteckOS.


That would be me. There is no CRC code at all in the SteckOS FAT32-implementation. I think that's not needed at all there.
Where one CRC7 checksum IS indeed needed is when using the SD card command CMD0 during SD card init, but not need to generate one because it always the same, as BitWise already pointed out.

Or was there another question I missed?


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Thu Aug 09, 2018 10:44 am 
Offline

Joined: Sun Dec 28, 2014 11:04 pm
Posts: 82
Location: Munich, Germany
ArnoldLayne wrote:
kakemoms wrote:
Sorry I got the code mixed up here (my brain is still in holiday mode). The FAT32 question was to the other coder with the SteckOS.


That would be me. There is no CRC code at all in the SteckOS FAT32-implementation. I think that's not needed at all there.
Where one CRC7 checksum IS indeed needed is when using the SD card command CMD0 during SD card init, but not need to generate one because it always the same, as BitWise already pointed out.


Coming to think of it, FAT32 long filenames use a crc7 checksum. But don't get me started on FAT long filenames.


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Fri Sep 07, 2018 3:49 pm 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
ArnoldLayne wrote:
Hi,

we are working our own FAT32 implementation as part of the operating system "SteckOS" for our 6502-based homebrew computer "Steckschwein" http://www.steckschwein.de

It's not complete yet, we currently do not follow cluster chains, so files > 1 cluster are a problem.
We chose not to support long file names either.
But creating, reading, writing files and directories works. The "API" is loosely modeled after POSIX (open,close,read,write).

The code is publicly available: https://bitbucket.org/steckschwein/stec ... os/kernel/

Our implementation only needs a means to read and write (512 byte)blocks and a few memory locations.

Cheers,
Thomas


Hi again!

I am grinding through your code, and mostly its easy reading. Only a few 65c02 specific instructions, so they are easy to replace. At least up until now. Then I came accross this code segment which makes less sense to me:

Code:
path_inverse:
      stz krn_tmp
      stz krn_tmp2
      ldy #0
      jsr l_inv
      iny
      lda #0
      sta (krn_ptr2),y
      rts
l_inv:
      lda (krn_ptr3), y
      iny
      cpy krn_tmp3
      beq l_seg
      cmp #'/'
      bne l_inv
      phy
      jsr l_inv
      ply
      sty krn_tmp
l_seg:
      ldy krn_tmp
      inc krn_tmp
      lda (krn_ptr3), y
      ldy krn_tmp2
      inc krn_tmp2
      sta (krn_ptr2), y
      cmp #'/'
      bne l_seg
      rts


The jsr instruction that goes back to its own code segment seems somewhat untraditional. Could you explain what is happening here? :roll:


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Mon Sep 10, 2018 7:54 am 
Offline

Joined: Sun Dec 28, 2014 11:04 pm
Posts: 82
Location: Munich, Germany
kakemoms wrote:
The jsr instruction that goes back to its own code segment seems somewhat untraditional. Could you explain what is happening here? :roll:

You got me there! :-)
The Steckschwein Project is a team effort, and that happens to be not my code. Looks like some kind of recursion to resolve a file path to me.
Let me try to convince my teammate to register here to have him explain it himself. :-)


Top
 Profile  
Reply with quote  
 Post subject: Re: FAT32?
PostPosted: Mon Sep 10, 2018 9:34 am 
Offline

Joined: Sun Dec 28, 2014 11:04 pm
Posts: 82
Location: Munich, Germany
ArnoldLayne wrote:
Let me try to convince my teammate to register here to have him explain it himself. :-)


He does not want to. But he added a few comments to the code to make more clear what's going on:

https://bitbucket.org/steckschwein/stec ... l/util.asm


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: