xistor 910619de4c fix missing semicolon 1 年之前
..
Makefile 426205e2a3 Added makefiles for LLVM Clang 5 年之前
Makefile.clang 9c5c2813a0 Update QEMU command in all README and Makefile 2 年之前
Makefile.gcc 9c5c2813a0 Update QEMU command in all README and Makefile 2 年之前
OLVASSEL.md 6cf2541942 Fixed issue #62 4 年之前
README.md 28fa056d41 Fix typo in `15_writesctor` 2 年之前
delays.c 910619de4c fix missing semicolon 1 年之前
delays.h e1062c8e0c Added new tutorial for Bruce 5 年之前
gpio.h e1062c8e0c Added new tutorial for Bruce 5 年之前
kernel8.img 6cf2541942 Fixed issue #62 4 年之前
link.ld e1062c8e0c Added new tutorial for Bruce 5 年之前
main.c e1062c8e0c Added new tutorial for Bruce 5 年之前
mbox.c e1062c8e0c Added new tutorial for Bruce 5 年之前
mbox.h e1062c8e0c Added new tutorial for Bruce 5 年之前
sd.c 6cf2541942 Fixed issue #62 4 年之前
sd.h e1062c8e0c Added new tutorial for Bruce 5 年之前
start.S ea4691947c Improve comments wrt stack setup 3 年之前
uart.c c59ad439f4 Enable UART0 FIFOs 3 年之前
uart.h e1062c8e0c Added new tutorial for Bruce 5 年之前

README.md

Tutorial 15 - Write Sector

Let's go back to tutorial 0B for a moment, and add a function to write the SD card. To test it, we'll implement a boot counter. We're going to read a sector into memory (same as in 0B), increase a counter in the sector buffer, then save it back to the SD card. This way every time we reboot this image, the counter should be increased.

For the counter I've choosen the last 4 bytes of the 2nd sector. I did not want to use the first sector, as that could mess up the Master Boot Record and render our card unbootable. Second sector is safer, although if you're using an EFI Partitioning Table (like I do), then the counter could mess up that too. So I've choosen the last 4 bytes of the sector hoping the table is shorter than 508 bytes. If this not the case for you, then change the COUNTER_SECTOR define to point to a surely unused sector on your SD card.

I'd would like to say thanks to @DamianOslebo for thgroughful testing and spotting a bad constant in the command defines.

Sd.h, sd.c

I've added new commands (CMD_WRITE_SINGLE, CMD_WRITE_MULTI) and new status flags (SR_WRITE_AVAILABLE, INT_WRITE_RDY) to our driver. We'll use them instead of their READ counterparts.

sd_writeblock(buffer,lba,num) write num blocks (sectors) from the buffer into the SD card starting at sector lba.

Main

We read a block after the bss segment in memory, and increase a counter in it, and save it back to the card. If everything went well, we print the actual counter value on the console.