xistor 910619de4c fix missing semicolon | 1 年間 前 | |
---|---|---|
.. | ||
Makefile | 5 年 前 | |
Makefile.clang | 2 年 前 | |
Makefile.gcc | 2 年 前 | |
OLVASSEL.md | 2 年 前 | |
README.md | 2 年 前 | |
delays.c | 1 年間 前 | |
delays.h | 6 年 前 | |
fat.c | 2 年 前 | |
fat.h | 6 年 前 | |
gpio.h | 6 年 前 | |
kernel8.img | 4 年 前 | |
link.ld | 6 年 前 | |
main.c | 6 年 前 | |
mbox.c | 6 年 前 | |
mbox.h | 6 年 前 | |
sd.c | 6 年 前 | |
sd.h | 6 年 前 | |
start.S | 3 年 前 | |
uart.c | 6 年 前 | |
uart.h | 6 年 前 |
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 ...
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.
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.