Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer System Laboratory

Similar presentations


Presentation on theme: "Computer System Laboratory"— Presentation transcript:

1 Computer System Laboratory
Lab12 - Porting / 16

2 Experimental Goal Understand the basic process of porting.
Port FreeRTOS to RPi 2. Understand some FreeRTOS implementations. / 16

3 Environment Host Machine Target Machine Build Machine OS: Windows
Raspberry Pi 2 Build Machine A computer with a SD card slot OS: Ubuntu (or above) 64-bit / 16

4 Software Required Host Machine Target Machine Build 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. / 16

5 Hardware Checklist Raspberry Pi 2 Power supply
Micro SD card and card reader USB-TTL cable / 16

6 Introduction to Porting
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. / 16

7 Popular Embedded OS Architecture
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. / 16

8 Introduction to FreeRTOS
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 FreeRTOS suggests that the two directories FreeRTOS/Source/portable/your_compiler/your_architecture/ and FreeRTOS/Demo/your_platform/ form the port layer. / 16

9 FreeRTOS Port for Raspberry Pi
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. / 16

10 Control Flow 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. / 16

11 Build Instructions Fix compiler version issue. Run % make directly.
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/arm- none-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. / 16

12 Porting to Raspberry Pi 2
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. / 16

13 Firmware Issue 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 , the firmware we have used so far. So, let’s use firmware instead. Backup your config.txt and FreeRTOS image. Format the boot partition. Put firmware /boot/* into boot partition. Restore your config.txt and FreeRTOS image. / 16

14 Boot Successfully Note: In my task1() and task2(), I replace “SetGpio(16, 1)” and “SetGpio(16, 0)” with printing “task 1” and “task 2” respectively. / 16

15 Lab Requirement 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. / 16

16 Reference FreeRTOS GitHub - jameswalmsley/RaspberryPi-FreeRTOS
GitHub - mopplayer/uCOSII_RPi BCM Raspberry Pi Documentation BCM Raspberry Pi Documentation uCOSII porting on RPi A+/B+/2B / 16


Download ppt "Computer System Laboratory"

Similar presentations


Ads by Google