ref:https://www.cnblogs.com/xiaojiang1025/p/6500532.html


为uboot添加网卡功能可以让uboot通过tftp下载内核, 方便我们的开发, 对于网卡功能的移植,我们依然在在一遍又一遍的实践这个uboot改造的套路。

  1. 找运行逻辑,即插入代码的位置。
  2. 根据运行逻辑编写功能代码。
  3. 找配置逻辑,即修改哪些文件使配置生效。
  4. 根据配置逻辑修改配置使功能代码生效。
  5. 重新编译烧写uboot。

1. 找运行逻辑

为了实现ping、tftp下载、nfs挂载等功能,必须将uboot的网卡功能配置上,这个功能属于板级功能,
README+经验+样板

需要在相应板级目录的xxx.c中配置,所以我们找到了"board/samsung/xboot/xboot.c",这个文件的入口是board_init(),即1.找到了运行逻辑

 24 /*
25 * netdev.h - definitions an prototypes for network devices
26 */
31 /*
32 * Board and CPU-specific initialization functions
33 * board_eth_init() has highest priority. cpu_eth_init() only
34 * gets called if board_eth_init() isn't instantiated or fails.
35 * Return values:
36 * 0: success
37 * -1: failure
38 */
39
40 int board_eth_init(bd_t *bis);
41 int cpu_eth_init(bd_t *bis);
56 int dm9000_initialize(bd_t *bis);
//doc/README.drivers.eth
17 ----------
18 Register
19 ----------
20
21 When U-Boot initializes, it will call the common function eth_initialize().
22 This will in turn call the board-specific board_eth_init() (or if that fails,
23 the cpu-specific cpu_eth_init()). These board-specific functions can do random
24 system handling, but ultimately they will call the driver-specific register
25 function which in turn takes care of initializing that particular instance.
26
27 Keep in mind that you should code the driver to avoid storing state in global
28 data as someone might want to hook up two of the same devices to one board.
29 Any such information that is specific to an interface should be stored in a
30 private, driver-defined data structure and pointed to by eth->priv (see below).
31
32 So the call graph at this stage would look something like:
33 board_init()
34 eth_initialize()
35 board_eth_init() / cpu_eth_init()
36 driver_register()
37 initialize eth_device
38 eth_register()
39

2. 编写功能代码

接下来就需要根据网卡手册进行配置,显然,写的都是裸板代码,这里,我们的dm9000网卡的配置代码如下,此为2.根据运行逻辑编写相应的代码

 31 struct exynos4_gpio_part2 *gpio2;
32 #ifdef CONFIG_DRIVER_DM9000
33 #define EXYNOS4412_SROMC_BASE 0X12570000
34 #define DM9000_Tacs (0x1)
35 #define DM9000_Tcos (0x1)
36 #define DM9000_Tacc (0x5)
37 #define DM9000_Tcoh (0x1)
38 #define DM9000_Tah (0xC)
39 #define DM9000_Tacp (0x9)
40 #define DM9000_PMC (0x1)
41 struct exynos_sromc {
42 unsigned int bw;
43 unsigned int bc[6];
44 };
45 /*
46 * s5p_config_sromc() - select the proper SROMC Bank and configure the
47 * band width control and bank control registers
48 * srom_bank - SROM
49 * srom_bw_conf - SMC Band witdh reg configuration value
50 * srom_bc_conf - SMC Bank Control reg configuration value
51 */
52 void exynos_config_sromc(u32 srom_bank, u32 srom_bw_conf, u32 srom_bc_conf)
53 {
54 unsigned int tmp;
55 struct exynos_sromc *srom = (struct exynos_sromc *)(EXYNOS4412_SROMC_BASE);
56 /* Configure SMC_BW register to handle proper SROMC bank */
57 tmp = srom->bw;
58 tmp&= ~(0xF << (srom_bank * 4));
59 tmp |= srom_bw_conf;
60 srom->bw = tmp;
61 /* Configure SMC_BC register */
62 srom->bc[srom_bank] = srom_bc_conf;
63 }
64 static void dm9000aep_pre_init(void)
65 {
66 unsigned int tmp;
67 unsigned char smc_bank_num = 1;
68 unsigned int
69 smc_bw_conf=0;
70 unsigned int
71 smc_bc_conf=0;
72 /* gpio configuration */
73 writel(0x00220020, 0x11000000 + 0x120);
74 writel(0x00002222, 0x11000000 + 0x140);
75 /* 16 Bit bus width */
76 writel(0x22222222, 0x11000000 + 0x180);
77 writel(0x0000FFFF, 0x11000000 + 0x188);
78 writel(0x22222222, 0x11000000 + 0x1C0);
79 writel(0x0000FFFF, 0x11000000 + 0x1C8);
80 writel(0x22222222, 0x11000000 + 0x1E0);
81 writel(0x0000FFFF, 0x11000000 + 0x1E8);
82 smc_bw_conf &= ~(0xf<<4);
83 smc_bw_conf |= (1<<7) | (1<<6) | (1<<5) | (1<<4);
84 smc_bc_conf = ((DM9000_Tacs << 28)
85 | (DM9000_Tcos << 24)
86 | (DM9000_Tacc << 16)
87 | (DM9000_Tcoh << 12)
88 | (DM9000_Tah << 8)
89 | (DM9000_Tacp << 4)
90 | (DM9000_PMC));
91 exynos_config_sromc(smc_bank_num,smc_bw_conf,smc_bc_conf);
92 }
93 #endif
94
95 int board_init(void)
100         gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
101 #ifdef CONFIG_DRIVER_DM9000
102 dm9000aep_pre_init();
103 #endif
104 return 0;
174 #endif
175 #ifdef CONFIG_CMD_NET
176 int board_eth_init(bd_t *bis)
177 {
178
179 int rc = 0;
180 #ifdef CONFIG_DRIVER_DM9000
181 rc = dm9000_initialize(bis);
182 #endif
183 return rc;
184 }
185 #endif

3. 找配置逻辑

将网卡代码编写好之后,我们来分析uboot的配置逻辑,这部分的大部分内容我已经在一文中进行了介绍,这里仅介绍和网卡相关的配置文件。和通用的配置文件一样,我们首先需要将
在相关配置文件中添加网络支持,一文中已经介绍了uboot的配置原理,make config最后生成的结果文件是"include/configs/xxx.h",里面以宏的形式对板子的功能进行了配置,我们这里需要的文件是"include/configs/xboot.h"
我们只需要打开或关闭相应的宏,就可以完成对某一功能的配置

4. 修改配置

我们主要的工作就是在头文件中打开相应的宏开关,虽然不使用这种宏开关的方式也可以将功能添加成功,但是移植的一个重要原则就是尊重原架构,这对后期维护和代码重用都很有好处。

 85 #define CONFIG_CMD_PING                 //#undef CONFIG_CMD_PING
 90 #define CONFIG_CMD_NET                  //#undef CONFIG_CMD_NET 
155 /* Enable devicetree support */
156 #define CONFIG_OF_LIBFDT
157
158 #ifdef CONFIG_CMD_NET
159 #define CONFIG_NET_MULTI
160 #define CONFIG_DRIVER_DM9000 1
161 #define CONFIG_DM9000_BASE 0x05000000
162 #define DM9000_IO CONFIG_DM9000_BASE
163 #define DM9000_DATA (CONFIG_DM9000_BASE + 4)
164 #define CONFIG_DM9000_USE_16BIT
165 #define CONFIG_DM9000_NO_SROM 1
166 #define CONFIG_ETHADDR 11:22:33:44:55:66
167 #define CONFIG_IPADDR 192.168.9.200
168 #define CONFIG_SERVERIP 192.168.9.120
169 #define CONFIG_GATEWAYIP 192.168.9.1
170 #define CONFIG_NETMASK 255.255.255.0
171 #endif
172
173 #endif /* __CONFIG_H */

5. 重新编译and烧写

最终的结果如下, 我们可以看到dm9000已经启动了

(转)从0移植uboot(六) _实现网络功能的更多相关文章

  1. 从0移植uboot(六) _实现网络功能

    为uboot添加网卡功能可以让uboot通过tftp下载内核, 方便我们的开发, 对于网卡功能的移植,我们依然在在一遍又一遍的实践这个uboot改造的套路. 找运行逻辑,即插入代码的位置. 根据运行逻 ...

  2. 从0移植uboot (二) _启动流程分析

    经过了上一篇的配置,我们已经执行make就可以编译出一个uboot.bin,但这还不够,首先,此时的uboot并不符合三星芯片对bootloader的格式要求,其次,此时的uboot.bin也没有结合 ...

  3. 从0移植uboot(五) _实现串口输出

    串口作为一种非常简单的通信方式,才是嵌入式系统调试的王道,通过设置串口输出,我们可以将程序运行的情况直接通过串口线输出到屏幕上,对于这种异常重要的功能,uboot原生就提供了支持,但为此我们需要做一些 ...

  4. 从0移植uboot(三) _编译最小可用uboot

    前两篇介绍了uboot-2013.01的配置原理以及大体的运行流程,本文将讨论如何对uboot源码进行配置,将一个可用的uboot烧录到SD卡中. 定制自己的core board 市面上能买到的开发板 ...

  5. 从0移植uboot (一) _配置分析

    来源:Linux社区  作者:xiaojiang1025  :http://www.linuxidc.com/Linux/2017-02/141018.htm 和绝大多数源码编译安装一样,uboot的 ...

  6. (转) 从0移植uboot(五) _实现串口输出

    ref : https://www.cnblogs.com/xiaojiang1025/p/6500520.html 串口作为一种非常简单的通信方式,才是嵌入式系统调试的王道,通过设置串口输出,我们可 ...

  7. (转)从0移植uboot(三) _编译最小可用uboot

    ref: https://www.cnblogs.com/xiaojiang1025/p/6436752.html 前两篇介绍了uboot-2013.01的配置原理以及大体的运行流程,本文将讨论如何对 ...

  8. (转)从0移植uboot (一) _配置分析

    ref : https://www.cnblogs.com/xiaojiang1025/p/6106431.html 本人建议的uboot学习路线,先分析原有配置,根据现有的配置修改.增加有关的部分, ...

  9. 从0移植uboot (四) _点亮调试LED

    这一节主要讨论1个问题:点灯.点灯是实际开发中,特别是裸板开发中常见的调试手段,相当于主机开发中漫天飞舞的printf/printk.为了追踪程序的现场执行情况,很多时候我们都使用点一个灯的方法来进行 ...

随机推荐

  1. Tcl模块化

    Proc 过程名 参数列表 过程体 示例代码(斐波那契数列): proc fib {num} { if {$num<=2} {return 1} return [expr [fib [expr ...

  2. uiautomator代码例子--java

    在androidtest下创建文件Ui2Test.java package com.example.myapplication; import android.app.Instrumentation; ...

  3. SpringBoot-自动装配对象及源码ImportSelector分析

    SpringBoot框架已经很流行了,笔者做项目也一直在用,使用久了,越来越觉得有必要理解SpringBoot框架中的一些原理了,目前的面试几乎都会用问到底层原理.我们在使用过程中基本上是搭建有一个框 ...

  4. Django 测试开发4 Django 模板和分页器

    Django结合前端框架Bootstrap来开发web页面.pip install django-bootstrap3 在setting.py添加‘bootstrap3’. 继承模板. 在base页面 ...

  5. vuecli3集成easyui

    思路是这样的,首先要将jquery设置成全局,然后就可以正常使用easyUI了. jquery安装命令: npm install --save jquery jquery-easyui安装命令: np ...

  6. Vue引入远程JS文件

    问题 最近在使用 Vue 做东西,用到钉钉扫描登录的功能,这里需要引入远程的 js 文件,因为 Vue 的方式跟之前的不太一样,又不想把文件下载到本地应用,找了一下解决的方法,貌似都需要引入第三方的库 ...

  7. MediaPlayer: MediaPlayer中的prepare方法和prepareAsync方法的区别

    prepare方法是将资源同步缓存到内存中,一般加载本地较小的资源可以用这个,如果是较大的资源或者网络资源建议使用prepareAsync方法,异步加载.但如果想让资源启动,即start()起来,因为 ...

  8. 浅谈TextView Ellipsize效果与Marquee跑马灯无效果问题

    说到TextView 效果,相信大家一定熟悉跑马灯. 先来看看 Ellipsize是什么,Ellipsize 从开发技术上翻译为省略效果.故名思议,就是当文本无法显示全部时,用什么效果来显示未显示的部 ...

  9. $createElement实现自定义弹窗

    <el-button type="text" @click="open4">点击打开 Message Box</el-button> m ...

  10. Git<一> 手工编辑冲突

    一:背景 Neo君之前在写东西时,都是自己负责各自的模块,没有出现代码拉下来冲突的情况.最近Neo君在搞一搞前端的东东,跟同事功能有些冲突,所以就难免会冲突. 所以简单总结下,这次针对的情况是不同的用 ...