SPI EEPROM in SD Card Slot - Page 1
Forum section: electronics / beginners

author: AntonioVal
author_rank: Newbie
timestamp: November 13, 2024, 12:36:28 pm
content: Hi,single board computers often boot via SD card. Some also have an extra SPI EEPROM or have SPI pins on the GPIO header.For devices lacking an extra EEPROM is it possible to use the SD Card slot to attach an EEPROM (and boot from it)? SD cards support SPI mode but it is slower than the normal mode.What would be the requirements beyond the flash chip?I have seen some projects like:https://codedbearder.com/posts/nanopi-r4s-spi-flash/"Just the NOR flash chip itself, a decoupling capacitor and a dip switch for enabling write protection and hold functionality, along with some pull-up resistors."orhttps://linux-sunxi.org/Bootable_SPI_flashwhich just uses a flash chip. But they both dont use the SD card pins.

author: Peabody
author_rank: Super Contributor
timestamp: November 13, 2024, 03:38:48 pm
content: It seems it should work if you can separate the card slot from the code that normally drives it. SD cards go through an elaborate initialization protocol, and use special commands for reading and writing, none of which the EEPROM would understand. But if you can use normal SPI drivers to control the card slot, I would guess it would work. However, I've never seen it done that way, and I don't know about booting from it.

author: pcprogrammer
author_rank: Super Contributor
timestamp: November 13, 2024, 06:53:57 pm
content: A SD card slot can either be SPI or dedicated SD card interface. When it is the latter I don't think it will work with an SPI based EEPROM (FLASH memory).Like Peabody wrote a SD card uses a very different protocol for communication and so the processor has to be able to detect the difference.The way it, in most systems, works is that the processor has an internal system ROM that contains the initial boot loader. It depends on how this boot loader works if different startup media can be used.As an example the Allwinner F1C100s uses a internal boot loader that checks if there is a SD card connected to the dedicated SD card interface. If so it reads sector 16 of the card to check if there is a boot loader header. If it is there it starts from the SD card. If not it checks if there is FLASH memory connected to the SPI interface. If so it reads the first 32 bytes to check if there is a boot loader header there. Again if it is there it will start from the FLASH memory. If not, I'm not sure about this, it just stops.So you have to check the specifications of the processor used on the SBC to see what is possible.

author: Peabody
author_rank: Super Contributor
timestamp: November 13, 2024, 10:06:03 pm
content: Quote from: pcprogrammer on November 13, 2024, 06:53:57 pmBut to read sector 16, it first must determine what kind of SD card it is - SD, SDHC, SDXC or whatever. It has to do that because reading a sector is done differently on different kinds of cards. The controller in an SD card will know how to respond to the queries from the MCU, but the controller in the EEPROM won't have a clue. So it would be necessary to change the code that lets you boot from an SD card - if you can find and change that code. Below is an example of the logic tree needed just to determine the card type.

author: pcprogrammer
author_rank: Super Contributor
timestamp: November 14, 2024, 07:09:12 am
content: Quote from: Peabody on November 13, 2024, 10:06:03 pmChanging this code is in case of the F1C100s not possible because it is factory programmed either one time programmable but more likely masked on the die. And it probably will be the same for many of the processors used on SBC's.It is not like it used to be with the 8 bit processors where the start point was set in the processor and all the memory was externally connected to a parallel bus. The process in modern processors is similar, but the memory it starts from is internal and the code is fixed. (with some exceptions maybe)