入门驱动hello模块的编辑,装载以及卸载

1.1创建一个hello.c文件
[zoulei@localhost ~]$ mkdir hello
[zoulei@localhost ~]$ ls
!                      cp               hello              模板  音乐
a.out                   dir              linux-3.0          视频  桌面
busybox-1.19.3          dropbear-0.53.1  linux-3.0.tar.bz2  图片
busybox-1.19.3.tar.bz2  duilie.c         svn                文档
caipiao.c               fl2440           公共的             下载
[zoulei@localhost ~]$cd hello/
[zoulei@localhost hello]$ls

[zoulei@localhost hello]$vim hello.c

#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/module.h>

           /*初始化函数 */
static int __init hello_init(void)
  {
      printk(KERN_ALERT "Welcome zoulei\n");return 0;
  }

          /*清除函数*/
 static void __exit hello_exit(void)                /*被__exit修饰词标记该代码仅用于模块卸载,或者系统关闭时*/
 {
 		
      printk(KERN_ALERT "Byebye!zoulei\n");
 
  }
 
  module_init(hello_init);                         /*用于指定模块初始化函数的宏*/
  module_exit(hello_exit);                         /*用于指定模块清除函数的宏,该声明帮助内核找到模块的清除函数是必须的,如果一个模块未定义清除函数,则内核不允许卸载该模块*/
 
 
  MODULE_AUTHOR("Zoulei<zoulei@gmail.com>");                        /*描述模块作者*/
  MODULE_DESCRIPTION("lt’s just a linux kernel module sample");   /*用来说明模块用途的简短描述*/
  MODULE_LICENSE("GPL");                                            /*指定代码使用的许可证*/


******************************************************************************************************************

编译出现的问题

编译error:  static void __exit hello_exit(void)没有定义,
解决:原因是“__”是双下划线。前缀是双下划线(_ _)的函数应该谨慎使用。

******************************************************************************************************************
                                                              1,5          顶端

1.2Hello 驱动的Makefile编写:

适用于Linux操作系统:
hello.c同一级目录下创建Makefile
 [zoulei@localhost hello]$vimMakefile
 LINUX_SRC ?= ~/fl2440/kernel/linux-3.0
   CROSS_COMPILE=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
  
   obj-m :=hello.o
  
   modules:
           @make -C $(LINUX_SRC) M=`pwd` modules
           @make clean
  
  clean:
          rm -f *.ko.* *.o *mod.c *.order *.symvers
 
~              

 [zoulei@localhost hello]$ ls
   hello.c  Makefile  
[zoulei@localhost hello]$ make
make[1]: Entering directory `/home/zoulei/fl2440/kernel/linux-3.0'
  CC [M]  /home/zoulei/hello/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/zoulei/hello/hello.mod.o
  LD [M]  /home/zoulei/hello/hello.ko
make[1]: Leaving directory `/home/zoulei/fl2440/kernel/linux-3.0'
make[1]: Entering directory `/home/zoulei/hello'
rm -f *.ko.* *.o *mod.c *.order *.symvers
make[1]: Leaving directory `/home/zoulei/hello'
[zoulei@localhost hello]$ls
hello.c  hello.ko  Makefile
****************************************************************************************************************
Make出现错误:原因是`pwd`里面的``这个符号写为引号‘’
modules:
            @make -C $(LINUX_SRC) M=`pwd` modules
            @make clean
 *************************************************************************
1.3在开发板上操作
>: ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:3E:26:0A:5B
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1298 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3864 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:208149 (203.2 KiB)  TX bytes:164803 (160.9 KiB)
          Interrupt:51 Base address:0x2300

>: tftp -gr hello.ko 192.168.1.115
hello.ko             100% |*******************************| 25335   0:00:00 ETA
>: ls
apps      dev       info      linuxrc   root      tmp
bin       etc       init      mnt       sbin      usr
data      hello.ko  lib       proc      sys       var
>: du hello.ko
25      hello.ko
>: insmod hello.ko
Welcome zoulei
>: rmmod hello
Byebye!zoulei

>: dmesg
Linux version 3.0.0 (zoulei@localhost.localdomain) (gcc version 4.5.3 (Buildroot 2012.02) ) #14 Sat Mar 18 17:24:14 PDT 2017
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: SMDK2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
S3C244X: core 405.600 MHz, memory 101.400 MHz, peripheral 50.700 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
On node 0 totalpages: 16384
free_area_init_node: node 0, pgdat c0494078, node_mem_map c04d0000
  Normal zone: 128 pages used for memmap
  Normal zone: 0 pages reserved
  Normal zone: 16256 pages, LIFO batch:3
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: noinitrd root=/dev/mtdblock2 rootfstype=jffs2 init=/linuxrc console=ttyS0,115200
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 59984k/59984k available, 5552k reserved, 0K highmem
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)
    DMA     : 0xffc00000 - 0xffe00000   (   2 MB)
    vmalloc : 0xc4800000 - 0xf6000000   ( 792 MB)
    lowmem  : 0xc0000000 - 0xc4000000   (  64 MB)
    modules : 0xbf000000 - 0xc0000000   (  16 MB)
      .init : 0xc0008000 - 0xc0027000   ( 124 kB)
      .text : 0xc0027000 - 0xc046fbc4   (4387 kB)
      .data : 0xc0470000 - 0xc04948a0   ( 147 kB)
       .bss : 0xc04948c4 - 0xc04cf6e4   ( 236 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:85
irq: clearing pending ext status 00000800
irq: clearing subpending status 00000003
irq: clearing subpending status 00000002
timer tcon=00500000, tcnt a509, tcfg 00000200,00000000, usec 00001e4c
Console: colour dummy device 80x30
console [ttyS0] enabled
Calibrating delay loop... 202.54 BogoMIPS (lpj=506368)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
gpiochip_add: gpios 288..303 (GPIOK) failed to register
gpiochip_add: gpios 320..334 (GPIOL) failed to register
gpiochip_add: gpios 352..353 (GPIOM) failed to register
NET: Registered protocol family 16
S3C Power Management, Copyright 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C244X: Clock Support, DVS off
bio: create slab <bio-0> at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 99 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
Advanced Linux Sound Architecture Driver Version 1.0.24.
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 117
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttyS0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttyS1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttyS2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 42 at 0x000000540000
Bad eraseblock 257 at 0x000002020000
Bad eraseblock 398 at 0x0000031c0000
Bad eraseblock 644 at 0x000005080000
Creating 6 MTD partitions on "NAND":
0x000000000000-0x000000100000 : "boot loader"
ftl_cs: FTL header not found.
0x000000100000-0x000001000000 : "linux kernel"
ftl_cs: FTL header not found.
0x000001000000-0x000005000000 : "rootfs"
ftl_cs: FTL header not found.
0x000005000000-0x00000a000000 : "apps"
uncorrectable error :
0x00000a000000-0x00000f000000 : "data"
ftl_cs: FTL header not found.
0x00000f000000-0x000010000000 : "backup"
ftl_cs: FTL header not found.
dm9000 Ethernet Driver, V1.31
eth0: dm9000a at c4862300,c4864304 IRQ 51 MAC: 08:00:3e:26:0a:5b (chip)
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mousedev: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
ALSA device list:
  No soundcards found.
TCP cubic registered
NET: Registered protocol family 17
Registering the dns_resolver key type
usb 1-1: new full speed USB device number 2 using s3c2410-ohci
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
VFS: Mounted root (jffs2 filesystem) on device 31:2.
Freeing init memory: 124K
dm9000 dm9000: eth0: link down
dm9000 dm9000: eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
Welcome zoulei
Byebye!zoulei

**************************************************************************************************************************************************************************
遇到的错误及解决办法:


开发板ping不通虚拟机,出现timeout,但开发板可以ping通本机,虚拟机也可以ping通开发板。
解决:原因是虚拟机设置有线网卡时没有选有线网卡选项如下图,选上即可解决.

总结:本机有线ip:  192.168.1.2
          虚拟机ip:     192.168.1.115
          fl2440开发板ip:     192.168.1.111
虚拟机要设置为桥接模式,手动设置虚拟机ip地址
开发板,本机,虚拟机三者之间要相互之间能够通信的充分必要条件是:(1)软件上,网络号要相同,也就是它们各自的ip地址与各自的子网掩码做与运算得到的网络号是相同的。
                                                                                                         (2)硬件上,物理之间要连接起来,也就是开发板与pc要用网线连接起来。
 



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值