从零开始之驱动发开、linux驱动(四十三、移植新的4.19版本的内核)

在kernel.org下载最新版本的内核,我下载的是linux-4.19版本的

因为新的内核只支持设备树方式启动,所以打算开始学习设备树。本篇博文不分析任何设备树的东西,只做移植使用。

先保证内核可以启动后再开一个专栏学习设备树。

 

 

1. 首先是找到默芯片认配置,我们是s5pv210_defconfig

 

2.配置内核

打开顶层的Makefile文件,搜索ARCH

把该行改为  ARCH  ?=  arm

3.默认配置

make s5pv210_defconfig

4.配置内核

make menuconfig

配置默认调试输出串口

支持 网络

[*] Networking support  ---> 
        Networking options  --->
            <*> Packet socket    
            
            <*> Unix domain sockets
  
            [*] TCP/IP networking
           
            [*]   IP: kernel level autoconfiguration    
            [*]     IP: DHCP support  
            [*]     IP: BOOTP support    
            [*]     IP: RARP support  

Device Drivers  --->   
    [*] Network device support  --->  
        [*]   Network core driver support 
        ......
        [*]   Ethernet driver support  --->      
            <*>   DM9000 support   

支持网络文件系统

File systems  --->  
    [*] Network File Systems  ---> 
        <*>   NFS client support   
        <*>     NFS client support for NFS version 2 (NEW)
        <*>     NFS client support for NFS version 3 (NEW)

        [*]   Root file system on NFS 

5. 修改设备树文件

更改命令行参数为

 bootargs = "console=ttySAC2,115200n8 root=/dev/nfs nfsroot=192.168.0.101:/home/run/work/rootfs/rootfs_3.16.57 ip=192.1    68.0.20 init=/linuxrci earlyprintk";

修改内存为

memory {
        device_type = "memory";
         reg = <0x30000000 0x20000000>;
    };

修改网卡为

ethernet@88000000 {
        compatible = "davicom,dm9000";
        reg = <0x88000000 0x2 0x88000004 0x2>;
        interrupt-parent = <&gph1>;
        interrupts = <2 4>;
        local-mac-address = [00 00 de ad be ef];
        davicom,no-eeprom;
        clocks = <&clocks CLK_SROMC>;
        clock-names = "sromc";
    };  

 

因为内核启动过程成关闭了SROM的时钟,所以要在DM9000中开启时钟。

下面是补丁文件内容

-- linux-4.19/drivers/net/ethernet/davicom/dm9000.c    2018-10-22 14:37:37.000000000 +0800
+++ linux-4.19.ok/drivers/net/ethernet/davicom/dm9000.c 2019-01-24 22:23:11.896498427 +0800
@@ -40,6 +40,8 @@
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
 
+#include <linux/clk.h>  //add  zb
+
 #include <asm/delay.h>
 #include <asm/irq.h>
 #include <asm/io.h>
@@ -1436,6 +1438,7 @@
    enum of_gpio_flags flags;
    struct regulator *power;
    bool inv_mac_addr = false;
+   const char *clk_name;
 
    power = devm_regulator_get(dev, "vcc");
    if (IS_ERR(power)) {
@@ -1572,6 +1575,20 @@
        ret = -EINVAL;
        goto out;
    }   
+   
+   //zb add
+    /* Enable clock if specified */
+    if (!of_property_read_string(dev->of_node, "clock-names", &clk_name)) {
+        struct clk *clk = devm_clk_get(dev, clk_name);
+        if (IS_ERR(clk)) {
+            dev_err(dev, "cannot get clock of %s\n", clk_name);
+            ret = PTR_ERR(clk);
+            goto out;
+        }
+        clk_prepare_enable(clk);
+        dev_info(dev, "enable clock '%s'\n", clk_name);
+    }
+

    /* fill in parameters for net-dev structure */
    ndev->base_addr = (unsigned long)db->io_addr;

 

把之前2017.1的uboot的启动命令行由

#define CONFIG_BOOTCOMMAND    "tftpboot 0x30007fc0 uImage;bootm 0x30007fc0"

更换成

 #define CONFIG_BOOTCOMMAND "tftpboot 40000000 s5pv210-x210.dtb;tftpboot 30007fc0 uImage;bootm 30007fc0 - 40000000"
wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

 

启动后效果如下,后面开始花半个月时间学习设备树。

SD checksum Error


U-Boot 2017.01 (Feb 13 2019 - 23:01:18 +0800)

CPU:   S5PC110 @ 1 GHz
Model: Samsung Goni based on S5PC110
Board:  SMDKV210
DRAM:  512 MiB
MMC:   SAMSUNG SDHCI: 0, SAMSUNG SDHCI: 1
MMC partition switch failed
*** Warning - MMC partition switch failed, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0 
dm9000 i/o: 0x88000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:09:c0:ff:ec:48
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.0.101; our IP address is 192.168.0.20
Filename 's5pv210-x210.dtb'.
Load address: 0x40000000
Loading: ##
         443.4 KiB/s
done
Bytes transferred = 24995 (61a3 hex)
dm9000 i/o: 0x88000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:09:c0:ff:ec:48
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.0.101; our IP address is 192.168.0.20
Filename 'uImage'.
Load address: 0x30007fc0
Loading: #################################################################
         #################################################################
         #################################################################
         ###################################################
         663.1 KiB/s
done
Bytes transferred = 3602136 (36f6d8 hex)
## Booting kernel from Legacy Image at 30007fc0 ...
   Image Name:   Linux-4.19.0
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    3602072 Bytes = 3.4 MiB
   Load Address: 30008000
   Entry Point:  30008000
## Flattened Device Tree blob at 40000000
   Booting using the fdt blob at 0x40000000
   XIP Kernel Image ... OK
   Loading Device Tree to 3fff6000, end 3ffff1a2 ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.19.0 (run@ubuntu) (gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29)) #2 PREEMPT Wed Feb 13 22:33:30 CST 2019
CPU: ARMv7 Processor [412fc082] revision 2 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
OF: fdt: Machine model: YIC System SMDKV210 based on S5PV210
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
random: get_random_bytes called from start_kernel+0x88/0x3ec with crng_init=0
Built 1 zonelists, mobility grouping on.  Total pages: 130048
Kernel command line: root=/dev/nfs nfsroot=192.168.0.101:/home/run/work/rootfs/rootfs_3.16.57 ip=192.168.0.20:192.168.0.101:192.168.0.1:255.255.255.0::eth0:off init=/linuxrc console=ttySAC2,115200
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 510976K/524288K available (5120K kernel code, 209K rwdata, 1504K rodata, 1024K init, 248K bss, 13312K reserved, 0K cma-reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xa0800000 - 0xff800000   (1520 MB)
    lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
    modules : 0x7f000000 - 0x80000000   (  16 MB)
      .text : 0x(ptrval) - 0x(ptrval)   (6112 kB)
      .init : 0x(ptrval) - 0x(ptrval)   (1024 kB)
      .data : 0x(ptrval) - 0x(ptrval)   ( 210 kB)
       .bss : 0x(ptrval) - 0x(ptrval)   ( 249 kB)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
rcu: Preemptible hierarchical RCU implementation.
        Tasks RCU enabled.
NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
VIC @(ptrval): id 0x00041192, vendor 0x41
S5PV210 clocks: mout_apll = 1000000000, mout_mpll = 667000000
        mout_epll = 96000000, mout_vpll = 54000000
sched_clock: 32 bits at 33MHz, resolution 29ns, wraps every 64392313329ns
clocksource: samsung_clocksource_timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 57309158834 ns
Console: colour dummy device 80x30
Calibrating delay loop... 996.14 BogoMIPS (lpj=4980736)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
CPU0: Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable
Setting up static identity map for 0x30100000 - 0x30100060
rcu: Hierarchical SRCU implementation.
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 2
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
futex hash table entries: 256 (order: 0, 7168 bytes)
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
clocksource: Switched to clocksource samsung_clocksource_timer
NET: Registered protocol family 2
tcp_listen_portaddr_hash hash table entries: 256 (order: 0, 6144 bytes)
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 4, 81920 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 12288 bytes)
UDP-Lite hash table entries: 256 (order: 1, 12288 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.
Initialise system trusted keyrings
workingset: timestamp_bits=30 max_order=17 bucket_order=0
romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
Key type asymmetric registered
Asymmetric key parser 'x509' registered
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
e2900000.serial: ttySAC0 at MMIO 0xe2900000 (irq = 58, base_baud = 0) is a S3C6400/10
e2900400.serial: ttySAC1 at MMIO 0xe2900400 (irq = 59, base_baud = 0) is a S3C6400/10
e2900800.serial: ttySAC2 at MMIO 0xe2900800 (irq = 60, base_baud = 0) is a S3C6400/10
console [ttySAC2] enabled
e2900c00.serial: ttySAC3 at MMIO 0xe2900c00 (irq = 61, base_baud = 0) is a S3C6400/10
exynos4-fb f8000000.fimd: failed to get system register.
OF: graph: no port node found in /soc/fimd@f8000000
[drm] Exynos DRM: using f8000000.fimd device for DMA mapping operations
exynos-drm exynos-drm: bound f8000000.fimd (ops fimd_component_ops)
[drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[drm] No driver support for vblank timestamp query.
[drm] sclk_fimd clock too low(0) for requested pixel clock(24373000)
[drm] sclk_fimd clock too low(0) for requested pixel clock(24373000)
[drm] sclk_fimd clock too low(0) for requested pixel clock(24373000)
Console: switching to colour frame buffer device 100x30
[drm] sclk_fimd clock too low(0) for requested pixel clock(24373000)
exynos-drm exynos-drm: fb0:  frame buffer device
[drm] Initialized exynos 1.1.0 20180330 for exynos-drm on minor 0
brd: module loaded
loop: module loaded
dm9000 88000000.ethernet: 88000000.ethernet supply vcc not found, using dummy regulator
dm9000 88000000.ethernet: Linked as a consumer to regulator.0
dm9000 88000000.ethernet: enable clock 'sromc'
eth0: dm9000b at (ptrval),(ptrval) IRQ 144 MAC: 00:00:de:ad:be:ef (platform data)
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-exynos: EHCI EXYNOS driver
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
ohci-exynos: OHCI EXYNOS driver
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdhci eb000000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb000000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
mmc0: SDHCI controller on samsung-hsmmc [eb000000.sdhci] using ADMA
s3c-sdhci eb100000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb100000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
mmc1: SDHCI controller on samsung-hsmmc [eb100000.sdhci] using ADMA
s3c-sdhci eb200000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb200000.sdhci: clock source 2: mmc_busclk.2 (96000000 Hz)
mmc2: SDHCI controller on samsung-hsmmc [eb200000.sdhci] using ADMA
s3c-sdhci eb300000.sdhci: clock source 0: mmc_busclk.0 (133400000 Hz)
s3c-sdhci eb300000.sdhci: clock source 3: mmc_busclk.3 (96000000 Hz)
mmc2: new high speed SDHC card at address b368
mmc3: Internal clock never stabilised.
mmc3: sdhci: ============ SDHCI REGISTER DUMP ===========
mmcblk2: mmc2:b368 NCard 3.70 GiB 
mmc3: sdhci: Sys addr:  0x00000000 | Version:  0x00002401
 mmcblk2: p1
mmc3: sdhci: Blk size:  0x00000000 | Blk cnt:  0x00000000
mmc3: sdhci: Argument:  0x00000000 | Trn mode: 0x00000000
mmc3: sdhci: Present:   0x01fa0000 | Host ctl: 0x00000000
mmc3: sdhci: Power:     0x0000000e | Blk gap:  0x00000000
mmc3: sdhci: Wake-up:   0x00000000 | Clock:    0x00008001
mmc3: sdhci: Timeout:   0x00000000 | Int stat: 0x00000000
mmc3: sdhci: Int enab:  0x00ff0043 | Sig enab: 0x00ff0043
mmc3: sdhci: AC12 err:  0x00000000 | Slot int: 0x00000000
mmc3: sdhci: Caps:      0x05e80080 | Caps_1:   0x00000000
mmc3: sdhci: Cmd:       0x00000000 | Max curr: 0x00000000
mmc3: sdhci: Resp[0]:   0x00000000 | Resp[1]:  0x00000000
mmc3: sdhci: Resp[2]:   0x00000000 | Resp[3]:  0x00000000
mmc3: sdhci: Host ctl2: 0x00000000
mmc3: sdhci: ADMA Err:  0x00000000 | ADMA Ptr: 0x00000000
mmc3: sdhci: ============================================
mmc3: SDHCI controller on samsung-hsmmc [eb300000.sdhci] using ADMA
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
NET: Registered protocol family 10
Segment Routing with IPv6
sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
NET: Registered protocol family 17
Loading compiled-in X.509 certificates
hctosys: unable to open rtc device (rtc0)
dm9000 88000000.ethernet eth0: link down
dm9000 88000000.ethernet eth0: link down
IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
random: fast init done
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
IP-Config: Complete:
     device=eth0, hwaddr=00:00:de:ad:be:ef, ipaddr=192.168.0.20, mask=255.255.255.0, gw=192.168.0.1
     host=192.168.0.20, domain=, nis-domain=(none)
     bootserver=192.168.0.101, rootserver=192.168.0.101, rootpath=
dm9000 88000000.ethernet eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
VFS: Mounted root (nfs filesystem) readonly on device 0:12.
devtmpfs: mounted
Freeing unused kernel memory: 1024K
Run /linuxrc as init process

Please press Enter to activate this console. 
[root@linux]/# 
[root@linux]/# 

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页