zoukankan      html  css  js  c++  java
  • 树莓派

    树莓派上Linux驱动,从hello world 开始 ... 

    hello.c 

    #include <linux/init.h>  
    #include <linux/module.h>  
    #include <linux/moduleparam.h>  
      
    MODULE_LICENSE("Dual BSD/GPL");  
      
    static int hello_init(void)  
    {  
        printk(KERN_ALERT"Hello, world
    ");  
        return 0;  
    }  
      
    static void hello_exit(void)  
    {  
        printk(KERN_ALERT"Goodbye, cruel world
    ");  
    }  
      
    module_init(hello_init);  
    module_exit(hello_exit);

    Makefile

    ifneq ($(KERNELRELEASE),)  
      
    obj-m := hello.o  
      
    else  
          
    KDIR := /home/xxx/Raspberry/linux 
    all:  
    	make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=/home/xxx/Raspberry/tools-master/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-
    
    clean:  
    	rm -f *.ko *.o *.mod.o *.mod.c *.symvers  modul*  
      
    endif 

    make生成hello.ko

    将hello.ko 通过sftp 传给树莓派板


    在树莓派班上

    $ sudo insmod hello.ko

    查看:

    $ dmesg | grep Hello
    [ 7454.663309] Hello, world
    
    $ lsmod |grep hello
    hello                  16384  0
    


    pi@raspberrypi:/sys/module/hello $ tree -a
    .
    ├── coresize
    ├── holders
    ├── initsize
    ├── initstate
    ├── notes
    │   └── .note.gnu.build-id
    ├── refcnt
    ├── sections
    │   ├── .ARM.exidx
    │   ├── .ARM.extab
    │   ├── .gnu.linkonce.this_module
    │   ├── __mcount_loc
    │   ├── .note.gnu.build-id
    │   ├── .rodata.str1.4
    │   ├── .strtab
    │   ├── .symtab
    │   └── .text
    ├── srcversion
    ├── taint
    └── uevent
    
    3 directories, 17 files


    pi@raspberrypi:~ $ sudo rmmod hello
    pi@raspberrypi:~ $ dmesg | grep Goodbye
    [ 8385.391257] Goodbye, cruel world
    

    参考

    http://www.cnblogs.com/xianrou/p/6327897.html


  • 相关阅读:
    loj#6433. 「PKUSC2018」最大前缀和(状压dp)
    PKUWC2019游记
    10. Regular Expression Matching
    9. Palindrome Number
    8. String to Integer (atoi)
    7. Reverse Integer
    6. ZigZag Conversion
    5. Longest Palindromic Substring
    4. Median of Two Sorted Arrays
    3. Longest Substring Without Repeating Characters
  • 原文地址:https://www.cnblogs.com/feiwatson/p/9478222.html
Copyright © 2011-2022 走看看