linux 筆記1基於iTop4412,學習記錄。(包括設備註冊設備驅動註冊使用)

以下內容是本人學習訊爲的4412,記錄的一些常用的指令和操作,以便以後查看方便。

 

內核編譯的指令:

進入文件夾“iTop4412_Kernel_3.0 ”,使用命令
“cp config_for_android_pop_elite .config”覆蓋自帶的配置文件,如下圖所示
 

 

 

二.模塊加載方法

1.將生成的  .ko 文件拷貝到u盤或者 sd卡  

2.將u 盤或者 sd卡 插到開發板 

3.使用命令, ls  /mnt 查看可掛載的盤目錄 

 ls /mnt/disk

4.掛載U盤  使用命令

mount /dev/sda1 /mnt/disk/   ( mount /dev/mmcblk1p1 /mnt/disk    )

5.加載模塊,使用命令

insmod /mnt/disk/mini_linux_module.ko

5.查看模塊使用命令

lsmod /mnt/disk/mini_linux_module.ko   或者 cat /proc/modules 

 

 

6.卸載模塊 使用命令

rmmod /mnt/disk/mini_linux_module.ko

(如果出現無法卸載的情況 :rmmod: can't change directory to '/lib/modules': No such file or directory
提示沒有'/lib/modules'目錄
– 使用命令“#mkdir /lib/modules”,新建一個目錄
• 是用rmmod命令仍然會出現如下錯誤:
– rmmod: can't change directory to '3.0.15': No such file or directory
• 提示沒有目錄'3.0.15'
– 使用命令“#mkdir /lib/modules/3.0.15”,繼續建目錄

 

三.ADB 寫 zImage  過程

1.reboot

2.fastboot

3.   fastboot.exe falsh kernel zImage 

4.輸入擦除命令fastboot -w

5.Windows 命令行中,輸入重啓開發板命令    fastboot reboot

 

 

 

四 。fastboot 模式命令

(創建 eMMC 分區並格式化。如果原來已經做過此步驟,則可以跳過,不必每次燒寫前
都分區和格式化。在超級終端中,輸入下面分區和格式化命令。
如下圖所示,輸入分區命令“fdisk -c 0”。

如下圖所示,輸入命令“ext3format mmc 0:2
如下圖所示,輸入命令“ext3format mmc 0:3”
如下圖所示,輸入命令“ext3format mmc 0:4”
在超級終端中,輸入命令“fastboot”)

進入fastboot :

如下圖,在 Windows 命令行中,輸入命令“adb services”。
會彈出 adb 命令的幫助文件
如下圖,查找 adb 設備,在 Windows 命令行中,輸入命令“adb devices”

如下圖,上傳 C 的測試程序,到安卓的“data”文件夾中。
在 Windows 命令行中,輸入命令“adb push helloworld /data”。

 

  燒寫步驟:

1.

(輸入燒寫 uboot 命令 “fastboot.exe flash bootloader u-boot-iTOP-4412.bin”
特別提醒,不建議用戶燒寫“u-boot-iTOP-4412.bin”這個文件,可跳過此步驟,因爲出廠
前已經燒寫過這個鏡像文件了。
)

a.輸入燒寫 zImage 內核命令“fastboot.exe flash kernel zImage”

b.輸入燒寫 ramdisk 命令 “fastboot.exe flash ramdisk ramdisk-uboot.img”

c.輸入燒寫 system 文件系統命令“fastboot.exe flash system system.img”

 

2. 輸入擦除命令“ fastboot -w ” (abc 燒寫完之後輸入此命令)

注意:上述 fastboot.exe flash 命令可以分開執行,只燒寫單個的鏡像。


3.在 Windows 命令行中,輸入重啓開發板命令“fastboot reboot”

 

五。常用的命令和目錄

vi arch/arm/mach-exynos/mach-itop4412.c   (包含 4412 的所有驅動的接口定義驅動)。

1. 查看總線命令  ls /sys/bus/   

2.查看設備好的命令  cat  /proc/devices

3.查看雜項設備號的命令 cat /proc/misc

 

六。設備的註冊

內核源碼路徑下: root@ubuntu:/home/topeet/android4.0/iTop4412_Kernel_3.0#
設備註冊需要做的
1.   vim include/linux/platform_device.h   // 查看 platform_device  結構體參數,
                包含設備註冊和設備的註銷函數 platform_device_register()   platform_device_unregister()
                
2.vim arch/arm/mach-exynos/mach-itop4412.c  //仿照 leds 添加hello的函數
                                                                    #ifdef CONFIG_HELLO_CTL
                                                                        struct platform_device s3c_device_hello_ctl = {
                                                                                .name   = "hello_ctl",
                                                                                .id             = -1,
                                                                        };
                                                                    #endif

                                                                    #ifdef CONFIG_HELLO_CTL
                                                                            &s3c_device_hello_ctl,
                                                                    #endif
                                                        
3.        vim drivers/char/Kconfig       // 添加 HELLO_CTL 宏定義 

                                        config HELLO_CTL
                                                tristate "Enable HELLO config"
                                                default y
                                                help
                                                  Enable HELLO config        

4.make menuconfig 查看下是否有選上【*】Enable HELLO config   然後 make zImage 然後再將生成的 zImage  通過 fastboot模式寫到板子上(fastboot.exe flash kernel zImage     -> fastboot reboot ) 

5.在超級串口上 輸入命令     ls /sys/devices/plantform           查看  設備是否註冊 查看到 hello_ctl   則設備已經註冊。                                  

七。 驅動註冊

內核源碼路徑下: root@ubuntu:/home/topeet/android4.0/iTop4412_Kernel_3.0#
驅動註冊需要做的
1.1.   vim include/linux/platform_device.h   // 查看 platform_driver 結構體參數,
                                            struct platform_driver {
                                                    int (*probe)(struct platform_device *);
                                                    int (*remove)(struct platform_device *);
                                                    void (*shutdown)(struct platform_device *);
                                                    int (*suspend)(struct platform_device *, pm_message_t state);
                                                    int (*resume)(struct platform_device *);
                                                    struct device_driver driver;
                                                    const struct platform_device_id *id_table;
                                            };

                                            extern int platform_driver_register(struct platform_driver *);
                                            extern void platform_driver_unregister(struct platform_driver *);
2.在之前的mini_linux_module 的基礎上做修改 文件 並命名爲 : probe_linux_module
3.修改文件 Makefile 中的  obj-m += probe_linux_module.o 
4.將新建文件夾  home/topeet/probe_linux_module  並將新改的文件,拷貝到新建文件夾裏。
5.make  生成了對應的 probe_linux_module .ko 文件 拷貝到u 盤 
6.在開發板上,掛載U盤   mount /dev/sta1 /mnt/disk   ->  

輸入初始化命令   insmod /mnt/disk/probe_linux_module.ko 
 輸入 rmmod  (如果提示錯誤則 rmmod -r probe_linux_module   mkdir /lib/modules/3.0.15   )
 然後再輸入  rmmod -r probe_linux_module   會打印  HELLO WORLD exit!

至此驅動註冊到卸載驅動 實驗完成。

 

八。生成設備節點(以下是雜項設備類。引入雜項設備1.節省主設備號 2.驅動寫起來簡單 )
雜項設備初始化部分源文件“drivers/char/ misc.c” 在Makefile 裏強制編譯的 
#include <linux/fs.h> 註冊設備節點的文件結構體 
1.雜項設備頭文件 #include <linux/miscdevice.h>  使用命令可查看 結構體 misdevice以及註冊函數   vim include/linux/miscdevice.h

                                        struct device;

                                        struct miscdevice  {
                                                int minor;  //設備號
                                                const char *name; //生成節點的名稱
                                                const struct file_operations *fops; //指向一個設備節點文件 
                                                struct list_head list;
                                                struct device *parent;
                                                struct device *this_device;
                                                const char *nodename;
                                                mode_t mode;
                                        };

                                        extern int misc_register(struct miscdevice * misc);
                                        extern int misc_deregister(struct miscdevice *misc);
2.以後的步驟參考上一節的內容。
 ls /dev   k可以看到我們註冊的設備節點 名是  ; hello_ctl123 

 

 

九。雜項設備驅動應用

編寫的簡單應用 調用設備驅動    調用 HELLO_CTL123 設備節點
1.應用中用到的頭文件
    include<stdio.h>    //調用打印函數 printf
    
    #include<sys/types.h>  //基本系統數據類型 。系統的基本數據類型在32位編譯環境中保持爲32 位值,並在64編譯環境中保持64位值。
    #include<sys/stat.h> //系統調用函數頭文件。可以調用普通的文件,目錄,管道。socket,字符,塊的屬性。
    #include<fcntl.h >定義了open函數
    #include<unistd.h >定義了close函數
    #include<sys/ioctl.h >定義了ioctl函數
調用的頭文件是和編譯器放在一起的
– 這裏使用arm2009q3編譯器,編譯器使用arm-none-linux-gnueabi-gcc
• 在編譯器目錄下使用查找命令找到該頭文件
進到目錄下 root@ubuntu:/usr/local/arm/arm-2009q3# 

– 例如#find ./ -name types.h    
    
2.調用的函數
– open函數是返回文件描述符
– ioctl函數是應用向驅動傳值
– close函數是關閉打開的文件    

編寫應用程序的代碼,編譯 invoke_hello  新建文件 invoke_hello.c  
– arm-none-linux-gnueabi-gcc -o invoke_hello invoke_hello.c -static
開發板中拷貝 devicenode_linux_module.ko 驅動,
加載驅動 insmod /mnt/disk/devicenode_linux_module.ko 
修改權限 chmod 777 /mnt/disk/invoke_hello
運行應用 ./mnt/disk/invoke_hello
 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章