Page 1 of 1
compiling kernel.c in raspberry pi tutorial error
Posted: Sun Mar 28, 2021 7:17 pm
by Paletech35
I'm following the tutorial on
Raspberry Pi Bare Bones adn trying to compile kernel.c yields many errors:
expected identifier before 'switch' on line 29
In function uart_init, 'UART0_CR' undeclared on line 83 mmio_write(UART0_CR, 0x00000000)
and then many more errors stating things are undeclared, similar to the second one above. I have compiled the cross compiler with arm-none-eabi, and compiling boot.S worked fine. I have no clue whats causing these errors, although at the end of the error list are some warnings as well.
- The list of warnings
Im using cygwin on windows 10 trying to compile for a Pi model 1.
Thanks in advance
Re: compiling kernel.c in raspberry pi tutorial error
Posted: Sun Mar 28, 2021 8:51 pm
by Octocontrabass
You can't have a switch statement inside an enum declaration.
I'm not sure why such an obvious mistake is in the article's sample code, but you can fix it easily enough by removing the switch statement and choosing an appropriate GPIO_BASE value for your target hardware. (Of course, you'll have to come up with something more clever if you want your code to work on more than a single model of Raspberry Pi.)
Re: compiling kernel.c in raspberry pi tutorial error
Posted: Sun Mar 28, 2021 9:25 pm
by Schol-R-LEA
This actually has been mentioned a few different times; while it is clearly an error in the code, I refrained from fixing it
the last time it came up because I wasn't sure if the original developer had something important which was
supposed to be there.
There was some speculation that it was there as a 'copy trap', that is, it was deliberately mis-coded in a way which would be easy to fix in order to discourage readers from trying to use it without going over the code.
Re: compiling kernel.c in raspberry pi tutorial error
Posted: Mon Mar 29, 2021 1:23 pm
by nexos
I personally think this should be fixed. This could greatly confuse some people. I once tried following this tutorial, saw the compiler error, so I figured it was broken. IMO this is just causing problems if it was a copy trap.
Re: compiling kernel.c in raspberry pi tutorial error
Posted: Mon Mar 29, 2021 1:33 pm
by kzinti
I agree. This is just stupid.
Re: compiling kernel.c in raspberry pi tutorial error
Posted: Mon Mar 29, 2021 2:28 pm
by Schol-R-LEA
Fair enough, I'll fix it now (assuming that no one has done it already).
EDIT:
The code I propose using, in order to minimize changes to the rest of the code, goes:
Code: Select all
#define RASPI_MODEL 2
#if (RASPI_MODEL == 2) || (RASPI_MODEL == 3)
#define MODEL_MMIO_BASE 0x3F000000
#elif (RASPI_MODEL == 4)
#define MODEL_MMIO_BASE 0xFE000000
#else
#define MODEL_MMIO_BASE 0x20000000
#endif
int raspi = RASPI_MODEL;
// ...
enum
{
// The MMIO area base address.
MMIO_BASE = MODEL_MMIO_BASE,
// ...
While some of this is a bit redundant, I was trying to keep the effects of the changes to a minimum.
However, when I tried testing this under QEMU, I wasn't able to get the "Hello, World!" output.
Re: compiling kernel.c in raspberry pi tutorial error
Posted: Wed Mar 31, 2021 2:00 pm
by Schol-R-LEA
I still haven't been able to get the print-out to work in emulation. Does anyone else have a working version of this?
Re: compiling kernel.c in raspberry pi tutorial error
Posted: Fri Apr 02, 2021 1:55 pm
by bzt
Schol-R-LEA wrote:Fair enough, I'll fix it now (assuming that no one has done it already).
EDIT:
The code I propose using, in order to minimize changes to the rest of the code, goes:
I believe the purpose of the switch is to detect the board in run-time. So either forget about the detection and "int raspi" on this page entirely, and just link to the page talking about the run-time board detection; or keep "int raspi" and the switch and use a static variable and bunch of defines like
Code: Select all
static uint32_t MMIO_BASE;
#define GPFSEL0 ((volatile uint32_t*)(MMIO_BASE+0x00200000))
#define GPFSEL1 ((volatile uint32_t*)(MMIO_BASE+0x00200004))
instead of an enum.
Schol-R-LEA wrote:I still haven't been able to get the print-out to work in emulation. Does anyone else have a working version of this?
Sadly no, not of this. But you should try my raspi3-tutorials, there's two Hello World tutorial in them, one for mini AUX (uart1), and one for the PL011 (uart0). But I can tell you I pissed blood when I was working on those because it is not documented that on later models (around late RPi2 and early RPi3) the uart clock frequency is not fixed, so in order to use a baud divisor, first you must fixate the uart freq with a mailbox call. (For older models, the mini AUX was CPU clock dependent and PL011 wasn't, for newer models it's the other way around, mini AUX is fixed and PL011 isn't. Took me days of trial-and-error to figure this out.) You could use my tutorials as a base, but they are for RPi3 AArch64 only.
(I got "time out" error for the wiki, is something wrong with the server? Had to wait a lot until forum loaded too)
EDIT: I've modified the code, moved MMIO_BASE from the enum into a variable and mmio_read() and mmio_write(). Please give it a try.
Cheers,
bzt