jsandler18 / raspi-kernel Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Thank you for your amazing tutorial series. It has been so informative and I have learnt loads!
I'm just having one problem with lesson 09. I'm compiling for my 64-bit Pi 3 (I am not following the tutorial series, only this specific section), and I can not compile the code (I changed the registers to work with 64-bit):
try_lock: mov x1, #0 swp x2, x1, [r0] // stores the value in x1 into the address in x0, and stores the value at the address in x0 into x2 mov x0, x2 blx lr
My error message is "Error: selected processor does not support `swp x2,x1,[x0]'!". Apparently the "swp" instruction was deprecated and removed, and does not exist on later Pi models. Is there a newer, better instruction to accomplish an atomic lock? Or is it my toolchain at fault? I have tried building with -mcpu=cortex-a7 but it tells me it's not a valid CPU, instead suggesting I try cortex-a53, but even then, I get the same error about the instruction not being supported.
When I run the command 'make', I get this error:
/mnt/c/users/andre/desktop/custom_rpi_os/gcc-arm-10.2-2020.11-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc -T linker.ld -o kernel.elf -ffreestanding -O2 -nostdlib objects/mailbox.o objects/mem.o objects/interrupts.o objects/atag.o objects/kerio.o objects/uart.o objects/gpu.o objects/process.o objects/timer.o objects/kernel.o objects/model2/framebuffer.o objects/stdlib.o objects/process_asm.o objects/interrupt_vector.o objects/boot.o objects/lock_asm.o
/mnt/c/users/andre/desktop/custom_rpi_os/gcc-arm-10.2-2020.11-x86_64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/10.2.1/../../../../arm-none-eabi/bin/ld: objects/model2/framebuffer.o:/mnt/c/Users/andre/desktop/custom_rpi_os/raspi-kernel-master/build/../include/kernel/framebuffer.h:20: multiple definition of `fbinfo'; objects/gpu.o:/mnt/c/Users/andre/desktop/custom_rpi_os/raspi-kernel-master/build/../include/kernel/framebuffer.h:20: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:39: build] Error 1
How can I fix this issue?
(I am on Ubuntu WSL)
I'm trying to get this code running on my RPi4B and I can't seem to get it working. I've changed PERIPHERAL_BASE to 0xFE000000 as documented here, but my Raspberry Pi gets stuck on the rainbow screen when booting. Does anyone have advice for further debugging this issue?
I've installed Raspbian on my SD card, and have deleted the other kernel images and replaced kernel7.img with the image built from the Makefile. On QEMU I'm able to run it fine (as long as I switch the PERIPHERAL_BASE back to the 2/3 address)
It only prints to the screen from the main thread.
When run on QEMU. Haven't tried on RPI
Compiling the OS code in the repository gives me u definitened reference errors to move_exception_vector
try_lock
and switch_to_thread
. Am I doing something wrong? Or is there an issue in the makefile?
Your code to disable three of the four processors does not work properly for me.
I have tested with my own C code, that just switches a few gpios on and off on a raspberry pi 3, and with your current boot.S code, my code is not launched.
However, if i replace the line cmp r1, #2
by cmp r1, #0
, it works.
If i understand correctly, the effect of that change is that my code runs on the core 0, instead of the core 2. No idea why it makes a difference, maybe core 0 is special, somehow?
Is there any reason why you choose to use core 2?
The code at the top of the page is fine, but the line-by-line explanation missed out the extra push/pop of r1 that you have to wrap around the line
bl irq_handler
Of course, it's pretty clear why it's necessary -- but it probably needs a mention, at least so that people who are typing in the code as its explained rather than copy/pasting from the top of the page don't get confused.
In the code shown for the kernel.c
file in the tutorial on this page, there is a # symbol that shouldn't be there. Removing it fixes the code.
raspi-kernel/src/kernel/interrupt_vector.S file has a minor typo in line 35, just so you know
Combining the heap segments to the left does not update the seg->next->prev
pointer to point to the previous heap segment.
Similar problem when combining on the right where the seg->next->next->prev
pointer is not updated to the current heap segment.
Freeing pointers in the same order they were allocated is causing the segment_size
field to become larger than the amount in the initial heap segment. I haven't tested any other scenarios but correctly setting the pointers as outlined above along with null checks solved the issue.
When I run the latest commit in the qemu emulator and connect to the VNC server with vncviewer, the screen stays black and nothing that I type in the terminal get's echo'ed back. I can't see any boot text either.
Where do I start with debugging?
I downloaded and built the "master" branch code, or part 06 branch code.
It runs smoothly on qemu-system-arm simulator,
but when I renamed the kernel.img to kernel7.img and copied to the raspbian SD card of the real raspi 2 hardware, it doesn't run at all, just blank black screen (I disabled the raspi colour splash test). I also tried to change the gpu.c BLACK colour to BLUE, it worked in simulator, but doesn't work on real hardware.
To double check, when I switch back the raspbian kernel7.img, the raspberry pi runs without issue. The hardware is raspberry pi 2 B model.
As the title suggests, trying to build qemu from the source provided throws a number of errors, its better to just clone the current github repo and compile build that or just download qemu-system-arm
from your package manager if it is included
You need to define these functions as extern inline in header and implement the logic in interrupts.c.
Else the build process will fail, with an undefined reference error.
When I go in to debug or just print out the value of atags in kernel.c after completing step 5 I always get an address of 0 for the atags variable and mem_init doesn't work because the mem_size that it computes it 0.
This seems related:
https://seasonofcode.com/posts/qemu-arm-boot-tags.html
Hi
Many thanks for this tutorial.
I stuck on the 2nd step on booting the myos.elf on qemu.
The emulation gives a black screen.
I'm using a macbook pro (macos mojave)
Thanks
A couple possible issues with mem.c, in alloc_page
:
-The address of the start of the page is calculated by page_mem = (void *)((page - all_pages_array) * PAGE_SIZE);
, however page_t has size 4 bytes, so page_mem
is 4x too big as each entry in all_pages_array
is 4 bytes.
-In allocating a page, you do not check if the page is part of the MMIO region, so a program could start writing data here erroneously.
Sorry if these aren't issues or I'm wrong about indexing into all_pages_array, I'm fairly new to this.
First of all, I am getting errors around line 64 in gpu.c complaining about how declaring 'i' and 'j' in the for loop requires c99. Defining the variables outside the for loop does the trick, though.
Secondly, I am having issues compiling process_asm.s, due to a bad expression.
arm-none-eabi-gcc -mcpu=cortex-a7 -fpic -ffreestanding -g -I../src/kernel -c ../src/kernel/process_asm.S -o objects/process_asm.o
../src/kernel/process_asm.S: Assembler messages:
../src/kernel/process_asm.S:17: Error: bad expression -- `ldr r0,=#(10000)'
I cloned your repo of section 9, corrected some of the paths in the Makefile, and compiled.
If I play with the syntax of =#(10000)
, sometimes I can get it to compile. However, I just get a wall of errors:
/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: multiple definition of `ENABLE_INTERRUPTS'
objects/interrupts.o:/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: first defined here
objects/process.o: In function `INTERRUPTS_ENABLED':
/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: multiple definition of `DISABLE_INTERRUPTS'
objects/interrupts.o:/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: first defined here
objects/timer.o: In function `INTERRUPTS_ENABLED':
/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: multiple definition of `INTERRUPTS_ENABLED'
objects/interrupts.o:/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: first defined here
objects/timer.o: In function `INTERRUPTS_ENABLED':
/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: multiple definition of `ENABLE_INTERRUPTS'
objects/interrupts.o:/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: first defined here
objects/timer.o: In function `INTERRUPTS_ENABLED':
/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: multiple definition of `DISABLE_INTERRUPTS'
objects/interrupts.o:/Users/gmisail/Downloads/raspi-kernel-93d44a737728aa5fe366ad8ca62563e78987b023 2/build/../include/kernel/interrupts.h:17: first defined here
collect2: error: ld returned 1 exit status
Thank you
I am trying to show ur OS on a real Screen.(Part 6). But my screen keeps black.
My raspys 1 + 2 work fine-> i checked it with other OS.
I followed ur tutorial until part 6. I got my Images and loaded them on my Card. After copieing them into my old OS installation of Rasphian i get stuck in the rainbow screen. If i tun the Rainbow Screen off, the Raspie get suck in blackscreen. Same on both(1+2). After 42 tries it surrendered.:(
Could someone assure me, that this tutorial still works in 2021? And inform me about , how u got it on the rean screen.
I am using windows subsystem for linux (WSL) on windows 10 - ubuntu app.
When I run the line "./configure --target-list=arm-softmmu,arm-linux-user" from the qemu folder I get:
ERROR: Python not found. Use --python=/path/to/python
So I run: " ./configure --target-list=arm-softmmu,arm-linux-user --python=/mnt/c/Python27"
And I get:
./configure: 1576: ./configure: /mnt/c/Python27: Permission denied
ERROR: Cannot use '/mnt/c/Python27', Python 2.6 or later is required.
Note that Python 3 or later is not yet supported.
Use --python=/path/to/python to specify a supported Python.
My Python version on /mnt/c/Python27 is 2.7.16
I'm very new to linux and I would very much appreciate any help
Thank you
I've copied the code from part two and compiled it. When I run it in qemu-system-arm
I get something like this:
HHeello, kernel World!
llHo, ello, kernel World!
kernel World!
Hello, kernel World!
Further, when I try to type I get the letter followed by a varying number of newlines. I tried looking at it with GDB and as near as I can determine there are four different instances of the kernel running (presumably on the four cores), which means all four of them race each other to initialize the UART and run uart_getc()
.
Is there a step I've missed to get the kernel to only start on one core?
In the file process_asm.S there might be an issue (I have been testing on a raspberry pi 2)
According to the arm specification, you should never push the sp ("reglist must not include the SP." from here). I tried out your code on my pi and that line seemed to be crashing it. So I think line 11 of process_asm.S should be changed to push {lr}
as we usually just want garbage there.
When I try to link kernel.o, I get this error:
~/Downloads/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gcc -T linker.ld -o myos.elf -ffreestanding -O2 -nostdlib boot.o kernel.o
kernel.o: In function `uart_putc':
kernel.c:(.text+0x88): undefined reference to `mmio_read'
kernel.o: In function `uart_getc':
kernel.c:(.text+0xb4): undefined reference to `mmio_read'
kernel.c:(.text+0xc8): undefined reference to `mmio_read'
collect2: error: ld returned 1 exit status
Surprisingly, I get nothing relevant when I try to search the web for this problem. I think I'm missing some library specific to the rpi, which needs to be passed to the linker.
I am trying to get the timer to work on the Raspberry Pi 2B v1.1 but it is not working. I use the UART for debugging and every time the timer interrupt should be called, the reset handler is called.
I have changed the "kerio.c" to output via the UART. In the timer interrupt in "timers.c" a text should be output. In "kernel.c" additionally the UART is initialized and the timer is set to 5 seconds. After 5 seconds the reset handler is called instead of the timer interrupt.
when i run the command "arm-none-eabi-gcc build/Makefile" after completing step 3 it gives me this error:
build/Makefile: file not recognized: file format not recognized
collect2.exe: error: ld returned 1 exit status
Hello hope you read this! Forked this after reading your guide, I cannot get QEMU to work as of now, what is the new qemu command that we can use as of the most recent commit you have? Currently I just run it and it hangs saying man0 and doesn't appear to echo or do anything. Any thoughts?
Running processes indefinitely works as a charm. But as soon as a process finishes, the context switch does not work any longer.
I found out, that all values inside the reap
method are correct during execution. Also, when reaping the last process other than the init process, the run_queue
size is 0 after popping it, but in the very next call to schedule
, the run_queue
's size is back to 1 again. As there is in reality nothing in there, the following pop
fetches illegal content, where it starts doing weird stuff.
Verifying the pid
field of new_thread
and the current_process
also shows, that even the current_process
is an illegal access (as pid
is a high number and proc_name
is scrambled).
So I would take a wild guess, that something in the switch_to_thread
assembly may be problematic.
I would guess the reaped thread must be called to a context switch, that disregards everything from the old thread, as the memory has already been freed.
Could you please verify it or maybe you have an idea to solve that?
Please provide information on implementation on header files.
For example part 3.
I would like to understand the implementation details and why you did it that way.
Only in the explanatory text, not in the codebase.
In mem.c at
while(seg->next != NULL && !seg->next->is_allocated) {
seg->next->next->prev = seg;
seg->next = seg->next->next;
seg->segment_size += seg->next->segment_size;
}
a seg = seg->next;
is needed at the end. Otherwise the loop iterates over the same segment over and over.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.