--- title: Embedded System Final --- * Mid term questions are skipped * Progress: 1,2,3,4,5,6,7,8,9,10,11,12,13 (total 13) # 1. Device drivers are broadly classified into two basic categories: character devices and block devices. Please individually describe them. (10%) ## Appeared in 99, 99_2, 101, 102, 104, 105_1, 105_2, 106, 108 ## Derivation * Please simply describe the Device Driver concepts. (10%) 103_2 * 驅動程式,允許High-Level的軟體與硬體溝通的程式,建立了一個硬體與硬體,或硬體與軟體溝通的介面,讓device可以交換資料。 ## Answer ### Character devices 一個序列的資料流,以不定長度的字元來傳送資料 * Character devices are accessed as stream of data. * e.g. Serial port ### block devices 以一個block為單位,在可定址的隨機位址可讀取或寫入資料 * Read and write blocks of data from random locations on addressable medium. * e,g, disks # 2. Please refer to below example code of a Linux driver and then describe the functionalities of Section 1 and Section 2. ``` static int my_major = 0; … If (my_major) { // Section 1 dev = MKDEV(my_major, my_minor); result = register_chrdev_region(dev, nr_devs, “mydev”); } else { // Section 2 result = alloc_chrdev_region(&dev, my_minor, nr_devs, “mydev”); my_major = MAJOR(dev); } If (result < 0){ printk(KERN_WARNING “mydev: can’t get major %d\n”, my_major); return result; } ``` ## Appeared in 103, 105_1, 106, 108 ## Answer Section 1: * pre assigned * if my_major!=0, register device by using the assigned ***mymajor, myminor*** Section 2: * dynamic alloc (動態配置號碼) * else, dynamically register device # 3.What is the Proc File System? Please describe the functionalities of /proc file system. (10%) ## Appeared in 101, 103_2, 105_1, 105_2, 106, 108 ## Answer 一個虛擬的檔案系統,實現Linux核心空間與使用者空間的通訊 * Interface that allows the kernel to communicate information about each running process on a Linux system. * Communication between kernel space and user space # 4. What is Memory Technology Devices (MTD) subsystem? (10%) ## Appeared in 99, 99_2, 101, 102, 103, 103_2, 104, 105, 106, 108 ## Answer Application和driver中間的虛擬層。讓Application用相同的指令對不同的flash driver做相同的事,且可以設定欲使用的driver型號。 * A type of device file to interact with flash memory. * The MTD layer architecture enables the separation of the lowlevel device complexities from the higher-layer data organization and storage formats that use memory devices. # 5. Why the engineers usually mount a NFS to develop an embedded system? Please point out the advantages of NFS for building an embedded system. (10%) ## Appeared in 99_2, 101, 104, 105_1, 105_2, 106, 108 ## Answer 使用NFS可以把程式透過網路的方式將資料儲存在其他地方,如要使用或修改的時候一樣在透過網路的方式進行,讓儲存空間不在受限於硬體儲存空間。 可以直接在NFS上的系統安裝其他工具程式直接進行編譯,可以增加程式開發與效能的速度。 * Network File System * NFS enables you to export a directory on an NFS server and mount that directory on a remote client machine as if it were a local file system. In other words, access file on a server machine like it is a local file system. * developer can have access to a huge number of files, libraries, tools, and utilities during development and debugging, even if the target embedded system is resource constrained. # 6. Please list the advantages of cramfs. (10%) ## Appeared in 102, 104, 105_1, 106, 108 ## Answer cramfs是專門針對快閃記憶體設計的唯讀壓縮的檔案系統,不是將檔案系統中的所有內容解壓到ROM中,而是系統需要訪問某個位置的資料時再將其解壓縮到ROM中,節省ROM的儲存空間,使用簡單,加載容易,速度快 * A read-only ,compressed file system. Simple and small, ideal for boot ROMS # 7. What is the BusyBox in an embedded system? How to add a new command into the embedded system except the commands that BusyBox provides. (10%) ## Appeared in 99, 99_2, 102,103, 103_2, 104, 105, 106, 108 ## Answer 把常用的指令和參數壓縮成一個檔案 * BusyBox provides compact replacements for many traditional fullblown utilities found on most desktop and embedded Linux distributions. 1.在Busybox中勾選欲增加的指令 2.將欲增加的指令Source Code編譯後放在\bin中 * add a new command * 1. cross compile c then copy to bin * 2. 修改busybox設定 # 8. Please describe the functionalities and their advantages of DHCP server and NFS server. (10%) ## Appeared in 103 ## Answer #### DHCP DHCP server: 給內部網絡或網絡服務供應商自動分配IP位址、主機名、DNS伺服器、域名,方便管理。在子網移動中不需要重新設置IP,自動獲取就行。 * A DHCP server controls the IP address assignments for IP subnets for which it has been configured, and for DHCP or BOOTP clients that have been configured to participate. A DHCP server listens for requests from a DHCP client (such as your target board), and assigns addresses and other pertinent information to the client as part of the boot process. #### NFS NFS server: 讓不同的機器、不同的作業系統透過網路可以彼此分享個別的檔案。將常用的數據存放在一台服務器,可以通過網路訪問,減少本地端磁碟空間的使用。 * Network File System * Your root file system is not size-restricted by your board's own limited resources, such as Flash memory. * Changes made to your application files during development are immediately available to your target system. * You can debug and boot your kernel before developing and debugging your root file system. # 9 Fig. 1 shows a typical DHCP exchange, please explain the each step (4 steps) in Fig. 1. (10%) ![](https://i.imgur.com/b2u9ByN.png) ## Appeared in 103_2, 105_1 ## Answer 1. Client要求租用IP位址 * The sequence starts with the client (target) transmitting a broadcast frame attempting to discover a DHCP server. This is shown by the DHCPDISCOVER message shown. 2. DHCP提供可租用的IP位址 * The server responds (if it has been so configured and enabled) by offering an IP address for the client. This is evidenced by the DHCPOFFER message. 3. Client確認DHCP的IP租約 * The client then responds by testing this IP address locally. The testing includes sending the DHCPREQUEST packet to the DHCP server, as shown. 4. DHCP Server同意IP租約 * Finally, the server responds by acknowledging the IP address assignment to the client, thus completing the automatic target configuration. # 10. What advantages of Ext3 File System compared to Ext2 File System? How to convert an Ext2 File System to the Ext3 File System? (10%) ## Appeared in 103, 105_1, 106, 108 ## Answer ### Advantage Ext3加入了日誌檔用來記錄之前做了哪些事情,提高檔案系統的完整性,避免意外當機對檔案系統的破壞。 * Availability: By journaling, after an unexpected power failure or system crash, file system check is not necessary * Data complete: Journaling can prevent the data damage. * speed: ext3's journaling optimizes hard drive head motion. * Easy to convert: Don't have to reformat to migrate from ext2 to ext3 ### Convert 先將要轉換的磁碟先mount上去,再輸入"tune2fs -j 磁碟名稱",就會產生一個日誌檔 * mount ext2 file system `mount /dev/sdb1 /mnt/flash` * create journal `tune2fs -j /dev/sdb1` # 11 How to build a simple EXT2 file system and modify its content (add and delete directories, make device nodes, and so on). ## Appeared in 105_1, 106, 108 ## Answer 在一個一般的檔案中使用Linux loopback device建立一個EXT2 file system image,建立好之後我們就能在這個檔案裡擁有一個 EXT2 file system,如此一來就能對這個一般的檔案像對block device進行操作和調整。 ### Create file image * mke2fs ### make directory * mkdir ### remove directory * rmdir or rm ### make device node * mknod # 12 Please describe the functionalities of below module utilities. (10%) (1) insmod (2) lsmod (3) modprobe (4) depmod (5) rmmod ## Appeared in 106, 108 ## Answer ### insmod 載入模組到kernel * insert a module into a running kernel. ### lsmod 列出目前已經載入的driver * displays a formatted list of the modules that are inserted into the kernel ### modprobe Linux kernel新增或刪除模組 *和insmod不同的是此指令可以根據模組相依性載入 * discover this relationship and load the dependent modules in the proper order. ### depmod 查看這支driver是否與其他driver有相依性,就是A driver要能動必須先安裝B driver,生成modules.dep檔案和對映檔案。 * When modprobe is executed, it searches for a file called modules.dep in the same location where the modules are installed ### rmmod 刪除kernel中一個正在執行的模組 * It simply removes a module from a running kernel # 13 Please list the advantages of JFFS2. (10%) ## Appeared in 99 ## Answer 1. 支援 NAND flash memory 裝置。 2. 提供Hard links support,JFFS只能用soft link。 3. 提供zlib、rubin、rtime壓縮。 4. 比JFFS有更好的效能,透過演算法去收集垃圾資料將其清除。 * Support for NAND flash devices * Hard links * Compression * Better performance: JFFS treated the disk as a purelycircular log. This generated a great deal of unnecessary I/O. The garbage collection algorithm in JFFS2 makes this mostly unnecessary. # 14 What is the Initial RAM Disk? What is the purpose of Initial RAM Disk? ## Answer * (參考某題的答案)Initial ramdisk is a Linux kernel feature to mount an early root file system to perform certain startup-related system initialization and configuration * The initial RAM disk is a small self-contained root file system that usually contains directives to load specific device drivers before the completion of the boot cycle. * 中文解釋:初始RAM磁盤(Initial RAM Disk)是Linux系統中的一個臨時根文件系統,用於在系統引導過程中掛載以支持兩階段引導過程。它包含各種可執行文件和驅動程序,允許掛載真正的根文件系統,然後卸載initrd RAM磁盤並釋放其內存。在許多嵌入式Linux系統中,initrd是最終的根文件系統。初始RAM磁盤(initrd)和initramfs是Linux系統中加載臨時根文件系統的兩種方法。它們常用於在實際的根文件系統可以掛載之前進行準備工作。當使用initrd時,系統通常按以下步驟啟動:引導加載程序加載內核和初始RAM磁盤,內核將initrd轉換為“正常”的RAM磁盤,並釋放initrd使用的內存。如果根設備不是/dev/ram0,則會遵循舊的(已棄用的)change_root過程。初始RAM磁盤的目的是在系統引導過程中提供一個臨時的根文件系統,以便進行各種準備工作,例如**加載驅動程序、設置設備、配置網絡**等。它允許在實際的根文件系統被掛載之前執行必要的操作,從而確保系統能夠成功引導並進入正常運行狀態。一旦真正的根文件系統準備就緒,初始RAM磁盤就會被卸載,系統將轉移到真正的根文件系統上進行操作。總結起來,**初始RAM磁盤是Linux系統中的一個臨時根文件系統,用於在引導過程中提供必要的準備工作,以確保系統能夠成功引導並進入正常運行狀態**。 ###### tags: `Embedded system` `CSnote`