2

I've been following this tutorial showing you how to write a custom kernel for the raspberry pi. Everything's working out well, but I can't figure out how to read files from the boot partition of the sd card.

I'm able to detect if the file is there by looking at the return value of the open function and get the file's size using fstat, but I'm not able to read the contents at all. Is there something I'm missing or forgetting to do?

The OK LED (and other GPIO) is the only output I have, so I'm using that to signal that the file has been read.

int pfd = open("hello.txt", O_RDWR);

char buf[100];
ssize_t bytes_read = read(pfd, &buf, 2);

if (bytes_read == 0) {
  LED_ON();
}

The LED doesn't turn on :(

2

In bare metal , file access doesn't work automatically. You need to implement a SD card reader driver and a FAT32 driver before file access works even remotely correctly. This is the whole point of bare metal after all.

The C libary simply makes the assumption those things are present , as if bare metal were a "hosted" implementation of C.

Copy or write an SD card reader driver and a FAT32 driver and connect all parts. This will be a great learning experience and illustrates perfectly how many services an OS like Raspbian Linux provides to a "hosted" C enviroment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.