Hello all,
I am currently developing a kernel on Raspberry Pi 4.
I followed this tutorial https://github.com/bztsrc/raspi3-tutorial but failed when I try to read and write something to the SD card.
It seems to have some problem when sending the eMMC command to the SD card module.
I am wondering is there any implementation of reading/writing content of SD card on Raspberry Pi 4?
Oscar
-
- Posts: 3
- Joined: Sat Mar 27, 2021 2:08 pm
Re: Read/write SD card on Raspberry Pi 4?
Are you sure your SD-card is in writeable mode?
I hate programming.
I hate programming.
Holy sh*t it works!
I love programming.
I hate programming.
Holy sh*t it works!
I love programming.
-
- Posts: 7282
- Joined: Sat Aug 18, 2012 2:33 pm
Re: Read/write SD card on Raspberry Pi 4?
Code: Select all
#define EMMC_ARG2 ((volatile unsigned int*)(MMIO_BASE+0x00300000))
from my own research
that code, is for driving the old SDHCI controller
on the pi3, it could be muxed to either wifi or SD via the normal gpio altfunc array, which that code is doing via sd_init()
but on the pi4, the SD slot isnt part of the gpio array anymore
there is a new high-speed mux dedicated to the SD interface, that will switch it between the old SDHCI and the new EMMC2
both are following the same standard, and should work with the same drivers
https://github.com/librerpi/rpi-open-fi ... xt#L63-L78
you either need to use the new mux to route the SD slot to SDHCI, or modify the driver to use EMMC2's base address
Re: Read/write SD card on Raspberry Pi 4?
I was trying for months to get my SD card driver working on the RPi 4. The relatively obvious modifications required are to use the base address of EMMC2 at 0xFE340000 and to fetch the base clock rate from the firmware with clock ID 12 for EMMC2. But this was not enough. Then I found that there is difference between the EMMC controllers of the RPi 1-3 and RPi 4. The RPi 4's controller is more compliant with the standard and requires to set the SD bus power VDD1 to 3.3V at initialization, which was not needed on the RPi 1-3, like that:
Code: Select all
#define EMMC_CONTROL0 (0xFE340000 + 0x28)
u32 control0 = read32 (EMMC_CONTROL0);
control0 |= 0x0F << 8;
write32 (EMMC_CONTROL0, control0);
-
- Posts: 7282
- Joined: Sat Aug 18, 2012 2:33 pm
Re: Read/write SD card on Raspberry Pi 4?
there are also 2 external GPIO lines, to control the IO voltage and SD power, which must be accessed via the mailbox
the engineers have been a bit dodgy with questions, but i think the io voltage one is using a mosfet to switch an IOREF pin between 1.8v and 3.3v
that IOREF goes back into the SoC, and sets the level for the SD pins coming back out
the SD power gpio, then just lets you enable/disable the main 3.3v supply to the uSD socket, but earlier revisions lack that
once a card is in 1.8v mode, you have to power-cycle it to get it back into 3.3v mode
the official firmware does that for you, and runs your kernel while the card is still in a 3.3v mode i believe
Re: Read/write SD card on Raspberry Pi 4?
cleverca22 wrote: ↑Fri Apr 02, 2021 9:04 pmthere are also 2 external GPIO lines, to control the IO voltage and SD power, which must be accessed via the mailbox
Yes, I forgot to mention, that the driver is disabling the 1.8V power, by writing a 0 to the external GPIO pin 4 using the property mailbox function 0x38041, because it is not using the 1.8V. I added 0x80 to the pin number for the external GPIO.
Not sure, if it is really necessary, but the driver works on a RPi 4B v1.1 and RPi 400 here and I did not hear about problems with it.
Re: Read/write SD card on Raspberry Pi 4?
Hi @rst,
do you have a working source code somewhere?
I've searched for 0x38041 in Circle to see what mailbox call you were referring to, but I had no luck finding it.
In order to make my code RPi4 compatible, I've changed the address to eMMC2, I've added the voltage config in EMMC_CONTROL0 you mentioned, but it is unclear what to do with these mailbox calls (my code for RPi3 does not query the eMMC freq, it only sets the speed by writing registers. Is this going to be a problem on RPi4?) Sadly I don't have a RPi4 board, so I'm flying blind.
Cheers,
bzt
do you have a working source code somewhere?
I've searched for 0x38041 in Circle to see what mailbox call you were referring to, but I had no luck finding it.
In order to make my code RPi4 compatible, I've changed the address to eMMC2, I've added the voltage config in EMMC_CONTROL0 you mentioned, but it is unclear what to do with these mailbox calls (my code for RPi3 does not query the eMMC freq, it only sets the speed by writing registers. Is this going to be a problem on RPi4?) Sadly I don't have a RPi4 board, so I'm flying blind.
Cheers,
bzt
Re: Read/write SD card on Raspberry Pi 4?
Hi @bzt, here it is.
Try 0x00038041 and it will work.I've searched for 0x38041 in Circle to see what mailbox call you were referring to, but I had no luck finding it.

It's probably not easy to get this working without the hardware.In order to make my code RPi4 compatible, I've changed the address to eMMC2, I've added the voltage config in EMMC_CONTROL0 you mentioned, but it is unclear what to do with these mailbox calls (my code for RPi3 does not query the eMMC freq, it only sets the speed by writing registers. Is this going to be a problem on RPi4?) Sadly I don't have a RPi4 board, so I'm flying blind.

Cheers
Re: Read/write SD card on Raspberry Pi 4?
Thank you!!!
Ahhh, I've tried 38041 too but that's not working either since github search only matches whole words as it turned out... Thank you!
Yes, absolutely. I miss the trial-and-error experiments very much. I'll try to learn from your code, adapt that to my code and then get an RPi4 somehow to actually test if it's working.
Cheers,
bzt