OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:40 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: compiling kernel.c in raspberry pi tutorial error
PostPosted: Sun Mar 28, 2021 7:17 pm 
Offline

Joined: Sun Mar 28, 2021 6:30 pm
Posts: 8
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.
Attachment:
File comment: The list of warnings
warnings.PNG
warnings.PNG [ 16.24 KiB | Viewed 9291 times ]

Im using cygwin on windows 10 trying to compile for a Pi model 1.
Thanks in advance


Top
 Profile  
 
 Post subject: Re: compiling kernel.c in raspberry pi tutorial error
PostPosted: Sun Mar 28, 2021 8:51 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.)


Top
 Profile  
 
 Post subject: Re: compiling kernel.c in raspberry pi tutorial error
PostPosted: Sun Mar 28, 2021 9:25 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
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.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: compiling kernel.c in raspberry pi tutorial error
PostPosted: Mon Mar 29, 2021 1:23 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: compiling kernel.c in raspberry pi tutorial error
PostPosted: Mon Mar 29, 2021 1:33 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
I agree. This is just stupid.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: compiling kernel.c in raspberry pi tutorial error
PostPosted: Mon Mar 29, 2021 2:28 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
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:

#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.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: compiling kernel.c in raspberry pi tutorial error
PostPosted: Wed Mar 31, 2021 2:00 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
I still haven't been able to get the print-out to work in emulation. Does anyone else have a working version of this?

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: compiling kernel.c in raspberry pi tutorial error
PostPosted: Fri Apr 02, 2021 1:55 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
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:
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group