xistor 910619de4c fix missing semicolon hai 1 ano
..
Makefile 426205e2a3 Added makefiles for LLVM Clang %!s(int64=5) %!d(string=hai) anos
Makefile.clang 9c5c2813a0 Update QEMU command in all README and Makefile %!s(int64=2) %!d(string=hai) anos
Makefile.gcc 9c5c2813a0 Update QEMU command in all README and Makefile %!s(int64=2) %!d(string=hai) anos
OLVASSEL.md 9c5c2813a0 Update QEMU command in all README and Makefile %!s(int64=2) %!d(string=hai) anos
README.md 47022f22d7 Fixed typos %!s(int64=2) %!d(string=hai) anos
delays.c 910619de4c fix missing semicolon hai 1 ano
delays.h 7ace64ba9f Initial commit %!s(int64=6) %!d(string=hai) anos
fat.c a9a9d5234a Update fat.c %!s(int64=2) %!d(string=hai) anos
fat.h 7c337daa89 change access to unaligned data to use individual "char" %!s(int64=6) %!d(string=hai) anos
gpio.h 7ace64ba9f Initial commit %!s(int64=6) %!d(string=hai) anos
kernel8.img 8ce0f75b47 Recompiled with latest gcc %!s(int64=4) %!d(string=hai) anos
link.ld 7ace64ba9f Initial commit %!s(int64=6) %!d(string=hai) anos
main.c 7ace64ba9f Initial commit %!s(int64=6) %!d(string=hai) anos
mbox.c 214885df63 compute the mailbox cmd only once %!s(int64=6) %!d(string=hai) anos
mbox.h 7ace64ba9f Initial commit %!s(int64=6) %!d(string=hai) anos
sd.c 0c0b9a5b21 Fixed newline %!s(int64=6) %!d(string=hai) anos
sd.h 7ace64ba9f Initial commit %!s(int64=6) %!d(string=hai) anos
start.S ea4691947c Improve comments wrt stack setup %!s(int64=3) %!d(string=hai) anos
uart.c 8a80ab88b9 Clearified mbox call in uart per issue #49 %!s(int64=6) %!d(string=hai) anos
uart.h 7ace64ba9f Initial commit %!s(int64=6) %!d(string=hai) anos

README.md

Tutorial 0D - Read File

We learned how to read and parse the root directory. In this tutorial we'll get one file from the root directory, and walk through the cluster chain to load it entirely into memory.

$ qemu-system-aarch64 -M raspi3b -drive file=test.dd,if=sd,format=raw -serial stdio
        ... output removed for clarity ...
FAT File LICENC~1BRO starts at cluster: 00000192
FAT Bytes per Sector: 00000200
FAT Sectors per Cluster: 00000004
FAT Number of FAT: 00000002
FAT Sectors per FAT: 00000014
FAT Reserved Sectors Count: 00000004
FAT First data sector: 00000054
        ... output removed for clarity ...
00085020: 43 6F 70 79  72 69 67 68  74 20 28 63  29 20 32 30  Copyright (c) 20
00085030: 30 36 2C 20  42 72 6F 61  64 63 6F 6D  20 43 6F 72  06, Broadcom Cor
00085040: 70 6F 72 61  74 69 6F 6E  2E 0A 43 6F  70 79 72 69  poration..Copyri
00085050: 67 68 74 20  28 63 29 20  32 30 31 35  2C 20 52 61  ght (c) 2015, Ra
00085060: 73 70 62 65  72 72 79 20  50 69 20 28  54 72 61 64  spberry Pi (Trad
00085070: 69 6E 67 29  20 4C 74 64  0A 41 6C 6C  20 72 69 67  ing) Ltd.All rig
        ... output removed for clearity ...

Fat.h, fat.c

This is also easy and pretty well documented. We locate the directory entry for our file, and get the starting cluster number. Then we load each cluster into memory as we walk the cluster chain.

fat_getpartition() load and check the boot record of the first MBR partition.

fat_getcluster(fn) return the starting cluster for the given filename.

fat_readfile(clu) reads a file into memory, returns pointer to the first byte.

Main

Once we initialize EMMC to read sectors, we load the boot record of the first partition. If the BPB describes a valid FAT partition, we find the starting cluster for the file 'LICENCE.broadcom'. If that not found, we'll look for 'kernel8.img'. If any of these found, we load it and dump it's first 512 bytes.