Free online course on building a simple Raspberry Pi OS from the University of Cambridge
This summer, the University of Cambridge Computer Lab has been home to a small group working on projects with the Raspberry Pi. Alex Chadwick is one of those people, and he’s produced this: a free course on building a very simple operating system for the Raspberry Pi in assembly language.
The course opens with some explanations about what assembly language is – and, importantly, what an operating system really is; you’ll learn some new concepts and possibly some new terms, and then you’ll dive headlong into practical work. You will work through sessions which teach you how to enable and manipulate one of the board’s LEDs, then learn some graphics theory and start generating lines, text and random numbers. Eventually you’ll be manipulating text to display computed values, and learning how to build your own command line interface. Alex has also given you instructions on building your own USB HID driver, which is a really useful way of getting to understand the USB controller that’s already on the Raspberry Pi. There’s a section of downloads with answers to every exercise, so you can keep an eye on your progress.
This is not meant for those new to programming (you’ll find it easier if you’ve got some experience), but should be accessible even if you’re new to assembly language if you are smart and persistent. This is as much a course on bare-metal programming as it is on OS building. It’s not easy, and it’s not meant to be; we expect you to find this course challenging – and you should find you come out of it with a great deal of skill and knowledge that you didn’t have before.
There’s a growing bare-metal programming community emerging around the Raspberry Pi (we’ve had to make a separate subforum for them in our message boards so they’ve got somewhere to talk to each other in ones and zeros), and they’re a really friendly and helpful group – if you get stuck at any point, drop in there and they’ll answer your questions. Alex will also be dropping into the comments below if you have anything you’d like to ask about the course.
Many thanks to the University of Cambridge Computer lab for making the course available, and especially to Alex. Alex does plan on extending the course in the future – but for now, you’ve got twelve lessons to get through which will have you bending your brain in ways which might be new to you, so I’ll let you get straight to it.
This is absolutely fantastic – a wealth of information for free! I hope it helps me and others like truly get to grips with some of the fundamentals of how computers work at the nuts and bolts level, instead of being some mysterious magic box. Thanks to all concerned.
> (we’ve had to make a separate subforum for them in our message
> boards so they’ve got somewhere to talk to each other in ones and zeros)
There are only 10 types of people in the world: those who understand binary and those who don’t.
So, 2 then…. ;-)
There are only 10 types of people in the world: those who understand binary, those who don’t, and those that think they do!!
10 represents 3 states in a binary collection.
There have been more security holes in software because of that than anything else in programming.
That’s like saying ‘2’ represents 3 states: 0, 1, 2.
There are only 0x10 people in the world, those who understand hex and fifteen other types who really should learn it!
Fantastic stuff! I feel a new career coming on….(Well, I’m only 47!) :-)
I agree – this is just brilliant!
Well Done Alex! – I look forward to any future extensions you may feel like adding
Is there a way to add comments to make the code somewhat readable?
BTW, I’m on Lesson 3, and your course is awesome!
I googled comments in GNU assember, which revealed this is the format of comments:
/* some stuff here
even more stuff */
and single line:
/* some stuff here */
This was the first thing that came to my mind when I first heard about the RiPi so I was really excited when I saw Alex at the Cambridge open day. It’s great to see that the tutorials are finally public!
In Lesson 10 he says: “I set out searching for a free driver that would run in an operating system that doesn’t even know what a file is yet, but I couldn’t find one.”
Did he consider the JTR/Honken open-source USB stack designed for PIC microcontrollers? There is some description of it here: http://dangerousprototypes.com/2012/06/06/open-source-usb-echo-demo-wiki/
We were promised robots
“Did he consider the”
Asking him what he considered makes more sense than asking this question here.
“we expect you to find this course challenging”, challenging I’m sure it is.
Education is what the Pi was built for and this fits the bill perfectly, I’ve been getting interested in assembler recently, I’d love to do this course but don’t think I’ve got the time at the moment (2 kids under 6 sap most of what’s free). One day…
I’ve found this series of video tutorials to be very helpful in learning assembly
That’s for x86 processors though, so it won’t be of much use with a Raspberry Pi.
Great to see bare metal programming on the front page, Alex has done a great job of breaking it down into easy to understand chunks.
Hopefully this will encourage young people to see learning assembly as useful for better understanding of how things work at a lower level and how it may help you get a place in the right University.
Not that theres any jobs for assembly programmers these days.
Saw one today
There are some jobs for assembler only projects, for PIC or other 8 bitters, but there are a lot more jobs for low-level C and assembler programmers. In fact I haven’t seen such demand for many years. If you have some real-time/embedded, C and assembler experience you could easily get a job right now. ARM and embedded Linux are also really desirable skills. I hear there are employers offering a good starting bonus for people with the right skills.
It’s good to see RPF catching up with the idea that “behind the scenes” coding is an employable skill, as much as Python and web programming.
The problem is unless you have some forum of University degree they are just not interested.
I have all those skills, have codes both a x86 and arm OS’s, won many assembly coding competitions, the same with electronics.
But still unemployed.
Lars Tørnes Hansen
From a friend, I got a trick : Be active on social medias, fx. Linkedin, and twitter, and have an about.me page. From those social medias, write about your DIY software projects with links to the code on fx github.com, so they can see what you can do. I has recently got more success with that kind of visibility.
This is really awesome!
I noticed a couple of times that while reading, all sorts of questions pop up in my head. Most of them are being answered in the paragraphs that follow. It makes the reading very enjoyable.
Thanks Alex, great work!
Interesting, Can there a section be introdtced to write your own kernel to the SD? That is add the bootsector and the “binary blob” of the GPU.
At the moment it’s about as low level as the Pi goes. The GPU code is proprietary Broadcom code and so can’t be changed. First of all the ROM runs bootcode.bin on the GPU, then loader.bin, then start.elf, then that runs kernel.img on the CPU, which is where the tutorial starts. On the Pi there isn’t a ‘boot sector’ like on x86, and kernel.img is the first thing we can change.
Like in olden ZX-Spectrum`s days…
Very well done with this. It is amazing.
You mention that the usb C code is on the downloads page. I can’t find it.
Could you provide a link?
Hi, Alex Chadwick here.
Just want to say thanks for all the positive feedback, it’s really good to hear people enjoying my work. If people have any comments or feedback, please don’t hesitate to contact me by email at email@example.com, here or in the forums.
Alex, thank you so much for this awesome resource! I’ve done a good amount of ‘low level’ C (i.e. bit twiddling and 2d graphics routines on ARM devices) and was hoping the RaspberryPi would finally give me a way into learning more about assembly and the ARM chips. This tutorial is exactly what I’ve been after and pitched perfectly IMO, keep it up!
What a truely brilliant site, thanks for the post.
The link http://www.ee.surrey.ac.uk/Teaching/Unix/ also was a great find for me, as I am a complete novice to Linux and its file system.
Keep up the good work.
Finaly, i was looking for a OS that has only the things i wanna use. first i wanna give LFS (Linux From Scratch) a try, but now i’m know for sure this is what i need.
Thanks, i will start right a way.
This is perfect!
It’s exactly what I’ve been wanting to see, but perhaps a bit scared to asked without being point to some textbooks or being told it’s already been done somewhere.
Please don’t ever feel awkward about asking for anything like this around these parts – the forums here are particularly newbie friendly, and we really do welcome people wanting to find out where they can find learning materials; it helps us all out.
Not sure if being trolled or I’m just stupid, but on Lesson 5 OK05, even if I just download the solution, compile it and run it, the LED does not blink out Morse code but stays solidly lit. I’ve checked the code many times over, and I’m new to assembly, but it looks like the code is fine… help?
Ah, I think I know what the problem is here.
On the SD card there should be a file called config.txt, if not just create it.
At the end, put the line kernel_old=1
Then test it on the Raspberry Pi again. The problem is that newer version of the boot code are slightly different, and it loads the kernel.img to a different location, so the OS can’t find the Morse Code pattern.
Onto the next lesson!
May be it would be better to teach Position-independent code and add the offset to R15 ?
I got stuck at the first hurdle, in the download section it says “download and install YAGARTO Tools and YAGARTO GNU ARM toolchain for Windows. You may need to restart your computer for this to work (honestly).” I tried this and the programs do not seem to have loaded so I’m a bit stuck…….
Program to “be loaded” is Eclipse CDT Integrated Development Environment. You should install it from YAGARTO site. Otherwise you can use notepad (or any plain text editor) to edit .s files (in Save As dialogue, enter file name with .s extension in double quotes like “kernel.s” ) and native shell (such as cmd.exe) to run ‘make’. I personally prefer some Norton Commander clone for all such tasks. You also may like to setup environment variables for your shell.
I was able to write the file using notepad, but wen I ran make in cmd.exe it told me that
‘make ‘is not recognised as an internal or external command, operable program or batch file.
Does anyone know what I should do?
Just read through the first series of lessons – I’ve been writing assembly language on small microprocessors and microcontrollers for most of my life and this is the kind of thing I was really hoping to be able to get up to on the Pi, but had no idea how to start without Linux getting in the way – this really begs to be made into a proper, published book – “Machine Code on your Raspberry Pi”… Excellent stuff!
Can u help me programming in ASM or HEX a Raspberry Pi , model B ?
This is great. Really really great. Thanks!
65 years old and I’m not a programmer. However, I have been interested in computers for a number of years. My last experience of Assembly Language was on a ZX Spectum in the 1980’s. One can only ask why has it taken so long for a relatively ‘straight forward’ computer as the Raspberry Pi to surface.
Timex Sinclair user here also, Robert. I have not been so excited about assembly in 30 years!
This is going to be a lot of fun this time around. Many thanks to Alex and RaspberryPi.org.
There is life in many of us old-timers who lost our user-groups when the DOS world arrived. Life just hasn’t been the same… until Raspberry Pi :)
I’ve just received a Raspberry Pi and am now about to embark on seeing what I can with it. A new challenge for a 74 year old!! Just had a thought that the programs I may write for it I may call ‘recipes’ !!!
Looking forward to being able to say ‘Rob’s Recipes Rock!’
You go, Rob :)
Hi, these lessons are great. I have a question with lesson 2. Alex says “we can’t precisely predict the speed this runs at” refering to the delay, can’t it be really predicted by no means?. I am interested on running real time applications with the Raspi and thought it could be done by creating a custom kernel, but does that mean that it can’t be done? thanks.
Great! Just what I need! Thank you so so so much Alex!!!
I want to create the best OS in the world, but I don’t find a easy and good tutorial to program my Raspberry Pi in HEX (in Code Machine Language). Everybody knows to programm my RPi in Assembler, Python and C, but nobody in HEX. There is somebody in the world who knows how to programm RaspPi in HEX, or there is a link with a good tutorial, or I will sell my Rpi and I will make the best os on a x86 platform? Please, let me know.