PowerPoint

Lab12 - Porting
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
1 / 16
 Understand the basic process of porting.
 Port FreeRTOS to RPi 2.
 Understand some FreeRTOS implementations.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
2 / 16
 Host Machine
 OS: Windows
 Target Machine
 Raspberry Pi 2
 Build Machine
 A computer with a SD card slot
 OS: Ubuntu 15.10 (or above) 64-bit
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
3 / 16
 Host Machine
 PL2303 Driver
 PuTTY
 Target Machine
 Raspberry Pi Firmware
 Raspberry Pi Older Firmware
 Build Machine
 GCC Cross-Compiler Targeting arm-none-eabi
 FreeRTOS port for Raspberry Pi
 You may find all software on the CSL Course Software.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
4 / 16
 Raspberry Pi 2
 Power supply
 Micro SD card and card reader
 USB-TTL cable
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
5 / 16
 In software engineering, porting is the process of adapting software so
that an executable program can be created for a computing environment
that is different from the one for which it was originally designed (e.g.
different CPU, operating system, or third party library).
 Software is portable when the cost of porting it to a new platform is less
than the cost of writing it from scratch.
 The lower the cost of porting software, relative to its implementation cost,
the more portable it is said to be.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
6 / 16
 OS porting only needs to modify OS Port
layer for the target platform.
 Modify the hardware dependent codes, such as
GPIO, memory mapping, or interrupt control.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
7 / 16
 Yet another real-time operating system
 Why choose FreeRTOS?
 Official introduction
 Unlike uCOSII which requires royalty payments for commercial use, FreeRTOS is
distributed under a modified GPL.
 Source code is available here.
 Source code structure
 Official introduction
 FreeRTOS suggests that the two directories
FreeRTOS/Source/portable/your_compiler/your_architecture/ and
FreeRTOS/Demo/your_platform/ form the port layer.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
8 / 16
 FreeRTOS has been officially ported to many platforms. Raspberry Pi
series is not included, however.
 Lucky, there is a contributed port from third party. This port runs on
Raspberry Pi 1 (BCM2835). We are going to modify it and make it run on
Raspberry Pi 2 (BCM2836).
 Download and extract the source code of this port. Compare the code
structure of this port and the official FreeRTOS ports.
 FreeRTOS/Source/portable/GCC/RaspberryPi/ and Demo/ form the port layer.
 Build script Makefile and linker script raspberrypi.ld are at the root of the
archive.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
9 / 16
 According to the linker script, the program entry point is _start in
Demo/startup.s.
 After doing some processor specific initializations, the control flow jumps
to main() in Demo/main.c.
 In main(), a FreeRTOS kernel API xTaskCreate() is called twice to
register two user-defined tasks task1() and task2(). Another FreeRTOS
kernel API vTaskStartScheduler() is then called to start the two tasks.
 task1() and task2() perform their works periodically. Their periods are
specified by a FreeRTOS kernel API vTaskDelay().
 FreeRTOS kernel API reference can be found here. Their implementations
can be found in the source code.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
10 / 16
 Fix compiler version issue.
 The linker needs libgcc.a and libc.a to generate the final executable. Find
their path and replace “/usr/lib/gcc/arm-none-eabi/4.7.4” and “/usr/armnone-eabi/lib” in Makefile with their path.
 Run % make directly.
 kernel.img is the FreeRTOS image bootable by RPi firmware. Currently,
this image is not able to run on RPi 2, since we have not modified the
code.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
11 / 16
 Modify the source code.
 Reference this article.
 You may also want to add UART support for debugging purpose.
 Modify the build script.
 Specify target CPU for compiler and assembler. In dbuild.config.mk, replace
“-march=armv6z” with “-mcpu=cortex-a7”, and add a line “ASFLAGS += mcpu=cortex-a7”.
 If you add additional .c or .s files, specify corresponding .o files in objects.mk.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
12 / 16
 Raspberry Pi Foundation only provides pre-compiled RPi firmware. In
other words, RPi firmware is not open-source, and what its code does is
actually not standardize.
 So, RPi firmware may not be compatible among all versions. If an OS is
able to run with RPi firmware of a certain version, it is not guaranteed to
be able to run with RPi firmware of another version.
 This FreeRTOS Raspberry Pi port only runs with RPi firmware of some
older versions. It can not run with firmware-1.20160315, the firmware
we have used so far. So, let’s use firmware-1.20150820 instead.
 Backup your config.txt and FreeRTOS image.
 Format the boot partition.
 Put firmware-1.20150820/boot/* into boot partition.
 Restore your config.txt and FreeRTOS image.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
13 / 16
 Note: In my task1() and task2(), I replace “SetGpio(16, 1)” and
“SetGpio(16, 0)” with printing “task 1” and “task 2” respectively.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
14 / 16
 Show that your FreeRTOS is able to run on RPi 2.
 E.g. Let the two tasks print something.
 Explain how task1() and task2() are called.
 Hint: Look into vTaskStartScheduler() to see how it starts all tasks.
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
15 / 16
 FreeRTOS
 GitHub - jameswalmsley/RaspberryPi-FreeRTOS
 GitHub - mopplayer/uCOSII_RPi
 BCM2835 - Raspberry Pi Documentation
 BCM2836 - Raspberry Pi Documentation
 uCOSII porting on RPi A+/B+/2B
Conventions
Department of Computer Science and Information Engineering
National Taiwan University
16 / 16