ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
11:40?12:00, October 24, 2014 
ESS2014@NYC Tokyo 
3bOS: A flexible and lightweight 
embedded OS operated using only 
3 buttons 
Encarnacion, Immanuel V? 
Ryohei Kobayashi? 
Kenji Kise? 
?University of the Philippines, Philippines 
?Tokyo Institute of Technology, Japan
This Presentation is about... 
! 3bOS 
" a simple and easily customizable embedded OS 
" running on the MieruEMB system 
" using only three push buttons 
Three push buttons 
3bOS running on the MieruEMB system 1
Outline 
! Introduction 
! Design 
! Implementation 
! Discussion and Conclusion 
2
Outline 
! Introduction 
! Design 
! Implementation 
! Discussion and Conclusion 
3
The Growth in Popularity of 
Embedded Systems 
! Being used in a lot of fields 
! Having skills and knowledge about 
embedded systems is required 
4 
Car electronics Medical products 
Communication devices
The MieruEMB system 
! An educational kit 
" for learning implementation skills and knowledge 
regarding embedded systems 
The MieruEMB system 5
The MieruEMB system 
! An educational kit 
" for learning implementation skills and knowledge 
regarding embedded systems 
Spartan XC3S500E 
512KB SRAM 
(128 x 128 pixel16-bit color) 
The MieruEMB system 6 
LCD screen 
SD card slot 
Three push buttons
Experiments on Computer Science 
! view 
7
3bOS 
! Characteristics 
" Running on the MieruEMB system 
" Only three push buttons interface 
" Simplicity 
 A few # lines of code 
 Flexibility 
 Users can easily implement their desired features 
! Features 
 The OS itself is loaded from the SD card 
 Reading FAT-formatted SD card 
 Reading contents in SD card 
 Running ELF files in SD card 
8
Outline 
! Introduction 
! Design 
! Implementation 
! Discussion and Conclusion 
9
ISA 
! 32-bit MIPS 
! Why MIPS? 
 simplicity and widespread use 
 Lots of information 
10
Storage 
! The contents of the 3bOS binary file are 
copied to memory when turned on 
11
I/O 
! Memory-mapped I/O 
! 32-bit address space 
12 
512KB 
1KB 
16KB 
SRAM 
0x000000 
19-bit Physical 
Address Space 
0x07FFFF 
General 
MMIO 
MMC 
MMIO 
0x800000 
0x8003FF 
MMIO: Memory Mapped I/O 
MMC : Multi Media Card 
Video 
Memory 
0x900000 
0x903FFF 
4GB
File System 
! FAT file system (FAT12) 
! Why FAT? 
 Simplicity and popularity on many platforms 
13
File Explorer 
! Features 
 Opening a sub/parent directory 
 Reading contents 
 Running ELF files 
14
Outline 
! Introduction 
! Design 
! Implementation 
! Discussion and Conclusion 
15
Implementation of 3bOS 
! The OS is mostly coded in C 
 Containing some assembly code 
! Compiled with gcc for MIPS* 
*Buildroot: http://buildroot.uclibc.org/ 16
Implementation of 3bOS 
! Important functions 
 Text and Display drivers 
 SD card driver 
 Execution and Exiting of the ELF files 
17
Text and Display Drivers 
! Display text (and/or) graphics 
! Problems 
 It is hard to use basic libraries(stdio.h, stdlib.h) 
in MIPS GCC (ver 4.3) 
 printf, malloc, free, memcpy, etc... 
 very limited sprintf 
18
Solution: gprintf 
! We made own printf 
! accepts patterns such as: 
 %d 
 %s 
 %x 
 %b 
 %% 
 etc... 
! No compile-time type 
checking 
19
SD Card Driver 
! Reads raw data from the SD card 
! Sends control signals to read/write from 
the SD card 
! Only a 512-byte sector can be read at a 
time 
! A Minor Problem: Physical and Logical 
sectors 
 Hardware reads physical sector addresses 
 Windows can only read logical sector addresses 
 Logical Sector #0 = Physical Sector #25 
20
Debugging by a hex editor 
21
Execution and Exiting of the ELF Files 
! A pre-execution menu is first displayed 
 Whenever the user wants to execute an ELF file 
in the 3bOS 
! After the executable exits, 3bOS returns to 
the pre-execution menu 
22
Execution and Exiting of the ELF Files 
! The Loading Process of an ELF file and 
Physical Memory Layout 
23
Main Problem 
! State is restored imperfectly 
 Processor state 
 Program counter 
 Registers($sp, $gp, $ra, etc...) 
 Video memory 
 Video memory would be overwritten when the new 
executable runs 
 But, the pre-execution menu should be restored after 
the executable exits 
24
The Wrong Solution 
! To save state before 
the pre-execution menu 
UI is drawn 
! But, the stack in the 
restored state is 
different... 
Pre-execution Menu 
Please choose 
how to open 
the ELF file. 
^% *^() )*# 
An app 
runs  exits 
25
The Correct Solution 
! No need to save stack or 
video memory! 
! ¡°done¡± is global variable 
 not in the stack 
26
Debugging with the IDA Debugger 
27
Outline 
! Introduction 
! Design 
! Implementation 
! Discussion and Conclusion 
28
Discussion 
! 3bOS¡¯s Important points 
 Simplicity and Flexibility 
 Just around 800 lines total 
(about one-eighth the size of FreeRTOS*) 
 Users can easily understand how 3bOS runs on the 
MieruEMB system 
 Users can easily implement their desired features 
 Low Memory Usage 
 3bOS leaves around 400KB of usable space for 
running programs (80% of the total size of the main 
memory) 
! It is suitable to use 3bOS as an educational 
material 
*FreeRTOS: http://www.freertos.org/ 29
Conclusion 
! 3bOS 
 A simple and customizable embedded OS 
operated using only 3 buttons 
 Running on the MieruEMB system 
! 3bOS is suitable for educational purposes 
 A Few # lines of code 
 Users who want to learn OS programming can 
easily understand it 
 Its flexibility makes it simple for users to modify, 
add, or remove features 
30

More Related Content

3bOS: A flexible and lightweight embedded OS operated using only 3 buttons

  • 1. 11:40?12:00, October 24, 2014 ESS2014@NYC Tokyo 3bOS: A flexible and lightweight embedded OS operated using only 3 buttons Encarnacion, Immanuel V? Ryohei Kobayashi? Kenji Kise? ?University of the Philippines, Philippines ?Tokyo Institute of Technology, Japan
  • 2. This Presentation is about... ! 3bOS " a simple and easily customizable embedded OS " running on the MieruEMB system " using only three push buttons Three push buttons 3bOS running on the MieruEMB system 1
  • 3. Outline ! Introduction ! Design ! Implementation ! Discussion and Conclusion 2
  • 4. Outline ! Introduction ! Design ! Implementation ! Discussion and Conclusion 3
  • 5. The Growth in Popularity of Embedded Systems ! Being used in a lot of fields ! Having skills and knowledge about embedded systems is required 4 Car electronics Medical products Communication devices
  • 6. The MieruEMB system ! An educational kit " for learning implementation skills and knowledge regarding embedded systems The MieruEMB system 5
  • 7. The MieruEMB system ! An educational kit " for learning implementation skills and knowledge regarding embedded systems Spartan XC3S500E 512KB SRAM (128 x 128 pixel16-bit color) The MieruEMB system 6 LCD screen SD card slot Three push buttons
  • 8. Experiments on Computer Science ! view 7
  • 9. 3bOS ! Characteristics " Running on the MieruEMB system " Only three push buttons interface " Simplicity A few # lines of code Flexibility Users can easily implement their desired features ! Features The OS itself is loaded from the SD card Reading FAT-formatted SD card Reading contents in SD card Running ELF files in SD card 8
  • 10. Outline ! Introduction ! Design ! Implementation ! Discussion and Conclusion 9
  • 11. ISA ! 32-bit MIPS ! Why MIPS? simplicity and widespread use Lots of information 10
  • 12. Storage ! The contents of the 3bOS binary file are copied to memory when turned on 11
  • 13. I/O ! Memory-mapped I/O ! 32-bit address space 12 512KB 1KB 16KB SRAM 0x000000 19-bit Physical Address Space 0x07FFFF General MMIO MMC MMIO 0x800000 0x8003FF MMIO: Memory Mapped I/O MMC : Multi Media Card Video Memory 0x900000 0x903FFF 4GB
  • 14. File System ! FAT file system (FAT12) ! Why FAT? Simplicity and popularity on many platforms 13
  • 15. File Explorer ! Features Opening a sub/parent directory Reading contents Running ELF files 14
  • 16. Outline ! Introduction ! Design ! Implementation ! Discussion and Conclusion 15
  • 17. Implementation of 3bOS ! The OS is mostly coded in C Containing some assembly code ! Compiled with gcc for MIPS* *Buildroot: http://buildroot.uclibc.org/ 16
  • 18. Implementation of 3bOS ! Important functions Text and Display drivers SD card driver Execution and Exiting of the ELF files 17
  • 19. Text and Display Drivers ! Display text (and/or) graphics ! Problems It is hard to use basic libraries(stdio.h, stdlib.h) in MIPS GCC (ver 4.3) printf, malloc, free, memcpy, etc... very limited sprintf 18
  • 20. Solution: gprintf ! We made own printf ! accepts patterns such as: %d %s %x %b %% etc... ! No compile-time type checking 19
  • 21. SD Card Driver ! Reads raw data from the SD card ! Sends control signals to read/write from the SD card ! Only a 512-byte sector can be read at a time ! A Minor Problem: Physical and Logical sectors Hardware reads physical sector addresses Windows can only read logical sector addresses Logical Sector #0 = Physical Sector #25 20
  • 22. Debugging by a hex editor 21
  • 23. Execution and Exiting of the ELF Files ! A pre-execution menu is first displayed Whenever the user wants to execute an ELF file in the 3bOS ! After the executable exits, 3bOS returns to the pre-execution menu 22
  • 24. Execution and Exiting of the ELF Files ! The Loading Process of an ELF file and Physical Memory Layout 23
  • 25. Main Problem ! State is restored imperfectly Processor state Program counter Registers($sp, $gp, $ra, etc...) Video memory Video memory would be overwritten when the new executable runs But, the pre-execution menu should be restored after the executable exits 24
  • 26. The Wrong Solution ! To save state before the pre-execution menu UI is drawn ! But, the stack in the restored state is different... Pre-execution Menu Please choose how to open the ELF file. ^% *^() )*# An app runs exits 25
  • 27. The Correct Solution ! No need to save stack or video memory! ! ¡°done¡± is global variable not in the stack 26
  • 28. Debugging with the IDA Debugger 27
  • 29. Outline ! Introduction ! Design ! Implementation ! Discussion and Conclusion 28
  • 30. Discussion ! 3bOS¡¯s Important points Simplicity and Flexibility Just around 800 lines total (about one-eighth the size of FreeRTOS*) Users can easily understand how 3bOS runs on the MieruEMB system Users can easily implement their desired features Low Memory Usage 3bOS leaves around 400KB of usable space for running programs (80% of the total size of the main memory) ! It is suitable to use 3bOS as an educational material *FreeRTOS: http://www.freertos.org/ 29
  • 31. Conclusion ! 3bOS A simple and customizable embedded OS operated using only 3 buttons Running on the MieruEMB system ! 3bOS is suitable for educational purposes A Few # lines of code Users who want to learn OS programming can easily understand it Its flexibility makes it simple for users to modify, add, or remove features 30