Skip to content

Commit

Permalink
lesson1 draft addded
Browse files Browse the repository at this point in the history
  • Loading branch information
s-matyukevich committed Nov 29, 2017
1 parent 6ad2431 commit 50ca3cd
Show file tree
Hide file tree
Showing 18 changed files with 494 additions and 52 deletions.
9 changes: 0 additions & 9 deletions build.sh

This file was deleted.

17 changes: 17 additions & 0 deletions docs/Contributions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Contributing to Raspberry Pi OS

The general workflow is the following:

1. Find an [issue](https://github.com/s-matyukevich/raspberry-pi-os/issues) that you want to start working on or create a new one.
1. In the comments claim that you want to start working on the issue. The first person who did this will be assigned to the issue. In some circumstancies I may reasing the issue to somebody elase after contacting the original person.
1. [Fork the repository](https://help.github.com/articles/fork-a-repo/).
1. Make all necesary changes.
1. [Send pull request](https://help.github.com/articles/about-pull-requests/).
1. After a review your changes will be merged.

The following types of contributions are particulary helpfull for the project.

1. Validating source code and text of the lessons for errors.
1. Helping to make lessons content more accurate and easier to understand.
1. Working on sorce code and description for new lessons.
1. Anything else that can help the project to become a perfect starting point for OS developers.
8 changes: 6 additions & 2 deletions docs/Prerequisites.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
## Prerequisites


### 1. [Raspberry Pi 3 model b](https://www.raspberrypi.org/products/raspberry-pi-3-model-b/)

Older versions of Raspberry Pi are not going to work with this tutorial, because all lessons are designed to use 64 bit processor that supports ARM.v8 architecture and such processor is only available in Raspberry Pi 3 model.
Older versions of Raspberry Pi are not going to work with this tutorial, because all lessons are designed to use 64 bit processor that supports ARMv8 architecture and such processor is only available in Raspberry Pi 3 model.

### 2. [USB to TTL serial cable](https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=usb+to+ttl+serial+cable&rh=i%3Aaps%2Ck%3Ausb+to+ttl+serial+cable)

After you get serial cable you need to test you connection. If you never done this before I recommend you to follow [this guide](https://cdn-learn.adafruit.com/downloads/pdf/adafruits-raspberry-pi-lesson-5-using-a-console-cable.pdf) It describes the process of connecting your raspberry Pi via serial cabel in great details. One thin that I can recomment you to do is to use your serial cable to power your Raspberry Pi. How to do this is described in the previous link.

### 3. Docker

Strictly speaking Docker is not a required dependency. It is just convinient to use docker to build source code of the lessons, especially for Mac and Windows users. Each lesson has `build.sh` script (or `build.bat` for windows users) This script uses docker to build source code of the lesson. Instructions how to install docker for you platform can be found on the [official docker website](https://docs.docker.com/engine/installation/)

If for some reasons you want to avoid using Docker, you can install [make utility](http://www.math.tau.ac.il/~danha/courses/software1/make-intro.html) as well as `aarch64-linux-gnu` toolchain. If you are using ubuntu you just need to install `gcc-aarch64-linux-gnu` and `build-essential` packages.
401 changes: 401 additions & 0 deletions docs/lesson01/rpi-os.md

Large diffs are not rendered by default.

Binary file added images/alt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gpfsel1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/lesson01/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARMGNU ?= gcc-aarch64-linux-gnu
ARMGNU ?= aarch64-linux-gnu

COPS = -Wall -nostdlib -nostartfiles -ffreestanding -Iinclude -mgeneral-regs-only
ASMOPS = -Iinclude

all : kernel7.img

Expand All @@ -11,7 +12,7 @@ src/%_c.o: src/%.c
$(ARMGNU)-gcc $(COPS) -c $< -o $@

src/%_s.o: src/%.S
$(ARMGNU)-as $< -o $@
$(ARMGNU)-gcc $(ASMOPS) -c $< -o $@

C_FILES = $(wildcard src/*.c)
ASM_FILES = $(wildcard src/*.S)
Expand Down
3 changes: 3 additions & 0 deletions src/lesson01/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

docker run -v $(pwd):/app -w /app smatyukevich/raspberry-pi-os-builder make $1
17 changes: 17 additions & 0 deletions src/lesson01/include/mm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef _MM_H
#define _MM_H

#define PAGE_SHIFT 12
#define TABLE_SHIFT 9
#define SECTION_SHIFT (PAGE_SHIFT + TABLE_SHIFT)

#define PAGE_SIZE (1 << PAGE_SHIFT)
#define SECTION_SIZE (1 << SECTION_SHIFT)

#ifndef __ASSEMBLER__

void memzero(unsigned long src, unsigned long n);

#endif

#endif /*_MM_H */
6 changes: 3 additions & 3 deletions src/lesson01/include/utils.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _BOOT_H
#define _BOOT_H

extern void DELAY ( unsigned int);
extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern void delay ( unsigned long);
extern void put32 ( unsigned long, unsigned int );
extern unsigned int get32 ( unsigned long );

#endif /*_BOOT_H */
15 changes: 12 additions & 3 deletions src/lesson01/src/boot.S
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#include "mm.h"

.section ".text.boot"

.globl _start
_start:
mrs x0, mpidr_el1
and x0, x0,#0xFF // Check processor id
cbz x0, master // Hang for all non-primary CPU
b hang
b proc_hang

proc_hang:
b proc_hang

master:
mov sp,#0x00400000
adr x0, bss_begin
adr x1, bss_end
sub x1, x1, x0
bl memzero

mov sp, #(2 * SECTION_SIZE)
bl kernel_main

hang: b hang

4 changes: 0 additions & 4 deletions src/lesson01/src/kernel.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#include <stddef.h>
#include <stdint.h>

#include "utils.h"
#include "mini_uart.h"

void kernel_main(void)
Expand Down
15 changes: 7 additions & 8 deletions src/lesson01/src/linker.ld
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
SECTIONS
{
.text :
{
KEEP(*(.text.boot))
*(.text)
}
.rodata :{ *(.rodata) }
.data :{ *(.data) }
.text.boot : { *(.text.boot) }
.text : { *(.text) }
.rodata : { *(.rodata) }
.data : { *(.data) }
. = ALIGN(0x8);
bss_begin = .;
.bss : { *(.bss*) }
bss_end = .;
}

24 changes: 11 additions & 13 deletions src/lesson01/src/mini_uart.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#include <stddef.h>
#include <stdint.h>

#include "utils.h"
#include "peripherals/mini_uart.h"
#include "peripherals/gpio.h"
Expand All @@ -9,18 +6,18 @@ void uart_send ( char c )
{
while(1)
{
if(GET32(AUX_MU_LSR_REG)&0x20) break;
if(get32(AUX_MU_LSR_REG)&0x20) break;
}
PUT32(AUX_MU_IO_REG,c);
put32(AUX_MU_IO_REG,c);
}

char uart_recv ( void )
{
while(1)
{
if(GET32(AUX_MU_LSR_REG)&0x01) break;
if(get32(AUX_MU_LSR_REG)&0x01) break;
}
return(GET32(AUX_MU_IO_REG)&0xFF);
return(get32(AUX_MU_IO_REG)&0xFF);
}

void uart_send_string(char* str)
Expand All @@ -33,14 +30,15 @@ void uart_send_string(char* str)

void uart_init ( void )
{
uint32_t ra;
unsigned int selector;

ra=GET32(GPFSEL1);
ra&=~(7<<12); //gpio14
ra|=2<<12; //alt5
ra&=~(7<<15); //gpio15
ra|=2<<15; //alt5
selector = GET32(GPFSEL1);
selector &= ~(7<<12); // clean gpio14
selector |= 2<<12; // set alt5 for gpio14
selector &= ~(7<<15); // clean gpio15
selector |= 2<<15; // set alt5 for gpio 15
PUT32(GPFSEL1,ra);

PUT32(GPPUD,0);
DELAY(150);
PUT32(GPPUDCLK0,(1<<14)|(1<<15));
Expand Down
6 changes: 6 additions & 0 deletions src/lesson01/src/mm.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.globl memzero
memzero:
str xzr, [x0], #8
subs x1, x1, #8
b.gt memzero
ret
14 changes: 7 additions & 7 deletions src/lesson01/src/utils.S
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.globl PUT32
PUT32:
.globl put32
put32:
str w1,[x0]
ret

.globl GET32
GET32:
.globl get32
get32:
ldr w0,[x0]
ret

.globl DELAY
DELAY:
.globl delay
delay:
subs x0, x0, #1
bne DELAY
bne delay
ret
Binary file modified src/lesson02/kernel7.img
Binary file not shown.
2 changes: 1 addition & 1 deletion src/lesson06/src/boot.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _start:
mrs x0, mpidr_el1
and x0, x0,#0xFF // Check processor id
cbz x0, master // Hang for all non-primary CPU
b hang
b proc_hang

proc_hang:
b proc_hang
Expand Down

0 comments on commit 50ca3cd

Please sign in to comment.