SD/MMC bootloader

Hi all,

I’m new to AVRs, but I love them so far… I was thinking about writing a bootloader that would look look for a binary image on an SD/MMC card on boot. If it was there, then flash the AVR from it. It seems this would be handy for in-field upgrades, it would also be extremely fast…etc, etc. My question is: Has anyone already done an open-source implementation of this idea for the ATMega series? If not, I’ll get one started this weekend…

If you use gcc they have examples of interfacing a FAT16/32 SD/MMC card. I can’t remember were the link was. If I find it I’ll post it. It would be easier then carring a laptop and ISP.

EDIT: Found it [AVRlib](http://hubbard.engr.scu.edu/embedded/avr/avrlib/)

tvelliott:
…If not, I’ll get one started this weekend…

Hi TV. This sounds really interesting. Did you find what you were looking for? Can you post some links?

roach:

tvelliott:
…If not, I’ll get one started this weekend…

Hi TV. This sounds really interesting. Did you find what you were looking for? Can you post some links?

No, I didn’t find one, but I am almost done with writing one. I can program the entire program space on the ATMega128 in less than 7 seconds. I will post a link here when I’m ready to publish the code.

hi tvelliott

I would be verrrry interested in this. please keep us posted.

dan

gonzzo:
hi tvelliott

I would be verrrry interested in this. please keep us posted.

dan

As promised, here it is.

Hope you enjoy!!

http://hanfordsite.com/files/mega_mmc_b … -12-30.zip

tvelliott:
As promised, here it is.

Thanks for this great hack on Pascal Stang’s code! I was trying to do something like this a few months ago.

sonos:

tvelliott:
As promised, here it is.

Thanks for this great hack on Pascal Stang’s code! I was trying to do something like this a few months ago.

I’m not aware of any code from Pascal Stang in here, but I did try to give credit due to Sham et al for the FAT16 implementation. Also, Paul @ pjrc.com for a good writeup on FAT32.

Have fun!

I thought there would be a lot more response to it. Sure has made development easier for me

[edit]

Here are some references

This is the majority of what I started with. There are a lot of bugs in this code. I also

stripped out all the write code, as we don’t need it for a bootloader that has to fit in 4K.

I merged in some of my own mmc code. I think I would have been better off starting from

scratch, but here it is

ftp://ftp.circuitcellar.com/pub/Circuit … ham176.zip

mmc code reference (this is the bible of mmc/sd spi mode access)

http://www.sandisk.com/Assets/File/OEM/ … mcv1.0.pdf

FAT32 reference mostly from here

(no code, but a great reference)

http://www.pjrc.com/tech/8051/ide/fat32.html

After some more research, I’m not sure if more credit should go to Pascal Stang or Sham et al.

I guess I would just like to add that I went through every part of the code I have presented here. Give credit to whomever you please. Bottom line is that the code I have presented has been tested on several different brands and sizes of SD/MMC cards with FAT16 and FAT32 file systems formatted with Windows and Linux mkfs.vrat and mfs.msdos. I have used the fat code in an mp3 player that I developed. It is working at 320kbps. Hope it works for you.

Cheers,

tve

This is AWESOME!

I was toying with the idea of implementing a bootloader that could support having a bunch of different programs on an MMC or CF card, that the bootloader could load whatever program the user selected from a list (via some unspecified input method. Possibly touchscreen or just over UART).

This will be a great starting point. Thanks!

Great Job! :stuck_out_tongue:

Takes me a few hours to adapt it to my hardware and than it was working without any change in your code. (less than 3700 words in total, there is some room to add features in the available 4096 word space)

I have some few comments/improvements:

a) MMC init should be done with a lower SPI clock frequency (thats according the MMC/SD spec). I am now starting with a slower clock and after mmc_init() i switch to the fastes SPI clock.

b) i am first checking if a SD/MMC card is in the slot at all. If not i jump immediately to 0 → increases the boot time

c) the timeout in the spi_put()/spi_get() routines is quite long. I reduced it from 0x2000 to 0x100

d) i would like to have FAT12 support also, because i am using small SD cards normally. Perhaps i will add this to the code

Thanks a lot for publishing

Hi, I was looking for the same. but the file is not downloadable pls do the needful.

I think this is it:

http://www.mikrocontroller.net/topic/67047#new