SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
Note: The Copyrights of the referenced materials and photos go to its original authors. As a result, this slide is for internal reference only.
For the contents created in this document, the Copyright belongs to William W.-Y. Liang. © 2005-2015 All Rights Reserved.
Note: The Copyrights of the referenced materials and photos go to their original authors. As a result, this slide is for non-commercial reference only.
For the contents created in this document, the Copyright belongs to William W.-Y. Liang. © 2005-2015 All Rights Reserved.
作業系統與硬體元件的驅動軟體開發法則
Operating Systems and Software Design Principles for Hardware Components
William W.-Y. Liang (梁文耀), Ph.D.
http: //www.ntut.edu.tw/~wyliang
© 2015 William W.-Y. Liang, All Rights Reserved.
大綱
作業系統與驅動軟體架構
即時作業系統 (RTOS) 與一般用途作業系統
驅動程式與 RTOS, Linux, 及 Android
硬體元件的驅動軟體開發
硬體元件與系統軟體銜接的準備工作
驅動程式於作業系統中所扮演的角色
驅動程式介面定義與實現方法
驅動程式的開源與閉源考量
開放與貢獻源碼 的優點
如何兼顧開源標準與閉源優化
開源與閉源分界的設計原則
授權議題的處理原則與開源釋出準則
2 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
嵌入式系統組成
Hardware
Software development environment
Tool chain and Library
Boot loader
OS Kernel / RTOS
Middleware*
Applications
3 OS vs. Hardware Components
*Example: In Android,
the middleware is called
the Application
Framework.
Source: Qing Li and Caroline Yao, “real-time concepts for embedded systems”
© 2015 William W.-Y. Liang, All Rights Reserved.
週邊裝置控制
Most of the I/O today is achieved by
Memory-mapped I/O
I/O devices communicate with the processor
through a set of registers in the I/O controller.
Control register
Status register
Data register
4 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
即時作業系統
特性:
具備基本多工能力, 較容易滿足即時系統需求; 硬體須自行控制
Examples:
VxWorks, Nucleus, ThreadX, QNX, RTEMS, Symbian, WinCE,
TRON, uC/OS II, eCOS, FreeRTOS, mbed RTOS
Application Development:
Usually implemented as threads which share the same space with the
kernel; MMU is usually not used; Real-time considerations
(priority, timing constrains)
5 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
一般用途作業系統
特性:
提供完整軟硬體資源管理機制; 應用程式不須顧慮底層硬體運作方
式; 可專注軟體系統設計, 發展具備完整架構之軟體堆疊; 較易發展
出功能複雜多樣化的軟體與應用產品
Example:
Linux (with many Distributions), Android,
Chrome OS, Firefox OS, Brillo, uClinux, MacOS, iOS, Windows
Application development
System independent application development: General applications,
GUI/Window programming, Web programming
System dependent software development: System programming, Device
drivers, Protocol software
6 OS vs. Hardware Components & Brillo
© 2015 William W.-Y. Liang, All Rights Reserved.
微控制器作業系統範例: mbed OS
7 OS vs. Hardware Components
Supports a wide range of ARM Cortex-M based hardware platforms from major MCU vendors
Provide a C++ Application Framework and component architecture
Automation of power management
Connectivity protocol stack support for BLE®, Cellular, Ethernet, Thread, Wi-fi®, Zigbee IP,
Zigbee NAN, 6LoWPAN, TLS & DTLS end-to-end IP secure communication channels, OMA
LWM2M protocol for device management
Software asset protection and secure firmware updates for device security & management
https:
//developer.mbed.org/blog/entry/Anno
uncing-our-plans-for-mbed-v30/
© 2015 William W.-Y. Liang, All Rights Reserved.
mbed RTOS 範例: Thread & ISR & I/O Control
8 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
驅動程式在一般用途作業系統的定位
Device drivers are usually treated as black boxes for
the application developers.
They resemble as a software layer
lying between the applications and
the actual devices.
9 OS vs. Hardware Components
http: //www.ni.com/tutorial/3789/en/
© 2015 William W.-Y. Liang, All Rights Reserved.
Linux 作業系統
Open source and free
Maintained by numerous volunteer experts and hackers
Robust, efficient, and reliable
Modular, configurable, and scalable
Tons of applications available
Lower hardware requirement and BOM cost for mid-range to low-end products.
Also suitable for general purpose computers, especially for high performance servers
10 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
Linux 驅動程式架構
UNIX/Linux systems implement device files to enable users to
employ familiar commands and functions such as open, read,
write, and close when working with some peripherals.
11 OS vs. Hardware Components
Example file operations
 int open( char *pathname, int flags, … );
 int read( int fd, void *buf, size_t count );
 int write( int fd, void *buf, size_t count );
 int close( int fd );
© 2015 William W.-Y. Liang, All Rights Reserved.
Android作業系統
Consistent user experience and good UI design
Easy to be commercialized
Complete software framework
Lower App development cost
Already supported by millions Apps
Applicable for m high-end to mid-range devices
High portability for Apps and the OS itself
Suitable for resource-limited handheld devices
12 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
Android 硬體抽象層 (HAL)
A hardware abstraction layer (HAL) is an
abstraction layer, implemented in software,
between the physical hardware of a computer
and the software that runs on that computer.
Typically seen in portable operating system
design, such as Linux.
Realized in user-space of the Android operating
system, with the concept of user-space device
driver.
13 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
大綱
作業系統與驅動軟體架構
即時作業系統 (RTOS) 與一般用途作業系統
驅動程式與 RTOS, Linux, 及 Android
硬體元件的驅動軟體開發
硬體元件與系統軟體銜接的準備工作
驅動程式於作業系統中所扮演的角色
驅動程式介面定義與實現方法
驅動程式的開源與閉源考量
開放與貢獻源碼 的優點
如何兼顧開源標準與閉源優化
開源與閉源分界的設計原則
授權議題的處理原則與開源釋出準則
14 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
硬體元件與系統軟體銜接的準備工作
選定一個或兩個初步支持之作業系統
如 Linux, Android, Windows, mbed OS, QNX, etc.
Linux 已為應用最廣泛的作業系統核心, 故為必要選項
研究既有作業系統對元件支持的程度與實現方式
由於 Linux 與 Android 為發展程度最高的開源專案, 目前
多數已標準化的軟硬體幾乎皆以 其為首要支持對象
已開源的部分可直接繼承來用: 藉以了解實作方式、避
免重複實作, 同時縮短開發時間.
步驟
根據各作業系統平台決定驅動程式介面
實作驅動程式
15 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
驅動程式於作業系統中所扮演的角色
驅動程式與上下層的關係
對上: 符合作業系統運作流程
複雜度較高
不同作業系統有不同的「遊戲規則」
對下: 操作硬體
配合硬體流程
一般用途作業系統須考慮的問題
正確運作: 複雜的多執行緒運行環境 + 中斷造成複雜的
資源共享與同步問題
運行效能: 為了讓多工環境有效運行, 應謹慎共用資源
耗電考量: 行動裝置與節能議題
16 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
驅動程式介面定義與實現方法
驅動程式即為一種硬體抽象層
Hardware Abstraction Layer (HAL)
介面函數規格定義應包含:
輸入命令與資料
輸出資料與狀態
規範與限制
Device Driver (HAL) API 隨作業系統而異
元件介面 Vendor API 則隨硬體功能由廠商定義
包含基礎操作功能, 通常與特定平台無關、具可移植性
可參考硬體功能與既有系統已定義的共通介面來設計
Glue實作: 基於 Vendor API 以實現對應驅動程式
17 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
驅動程式的開源與閉源考量
開源與閉源的原則
只保護最需要的部分
其他部分可考慮盡量開放
沒有技術含量的部分
技術含量太低的部分
(亦即別人也很容易實現的地方)
開源 vs. 閉源
不開源代表必須自行維護, 包括處理各式各樣客戶的需
求 (會增加維護上的負擔與成本)
開源可借力使力, 可透過客戶或其他開發者協助改善軟
體品質
18 OS vs. Hardware Components
http:
//m.eettaiwan.com/ART_8800697488_676964_NT_57e14b60_2.HTM
© 2015 William W.-Y. Liang, All Rights Reserved.
開放與貢獻源碼的優點
Upstream 源碼
將源碼貢獻回開源源碼庫
一旦開源社群審核並接受 之後, 開發者將持續為該源碼
進行維護
以 Linux Kernel 為例, 其優點包括:
較佳品質: 被維護的驅動程式可能被開發者 (Kernel
Hackers) 改得更好
持續維護: 被接受的驅動程式可以持續被維護及更新 (特
別是對新版本的跟進), 長期來看可降低維護成本, 亦可延
長硬體銷售期.
提升公司能見度與 Credit
19 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
如何兼顧開源標準與閉源優化
設計原則: 盡量採開源以擴大適用場域, 亦可降低長
期維護成本. 僅將最關鍵部分以閉源方式實作.
韌體實現方式
作法: 以韌體運行於元件內建微控制器
優點: 完全隔絕授權議題
缺點: 可使用資源較受限
驅動軟體方式
作法: 以驅動程式實現所有工作
優點: 可運用主系統資源 (CPU & Memory)
缺點: 需謹慎處理如 GPL 等授權問題
20 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
如何兼顧開源標準與閉源優化 (續)
中介服務方式
作法: 透過中介軟體服務元件操作
優點: 可隔絕授權相關問題
缺點: 大量 IPC 影響運行效能
混合實作模式
作法: 將不重要的程式邏輯開源, 關鍵操作保留於韌體於
元件控制器或中介服務方式實現
優點: 可同時兼顧閉源與開源授權議題
缺點: 需良好的設計配套以降低溝通及資料傳輸延遲
21 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
開源與閉源分界的設計原則
如何訂定開源閉源的分界點是一種藝術, 如同手術
一般, 漂亮的一刀是術後讓傷痕最小化的關鍵!
考量重點: 保護的價值 vs. 維護成本 vs. 運行效能
若有 GPL 開源授權考量, 可考慮將閉源部分放在:
軟體服務元件 (如 Android 與其他 OS)
雲端的伺服器軟體 (如雲端應用與 WebApp 做法)
獨立處理器的韌體 (如微控制器韌體)
驅動軟體的設計通常可將閉源程式邏輯實現於微控
制器韌體與上層軟體服務之中 (前述混合實作模式)
22 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
附錄: 授權議題的處理原則
GPL 相關部分必須開放
其他部分能開放盡量開放
閉源而以 binary 呈現的部分,
於不違反 GPL 的前提下, 應具備
合理再散播之授權條款
如 MIT 或 BSD Licenses 或 NDA
23 OS vs. Hardware Components
認識 GPL
 開源 ≠ GPL (General Public License)
 強制開源的時機: GPL 軟體重新散佈(redistribution)時
 GPL 的感染性
 直接修改 GPL 源碼或靜態連結時必然發生
 動態連結 (.so & .ko)則需由衍生作品角度來判定
 正確運用 GPL: 適當拿捏開源與閉源可兼顧開放與保護的目的
 GPL 塑造了開源巨人, 讓我們可站在其肩膀向前大步邁進!
© 2015 William W.-Y. Liang, All Rights Reserved.
附錄: 源碼庫與開源釋出準則
目前採用最多的版本管理系統: git
開源源碼庫: e.g. github, bitbucket
最佳的開源方式: 貢獻至上游源碼庫(up-streaming)
需符合上游源碼架構, 包括Coding style、source tree
structure、data structure、implementation methods
24 OS vs. Hardware Components
© 2015 William W.-Y. Liang, All Rights Reserved.
Q&A
其他分享: http://goo.gl/6qxlSv
Home: http://www.ntut.edu.tw/~wyliang
FB: http://www.facebook.com/william.wyliang
Slideshare: http://www.slideshare.net/williamwyliang/
Email: william.wyliang@gmail.com
關於講者:梁文耀 (William W.-Y. Liang)
• 顧問 / 開源貢獻者 (2014.10~)
• 鴻海科技集團創新數位系統事業群資深處長 (2013.01~2014.09)
• 安佐立科技顧問公司技術總監 (2012.08~2013.07)
• 國立台北科技大學資訊工程系專任助理教授 (2005.02~2012.07)
• 先前經歷: 聚興科技研發處協理、晶慧資訊研發副總經理、
晶慧資訊研發部經理、晶慧資訊資深工程師、美商 Avant! 軟體工程師
• 專長領域:作業系統、嵌入式系統、計算機結構、平行與分散式系統
 Linux 系統軟體 (1993~Now)
 Android 與 Linux 嵌入式系統核心及軟硬整合開發 (2001~Now)
• 國立台灣大學資訊工程博士、國立清華大學資訊科學碩士
OS vs. Hardware Components25

Mais conteúdo relacionado

Mais procurados

0 introduction to computer architecture
0 introduction to computer architecture0 introduction to computer architecture
0 introduction to computer architectureaamc1100
 
Aula sobre Placa-mãe
Aula sobre Placa-mãeAula sobre Placa-mãe
Aula sobre Placa-mãeFilipe Flores
 
Computer Architecture and organization
Computer Architecture and organizationComputer Architecture and organization
Computer Architecture and organizationBadrinath Kadam
 
Unit 1 basic structure of computers
Unit 1   basic structure of computersUnit 1   basic structure of computers
Unit 1 basic structure of computerschidabdu
 
Computer Hardware
Computer HardwareComputer Hardware
Computer Hardwarenitinmote
 
第8回oss運用管理勉強会 Zabbix入門&Zabbix3.0先取り紹介
第8回oss運用管理勉強会 Zabbix入門&Zabbix3.0先取り紹介第8回oss運用管理勉強会 Zabbix入門&Zabbix3.0先取り紹介
第8回oss運用管理勉強会 Zabbix入門&Zabbix3.0先取り紹介Daisuke Ikeda
 
B07_業務の自動化を多角的に実現する Power Automate の世界 [Microsoft Japan Digital Days]
B07_業務の自動化を多角的に実現する Power Automate の世界 [Microsoft Japan Digital Days]B07_業務の自動化を多角的に実現する Power Automate の世界 [Microsoft Japan Digital Days]
B07_業務の自動化を多角的に実現する Power Automate の世界 [Microsoft Japan Digital Days]日本マイクロソフト株式会社
 
Bca 2nd sem-u-1.2 digital logic circuits, digital component
Bca 2nd sem-u-1.2 digital logic circuits, digital componentBca 2nd sem-u-1.2 digital logic circuits, digital component
Bca 2nd sem-u-1.2 digital logic circuits, digital componentRai University
 

Mais procurados (19)

0 introduction to computer architecture
0 introduction to computer architecture0 introduction to computer architecture
0 introduction to computer architecture
 
INSTRUCTION CYCLE
INSTRUCTION CYCLEINSTRUCTION CYCLE
INSTRUCTION CYCLE
 
Aula sobre Placa-mãe
Aula sobre Placa-mãeAula sobre Placa-mãe
Aula sobre Placa-mãe
 
Computer Architecture and organization
Computer Architecture and organizationComputer Architecture and organization
Computer Architecture and organization
 
Microsoft の変革
Microsoft の変革Microsoft の変革
Microsoft の変革
 
COBIT
COBIT COBIT
COBIT
 
Expansion slots
Expansion slotsExpansion slots
Expansion slots
 
3 Pipelining
3 Pipelining3 Pipelining
3 Pipelining
 
Bios
BiosBios
Bios
 
Bios
BiosBios
Bios
 
Unit 1 basic structure of computers
Unit 1   basic structure of computersUnit 1   basic structure of computers
Unit 1 basic structure of computers
 
La carte mère
La carte mèreLa carte mère
La carte mère
 
Processadores RISC
Processadores RISCProcessadores RISC
Processadores RISC
 
Computer Hardware
Computer HardwareComputer Hardware
Computer Hardware
 
Basic computer architecture
Basic computer architectureBasic computer architecture
Basic computer architecture
 
第8回oss運用管理勉強会 Zabbix入門&Zabbix3.0先取り紹介
第8回oss運用管理勉強会 Zabbix入門&Zabbix3.0先取り紹介第8回oss運用管理勉強会 Zabbix入門&Zabbix3.0先取り紹介
第8回oss運用管理勉強会 Zabbix入門&Zabbix3.0先取り紹介
 
Cpu & its execution of instruction
Cpu & its execution of instructionCpu & its execution of instruction
Cpu & its execution of instruction
 
B07_業務の自動化を多角的に実現する Power Automate の世界 [Microsoft Japan Digital Days]
B07_業務の自動化を多角的に実現する Power Automate の世界 [Microsoft Japan Digital Days]B07_業務の自動化を多角的に実現する Power Automate の世界 [Microsoft Japan Digital Days]
B07_業務の自動化を多角的に実現する Power Automate の世界 [Microsoft Japan Digital Days]
 
Bca 2nd sem-u-1.2 digital logic circuits, digital component
Bca 2nd sem-u-1.2 digital logic circuits, digital componentBca 2nd sem-u-1.2 digital logic circuits, digital component
Bca 2nd sem-u-1.2 digital logic circuits, digital component
 

Semelhante a 作業系統與硬體元件的驅動軟體開發法則 (Operating Systems and Software Design Principles for Hardware Components)

嵌入式智慧應用開源軟硬整合新趨勢 (Open Source Software and Hardware Integration Trend for Emb...
嵌入式智慧應用開源軟硬整合新趨勢 (Open Source Software and Hardware Integration Trend for Emb...嵌入式智慧應用開源軟硬整合新趨勢 (Open Source Software and Hardware Integration Trend for Emb...
嵌入式智慧應用開源軟硬整合新趨勢 (Open Source Software and Hardware Integration Trend for Emb...William Liang
 
IoT Cloud Platforms- Players, Vendors and Vertical Segments -20160519
IoT Cloud Platforms- Players, Vendors and Vertical Segments -20160519IoT Cloud Platforms- Players, Vendors and Vertical Segments -20160519
IoT Cloud Platforms- Players, Vendors and Vertical Segments -20160519August Lin
 
Velocity2011分享
Velocity2011分享Velocity2011分享
Velocity2011分享Zoom Quiet
 
Chinese Uses of Big Data Cloud Security 漫步在雲端資安新戰場
Chinese Uses of Big Data Cloud Security 漫步在雲端資安新戰場 Chinese Uses of Big Data Cloud Security 漫步在雲端資安新戰場
Chinese Uses of Big Data Cloud Security 漫步在雲端資安新戰場 Bill Hagestad II
 
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego daycsdnmobile
 
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego daycsdnmobile
 
Zh120226techparty velocity2011-review
Zh120226techparty velocity2011-reviewZh120226techparty velocity2011-review
Zh120226techparty velocity2011-reviewZoom Quiet
 
Jira 4.0 白皮书
Jira 4.0 白皮书Jira 4.0 白皮书
Jira 4.0 白皮书YUCHENG HU
 
智慧應用與物聯網發展趨勢 (A Development Trend of Smart Applications and IoT)
智慧應用與物聯網發展趨勢 (A Development Trend of Smart Applications and IoT)智慧應用與物聯網發展趨勢 (A Development Trend of Smart Applications and IoT)
智慧應用與物聯網發展趨勢 (A Development Trend of Smart Applications and IoT)William Liang
 
Picoway Company Profile 1.5
Picoway Company Profile 1.5Picoway Company Profile 1.5
Picoway Company Profile 1.5picoway
 
Picoway Company Profile V1.5
Picoway Company Profile V1.5Picoway Company Profile V1.5
Picoway Company Profile V1.5picoway
 
The development trends of smart applications and open source system software ...
The development trends of smart applications and open source system software ...The development trends of smart applications and open source system software ...
The development trends of smart applications and open source system software ...William Liang
 
[MonkeyFest 2018 ] App 開發與 DevOps 上的實踐
[MonkeyFest 2018 ] App 開發與 DevOps 上的實踐[MonkeyFest 2018 ] App 開發與 DevOps 上的實踐
[MonkeyFest 2018 ] App 開發與 DevOps 上的實踐Edward Kuo
 

Semelhante a 作業系統與硬體元件的驅動軟體開發法則 (Operating Systems and Software Design Principles for Hardware Components) (20)

Android JNI
Android JNIAndroid JNI
Android JNI
 
嵌入式智慧應用開源軟硬整合新趨勢 (Open Source Software and Hardware Integration Trend for Emb...
嵌入式智慧應用開源軟硬整合新趨勢 (Open Source Software and Hardware Integration Trend for Emb...嵌入式智慧應用開源軟硬整合新趨勢 (Open Source Software and Hardware Integration Trend for Emb...
嵌入式智慧應用開源軟硬整合新趨勢 (Open Source Software and Hardware Integration Trend for Emb...
 
IoT Cloud Platforms- Players, Vendors and Vertical Segments -20160519
IoT Cloud Platforms- Players, Vendors and Vertical Segments -20160519IoT Cloud Platforms- Players, Vendors and Vertical Segments -20160519
IoT Cloud Platforms- Players, Vendors and Vertical Segments -20160519
 
SWsoft_Prim@Telecom
SWsoft_Prim@TelecomSWsoft_Prim@Telecom
SWsoft_Prim@Telecom
 
软件工程2010
软件工程2010软件工程2010
软件工程2010
 
Jobforcompal
JobforcompalJobforcompal
Jobforcompal
 
Velocity2011分享
Velocity2011分享Velocity2011分享
Velocity2011分享
 
Chinese Uses of Big Data Cloud Security 漫步在雲端資安新戰場
Chinese Uses of Big Data Cloud Security 漫步在雲端資安新戰場 Chinese Uses of Big Data Cloud Security 漫步在雲端資安新戰場
Chinese Uses of Big Data Cloud Security 漫步在雲端資安新戰場
 
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
 
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
上午2 intel 杜伟_iadp app_up intro - isn isc chn for idf meego day
 
Zh120226techparty velocity2011-review
Zh120226techparty velocity2011-reviewZh120226techparty velocity2011-review
Zh120226techparty velocity2011-review
 
Jira 4.0 白皮书
Jira 4.0 白皮书Jira 4.0 白皮书
Jira 4.0 白皮书
 
行動技術開發概論
行動技術開發概論行動技術開發概論
行動技術開發概論
 
智慧應用與物聯網發展趨勢 (A Development Trend of Smart Applications and IoT)
智慧應用與物聯網發展趨勢 (A Development Trend of Smart Applications and IoT)智慧應用與物聯網發展趨勢 (A Development Trend of Smart Applications and IoT)
智慧應用與物聯網發展趨勢 (A Development Trend of Smart Applications and IoT)
 
Picoway Company Profile 1.5
Picoway Company Profile 1.5Picoway Company Profile 1.5
Picoway Company Profile 1.5
 
Picoway Company Profile V1.5
Picoway Company Profile V1.5Picoway Company Profile V1.5
Picoway Company Profile V1.5
 
軟體安全防護大作戰
軟體安全防護大作戰軟體安全防護大作戰
軟體安全防護大作戰
 
The development trends of smart applications and open source system software ...
The development trends of smart applications and open source system software ...The development trends of smart applications and open source system software ...
The development trends of smart applications and open source system software ...
 
Ox office現在。即未來(201509)
Ox office現在。即未來(201509)Ox office現在。即未來(201509)
Ox office現在。即未來(201509)
 
[MonkeyFest 2018 ] App 開發與 DevOps 上的實踐
[MonkeyFest 2018 ] App 開發與 DevOps 上的實踐[MonkeyFest 2018 ] App 開發與 DevOps 上的實踐
[MonkeyFest 2018 ] App 開發與 DevOps 上的實踐
 

Mais de William Liang

Edge Computing for the Industry
Edge Computing for the IndustryEdge Computing for the Industry
Edge Computing for the IndustryWilliam Liang
 
From Embedded to IoT and From Cloud to Edge & AIoT -- A computer technology t...
From Embedded to IoT and From Cloud to Edge & AIoT -- A computer technology t...From Embedded to IoT and From Cloud to Edge & AIoT -- A computer technology t...
From Embedded to IoT and From Cloud to Edge & AIoT -- A computer technology t...William Liang
 
The key issues for teaching or learning Android and Linux Kernel
The key issues for teaching or learning Android and Linux KernelThe key issues for teaching or learning Android and Linux Kernel
The key issues for teaching or learning Android and Linux KernelWilliam Liang
 
Data-centric IoT (NTU CSIE 2016.12)
Data-centric IoT (NTU CSIE 2016.12)Data-centric IoT (NTU CSIE 2016.12)
Data-centric IoT (NTU CSIE 2016.12)William Liang
 
行動終端、物聯網與雲端平台在高速移動網路下的整合趨勢 (for MOPCON 2016)
行動終端、物聯網與雲端平台在高速移動網路下的整合趨勢 (for MOPCON 2016)行動終端、物聯網與雲端平台在高速移動網路下的整合趨勢 (for MOPCON 2016)
行動終端、物聯網與雲端平台在高速移動網路下的整合趨勢 (for MOPCON 2016)William Liang
 
高速移動網路新時代 - 雲端與物聯網發展新趨勢 (An Integration Trend of Terminal Devices, IoT and C...
高速移動網路新時代  - 雲端與物聯網發展新趨勢 (An Integration Trend of Terminal Devices, IoT and C...高速移動網路新時代  - 雲端與物聯網發展新趨勢 (An Integration Trend of Terminal Devices, IoT and C...
高速移動網路新時代 - 雲端與物聯網發展新趨勢 (An Integration Trend of Terminal Devices, IoT and C...William Liang
 
An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...William Liang
 
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)William Liang
 
Android device driver structure introduction
Android device driver structure introductionAndroid device driver structure introduction
Android device driver structure introductionWilliam Liang
 

Mais de William Liang (10)

Internet of energy
Internet of energyInternet of energy
Internet of energy
 
Edge Computing for the Industry
Edge Computing for the IndustryEdge Computing for the Industry
Edge Computing for the Industry
 
From Embedded to IoT and From Cloud to Edge & AIoT -- A computer technology t...
From Embedded to IoT and From Cloud to Edge & AIoT -- A computer technology t...From Embedded to IoT and From Cloud to Edge & AIoT -- A computer technology t...
From Embedded to IoT and From Cloud to Edge & AIoT -- A computer technology t...
 
The key issues for teaching or learning Android and Linux Kernel
The key issues for teaching or learning Android and Linux KernelThe key issues for teaching or learning Android and Linux Kernel
The key issues for teaching or learning Android and Linux Kernel
 
Data-centric IoT (NTU CSIE 2016.12)
Data-centric IoT (NTU CSIE 2016.12)Data-centric IoT (NTU CSIE 2016.12)
Data-centric IoT (NTU CSIE 2016.12)
 
行動終端、物聯網與雲端平台在高速移動網路下的整合趨勢 (for MOPCON 2016)
行動終端、物聯網與雲端平台在高速移動網路下的整合趨勢 (for MOPCON 2016)行動終端、物聯網與雲端平台在高速移動網路下的整合趨勢 (for MOPCON 2016)
行動終端、物聯網與雲端平台在高速移動網路下的整合趨勢 (for MOPCON 2016)
 
高速移動網路新時代 - 雲端與物聯網發展新趨勢 (An Integration Trend of Terminal Devices, IoT and C...
高速移動網路新時代  - 雲端與物聯網發展新趨勢 (An Integration Trend of Terminal Devices, IoT and C...高速移動網路新時代  - 雲端與物聯網發展新趨勢 (An Integration Trend of Terminal Devices, IoT and C...
高速移動網路新時代 - 雲端與物聯網發展新趨勢 (An Integration Trend of Terminal Devices, IoT and C...
 
An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...
 
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
An introduction to the linux kernel and device drivers (NTU CSIE 2016.03)
 
Android device driver structure introduction
Android device driver structure introductionAndroid device driver structure introduction
Android device driver structure introduction
 

作業系統與硬體元件的驅動軟體開發法則 (Operating Systems and Software Design Principles for Hardware Components)

  • 1. Note: The Copyrights of the referenced materials and photos go to its original authors. As a result, this slide is for internal reference only. For the contents created in this document, the Copyright belongs to William W.-Y. Liang. © 2005-2015 All Rights Reserved. Note: The Copyrights of the referenced materials and photos go to their original authors. As a result, this slide is for non-commercial reference only. For the contents created in this document, the Copyright belongs to William W.-Y. Liang. © 2005-2015 All Rights Reserved. 作業系統與硬體元件的驅動軟體開發法則 Operating Systems and Software Design Principles for Hardware Components William W.-Y. Liang (梁文耀), Ph.D. http: //www.ntut.edu.tw/~wyliang
  • 2. © 2015 William W.-Y. Liang, All Rights Reserved. 大綱 作業系統與驅動軟體架構 即時作業系統 (RTOS) 與一般用途作業系統 驅動程式與 RTOS, Linux, 及 Android 硬體元件的驅動軟體開發 硬體元件與系統軟體銜接的準備工作 驅動程式於作業系統中所扮演的角色 驅動程式介面定義與實現方法 驅動程式的開源與閉源考量 開放與貢獻源碼 的優點 如何兼顧開源標準與閉源優化 開源與閉源分界的設計原則 授權議題的處理原則與開源釋出準則 2 OS vs. Hardware Components
  • 3. © 2015 William W.-Y. Liang, All Rights Reserved. 嵌入式系統組成 Hardware Software development environment Tool chain and Library Boot loader OS Kernel / RTOS Middleware* Applications 3 OS vs. Hardware Components *Example: In Android, the middleware is called the Application Framework. Source: Qing Li and Caroline Yao, “real-time concepts for embedded systems”
  • 4. © 2015 William W.-Y. Liang, All Rights Reserved. 週邊裝置控制 Most of the I/O today is achieved by Memory-mapped I/O I/O devices communicate with the processor through a set of registers in the I/O controller. Control register Status register Data register 4 OS vs. Hardware Components
  • 5. © 2015 William W.-Y. Liang, All Rights Reserved. 即時作業系統 特性: 具備基本多工能力, 較容易滿足即時系統需求; 硬體須自行控制 Examples: VxWorks, Nucleus, ThreadX, QNX, RTEMS, Symbian, WinCE, TRON, uC/OS II, eCOS, FreeRTOS, mbed RTOS Application Development: Usually implemented as threads which share the same space with the kernel; MMU is usually not used; Real-time considerations (priority, timing constrains) 5 OS vs. Hardware Components
  • 6. © 2015 William W.-Y. Liang, All Rights Reserved. 一般用途作業系統 特性: 提供完整軟硬體資源管理機制; 應用程式不須顧慮底層硬體運作方 式; 可專注軟體系統設計, 發展具備完整架構之軟體堆疊; 較易發展 出功能複雜多樣化的軟體與應用產品 Example: Linux (with many Distributions), Android, Chrome OS, Firefox OS, Brillo, uClinux, MacOS, iOS, Windows Application development System independent application development: General applications, GUI/Window programming, Web programming System dependent software development: System programming, Device drivers, Protocol software 6 OS vs. Hardware Components & Brillo
  • 7. © 2015 William W.-Y. Liang, All Rights Reserved. 微控制器作業系統範例: mbed OS 7 OS vs. Hardware Components Supports a wide range of ARM Cortex-M based hardware platforms from major MCU vendors Provide a C++ Application Framework and component architecture Automation of power management Connectivity protocol stack support for BLE®, Cellular, Ethernet, Thread, Wi-fi®, Zigbee IP, Zigbee NAN, 6LoWPAN, TLS & DTLS end-to-end IP secure communication channels, OMA LWM2M protocol for device management Software asset protection and secure firmware updates for device security & management https: //developer.mbed.org/blog/entry/Anno uncing-our-plans-for-mbed-v30/
  • 8. © 2015 William W.-Y. Liang, All Rights Reserved. mbed RTOS 範例: Thread & ISR & I/O Control 8 OS vs. Hardware Components
  • 9. © 2015 William W.-Y. Liang, All Rights Reserved. 驅動程式在一般用途作業系統的定位 Device drivers are usually treated as black boxes for the application developers. They resemble as a software layer lying between the applications and the actual devices. 9 OS vs. Hardware Components http: //www.ni.com/tutorial/3789/en/
  • 10. © 2015 William W.-Y. Liang, All Rights Reserved. Linux 作業系統 Open source and free Maintained by numerous volunteer experts and hackers Robust, efficient, and reliable Modular, configurable, and scalable Tons of applications available Lower hardware requirement and BOM cost for mid-range to low-end products. Also suitable for general purpose computers, especially for high performance servers 10 OS vs. Hardware Components
  • 11. © 2015 William W.-Y. Liang, All Rights Reserved. Linux 驅動程式架構 UNIX/Linux systems implement device files to enable users to employ familiar commands and functions such as open, read, write, and close when working with some peripherals. 11 OS vs. Hardware Components Example file operations  int open( char *pathname, int flags, … );  int read( int fd, void *buf, size_t count );  int write( int fd, void *buf, size_t count );  int close( int fd );
  • 12. © 2015 William W.-Y. Liang, All Rights Reserved. Android作業系統 Consistent user experience and good UI design Easy to be commercialized Complete software framework Lower App development cost Already supported by millions Apps Applicable for m high-end to mid-range devices High portability for Apps and the OS itself Suitable for resource-limited handheld devices 12 OS vs. Hardware Components
  • 13. © 2015 William W.-Y. Liang, All Rights Reserved. Android 硬體抽象層 (HAL) A hardware abstraction layer (HAL) is an abstraction layer, implemented in software, between the physical hardware of a computer and the software that runs on that computer. Typically seen in portable operating system design, such as Linux. Realized in user-space of the Android operating system, with the concept of user-space device driver. 13 OS vs. Hardware Components
  • 14. © 2015 William W.-Y. Liang, All Rights Reserved. 大綱 作業系統與驅動軟體架構 即時作業系統 (RTOS) 與一般用途作業系統 驅動程式與 RTOS, Linux, 及 Android 硬體元件的驅動軟體開發 硬體元件與系統軟體銜接的準備工作 驅動程式於作業系統中所扮演的角色 驅動程式介面定義與實現方法 驅動程式的開源與閉源考量 開放與貢獻源碼 的優點 如何兼顧開源標準與閉源優化 開源與閉源分界的設計原則 授權議題的處理原則與開源釋出準則 14 OS vs. Hardware Components
  • 15. © 2015 William W.-Y. Liang, All Rights Reserved. 硬體元件與系統軟體銜接的準備工作 選定一個或兩個初步支持之作業系統 如 Linux, Android, Windows, mbed OS, QNX, etc. Linux 已為應用最廣泛的作業系統核心, 故為必要選項 研究既有作業系統對元件支持的程度與實現方式 由於 Linux 與 Android 為發展程度最高的開源專案, 目前 多數已標準化的軟硬體幾乎皆以 其為首要支持對象 已開源的部分可直接繼承來用: 藉以了解實作方式、避 免重複實作, 同時縮短開發時間. 步驟 根據各作業系統平台決定驅動程式介面 實作驅動程式 15 OS vs. Hardware Components
  • 16. © 2015 William W.-Y. Liang, All Rights Reserved. 驅動程式於作業系統中所扮演的角色 驅動程式與上下層的關係 對上: 符合作業系統運作流程 複雜度較高 不同作業系統有不同的「遊戲規則」 對下: 操作硬體 配合硬體流程 一般用途作業系統須考慮的問題 正確運作: 複雜的多執行緒運行環境 + 中斷造成複雜的 資源共享與同步問題 運行效能: 為了讓多工環境有效運行, 應謹慎共用資源 耗電考量: 行動裝置與節能議題 16 OS vs. Hardware Components
  • 17. © 2015 William W.-Y. Liang, All Rights Reserved. 驅動程式介面定義與實現方法 驅動程式即為一種硬體抽象層 Hardware Abstraction Layer (HAL) 介面函數規格定義應包含: 輸入命令與資料 輸出資料與狀態 規範與限制 Device Driver (HAL) API 隨作業系統而異 元件介面 Vendor API 則隨硬體功能由廠商定義 包含基礎操作功能, 通常與特定平台無關、具可移植性 可參考硬體功能與既有系統已定義的共通介面來設計 Glue實作: 基於 Vendor API 以實現對應驅動程式 17 OS vs. Hardware Components
  • 18. © 2015 William W.-Y. Liang, All Rights Reserved. 驅動程式的開源與閉源考量 開源與閉源的原則 只保護最需要的部分 其他部分可考慮盡量開放 沒有技術含量的部分 技術含量太低的部分 (亦即別人也很容易實現的地方) 開源 vs. 閉源 不開源代表必須自行維護, 包括處理各式各樣客戶的需 求 (會增加維護上的負擔與成本) 開源可借力使力, 可透過客戶或其他開發者協助改善軟 體品質 18 OS vs. Hardware Components http: //m.eettaiwan.com/ART_8800697488_676964_NT_57e14b60_2.HTM
  • 19. © 2015 William W.-Y. Liang, All Rights Reserved. 開放與貢獻源碼的優點 Upstream 源碼 將源碼貢獻回開源源碼庫 一旦開源社群審核並接受 之後, 開發者將持續為該源碼 進行維護 以 Linux Kernel 為例, 其優點包括: 較佳品質: 被維護的驅動程式可能被開發者 (Kernel Hackers) 改得更好 持續維護: 被接受的驅動程式可以持續被維護及更新 (特 別是對新版本的跟進), 長期來看可降低維護成本, 亦可延 長硬體銷售期. 提升公司能見度與 Credit 19 OS vs. Hardware Components
  • 20. © 2015 William W.-Y. Liang, All Rights Reserved. 如何兼顧開源標準與閉源優化 設計原則: 盡量採開源以擴大適用場域, 亦可降低長 期維護成本. 僅將最關鍵部分以閉源方式實作. 韌體實現方式 作法: 以韌體運行於元件內建微控制器 優點: 完全隔絕授權議題 缺點: 可使用資源較受限 驅動軟體方式 作法: 以驅動程式實現所有工作 優點: 可運用主系統資源 (CPU & Memory) 缺點: 需謹慎處理如 GPL 等授權問題 20 OS vs. Hardware Components
  • 21. © 2015 William W.-Y. Liang, All Rights Reserved. 如何兼顧開源標準與閉源優化 (續) 中介服務方式 作法: 透過中介軟體服務元件操作 優點: 可隔絕授權相關問題 缺點: 大量 IPC 影響運行效能 混合實作模式 作法: 將不重要的程式邏輯開源, 關鍵操作保留於韌體於 元件控制器或中介服務方式實現 優點: 可同時兼顧閉源與開源授權議題 缺點: 需良好的設計配套以降低溝通及資料傳輸延遲 21 OS vs. Hardware Components
  • 22. © 2015 William W.-Y. Liang, All Rights Reserved. 開源與閉源分界的設計原則 如何訂定開源閉源的分界點是一種藝術, 如同手術 一般, 漂亮的一刀是術後讓傷痕最小化的關鍵! 考量重點: 保護的價值 vs. 維護成本 vs. 運行效能 若有 GPL 開源授權考量, 可考慮將閉源部分放在: 軟體服務元件 (如 Android 與其他 OS) 雲端的伺服器軟體 (如雲端應用與 WebApp 做法) 獨立處理器的韌體 (如微控制器韌體) 驅動軟體的設計通常可將閉源程式邏輯實現於微控 制器韌體與上層軟體服務之中 (前述混合實作模式) 22 OS vs. Hardware Components
  • 23. © 2015 William W.-Y. Liang, All Rights Reserved. 附錄: 授權議題的處理原則 GPL 相關部分必須開放 其他部分能開放盡量開放 閉源而以 binary 呈現的部分, 於不違反 GPL 的前提下, 應具備 合理再散播之授權條款 如 MIT 或 BSD Licenses 或 NDA 23 OS vs. Hardware Components 認識 GPL  開源 ≠ GPL (General Public License)  強制開源的時機: GPL 軟體重新散佈(redistribution)時  GPL 的感染性  直接修改 GPL 源碼或靜態連結時必然發生  動態連結 (.so & .ko)則需由衍生作品角度來判定  正確運用 GPL: 適當拿捏開源與閉源可兼顧開放與保護的目的  GPL 塑造了開源巨人, 讓我們可站在其肩膀向前大步邁進!
  • 24. © 2015 William W.-Y. Liang, All Rights Reserved. 附錄: 源碼庫與開源釋出準則 目前採用最多的版本管理系統: git 開源源碼庫: e.g. github, bitbucket 最佳的開源方式: 貢獻至上游源碼庫(up-streaming) 需符合上游源碼架構, 包括Coding style、source tree structure、data structure、implementation methods 24 OS vs. Hardware Components
  • 25. © 2015 William W.-Y. Liang, All Rights Reserved. Q&A 其他分享: http://goo.gl/6qxlSv Home: http://www.ntut.edu.tw/~wyliang FB: http://www.facebook.com/william.wyliang Slideshare: http://www.slideshare.net/williamwyliang/ Email: william.wyliang@gmail.com 關於講者:梁文耀 (William W.-Y. Liang) • 顧問 / 開源貢獻者 (2014.10~) • 鴻海科技集團創新數位系統事業群資深處長 (2013.01~2014.09) • 安佐立科技顧問公司技術總監 (2012.08~2013.07) • 國立台北科技大學資訊工程系專任助理教授 (2005.02~2012.07) • 先前經歷: 聚興科技研發處協理、晶慧資訊研發副總經理、 晶慧資訊研發部經理、晶慧資訊資深工程師、美商 Avant! 軟體工程師 • 專長領域:作業系統、嵌入式系統、計算機結構、平行與分散式系統  Linux 系統軟體 (1993~Now)  Android 與 Linux 嵌入式系統核心及軟硬整合開發 (2001~Now) • 國立台灣大學資訊工程博士、國立清華大學資訊科學碩士 OS vs. Hardware Components25