移植交换芯片SDK到Linux系统
2010-05-20 15:47
204 查看
需求:
把88E6131交换芯片的sdk移植到现有嵌入式linux系统中,使得以后能通过上层函数在对交换芯片进行配置操作(如lan配置)。
已知条件:
*有交换芯片的文档,sdk源码,例子,无针对现有系统的直接解决方案.
实现方法概述:
* 编译SDK之后会生成一个qdDriver.o文件。
* 自己写一个main函数,gcc的时候把这个.o文件也作为编译目标之一。最后编译出来的就是一个link了main函数与sdk的目标文件。
* 这个目标文件跑在Linux的用户层。软件工程师要在这里面实现2个接口(mii_read/mii_write)。这样用户层的SDK就能对硬件寄存器进行操作了。
对接口的实现方法:
在内核层面,利用linux的
device_attr (),在文件系统中增加设备属性。
让内核加载交换芯片驱动时生成设备属性文件:
编译内核之后,操作系统的/sys/device/2:10/reg_io即为增加的设备属性文件。
可对此文件可进行读写操作,以达到读写交换芯片寄存器的作用。
在用户层面,写两个函数来对上面的设备属性文件进行读写操作,把这两个函数作为mii接口,编译到SDK中即可。
附录:对88E6131的SDK代码移植的步骤具体注意事项
<!--@page { size: 8.5in 11in; margin: 0.79in }P { margin-bottom: 0.08in }-->
Build qdDrv.o for Linux
-----------------------------------
1. Extract the given ZIP file into$HOME/DSDT_2.x directory(directory can be changed)
in Linux system (verified with RedHat7.3)
2. Edit setenv file in$HOME/DSDT_2.x/tools
3. Modify the following variablesaccording to your setup.
declare -x USER_BASE=$HOME/DSDT_2.x
declare -x PROJ_NAME=qdDrv
4. run "source setenv"
5. Change directory to$HOME/DSDT_2.x/src
6. run "make"
qdDrv.o and qdDrv.map will becreated in $HOME/DSDT_2.x/Library.
PRACTICE NOTE:
following above is not enough tomake compilation success. You need to do following things:
make sure that /bin/sh is pointingto /bin/bash
the commands in ./tools/setenvdoesn't really set global environment, so need to port it insrc/makefile manually
need to specify the platformCompiler and Linker as shown below:
make -C srcCC="$(OPENWRT_DIR)/staging_dir/toolchain-mips_gcc4.1.2/bin/mips-linux-uclibc-gcc"LD="$(OPENWRT_DIR)/staging_dir/toolchain-mips_gcc4.1.2/bin/mips-linux-uclibc-ld"
DSDT_2.8b/tools/makelnx.defs maynot using the correct -march parameters.
So after changes of following files,build can be successful:
build_dir/mips/cpe_mgmt-CPE_MGMT-B001/DSDT_2.8b/src/makefile
build_dir/mips/cpe_mgmt-CPE_MGMT-B001/DSDT_2.8b/Makefile
build_dir/mips/cpe_mgmt-CPE_MGMT-B001/DSDT_2.8b/tools/makelnx.defs
build_dir/mips/cpe_mgmt-CPE_MGMT-B001/DSDT_2.8b/sample/mskefile
把88E6131交换芯片的sdk移植到现有嵌入式linux系统中,使得以后能通过上层函数在对交换芯片进行配置操作(如lan配置)。
已知条件:
*有交换芯片的文档,sdk源码,例子,无针对现有系统的直接解决方案.
实现方法概述:
* 编译SDK之后会生成一个qdDriver.o文件。
* 自己写一个main函数,gcc的时候把这个.o文件也作为编译目标之一。最后编译出来的就是一个link了main函数与sdk的目标文件。
* 这个目标文件跑在Linux的用户层。软件工程师要在这里面实现2个接口(mii_read/mii_write)。这样用户层的SDK就能对硬件寄存器进行操作了。
对接口的实现方法:
在内核层面,利用linux的
device_attr (),在文件系统中增加设备属性。
利用linux 的 device_attr (),在文件系统中增加设备属性。 static ssize_t sysfs_reg_io(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct phy_device *phydev = to_phy_device(dev); struct mii_bus *bus = phydev->bus; reg_io_mode_t mode = REG_IO_MODE_UNKNOWN; int busaddr = 0; u16 regnum = 0; u16 val = 0; int result = -1; //validate input command format if((buf[0] == 'R' || buf[0] == 'r') && (buf[11] == '/n' || buf[11] == '/0')) { mode = REG_IO_MODE_READ; } else if ((buf[0] == 'W' || buf[0] == 'w') && (buf[18] == '/n' || buf[18] == '/0')) { mode = REG_IO_MODE_WRITE; } else { return result; } busaddr = (int)((char2hex(buf[4]) << 4) + char2hex(buf[5])); regnum = (u16)((char2hex(buf[9]) << 4) + char2hex(buf[10])); if(mode == REG_IO_MODE_READ){ result = mii_bus_read(bus, busaddr, regnum); } else if(mode == REG_IO_MODE_WRITE){ val = (u16)((char2hex(buf[14]) << 12) + (char2hex(buf[15]) << 8) + (char2hex(buf[16]) << 4) + char2hex(buf[17])); result = mii_bus_write(bus, busaddr, regnum, val); } return result; } static DEVICE_ATTR(reg_io, S_IWUSR | S_IRUSR, sysfs_reg_io_help, sysfs_reg_io);
让内核加载交换芯片驱动时生成设备属性文件:
static int mv_common_init(struct phy_device *phydev) { ... err |= device_create_file(&phydev->dev, &dev_attr_reg_io); ... }
编译内核之后,操作系统的/sys/device/2:10/reg_io即为增加的设备属性文件。
可对此文件可进行读写操作,以达到读写交换芯片寄存器的作用。
在用户层面,写两个函数来对上面的设备属性文件进行读写操作,把这两个函数作为mii接口,编译到SDK中即可。
附录:对88E6131的SDK代码移植的步骤具体注意事项
<!--@page { size: 8.5in 11in; margin: 0.79in }P { margin-bottom: 0.08in }-->
Build qdDrv.o for Linux
-----------------------------------
1. Extract the given ZIP file into$HOME/DSDT_2.x directory(directory can be changed)
in Linux system (verified with RedHat7.3)
2. Edit setenv file in$HOME/DSDT_2.x/tools
3. Modify the following variablesaccording to your setup.
declare -x USER_BASE=$HOME/DSDT_2.x
declare -x PROJ_NAME=qdDrv
4. run "source setenv"
5. Change directory to$HOME/DSDT_2.x/src
6. run "make"
qdDrv.o and qdDrv.map will becreated in $HOME/DSDT_2.x/Library.
PRACTICE NOTE:
following above is not enough tomake compilation success. You need to do following things:
make sure that /bin/sh is pointingto /bin/bash
the commands in ./tools/setenvdoesn't really set global environment, so need to port it insrc/makefile manually
need to specify the platformCompiler and Linker as shown below:
make -C srcCC="$(OPENWRT_DIR)/staging_dir/toolchain-mips_gcc4.1.2/bin/mips-linux-uclibc-gcc"LD="$(OPENWRT_DIR)/staging_dir/toolchain-mips_gcc4.1.2/bin/mips-linux-uclibc-ld"
DSDT_2.8b/tools/makelnx.defs maynot using the correct -march parameters.
So after changes of following files,build can be successful:
build_dir/mips/cpe_mgmt-CPE_MGMT-B001/DSDT_2.8b/src/makefile
build_dir/mips/cpe_mgmt-CPE_MGMT-B001/DSDT_2.8b/Makefile
build_dir/mips/cpe_mgmt-CPE_MGMT-B001/DSDT_2.8b/tools/makelnx.defs
build_dir/mips/cpe_mgmt-CPE_MGMT-B001/DSDT_2.8b/sample/mskefile
相关文章推荐
- atheros 8328交换芯片 在SDK_10.5.13上面的移植
- Mavell 8686无线芯片在 Linux 系统移植
- Linux内核移植过程之根文件系统
- 大话运动DV产品系统设计 - 基于芯片商提供的SDK API开发之一
- qt移植到OK6410开发板linux系统过程
- Linux3.4.0 Yaffs2文件系统移植-支持Android4.0
- linux 内核移植和根文件系统的制作
- 基于XIP技术的ARM Linux系统的研究与移植
- linux系统移植 书
- 基于S3C2440的Linux内核移植和yaffs2文件系统制作
- 将 Linux 应用程序移植到 64 位系统上
- 在XP下做linux嵌入式系统移植 AT91SAM9260
- Linux系统移植——initramfs根文件系统格式操作
- 移植minicom到嵌入式linux系统
- u-boot,linux,文件系统移植笔记1
- 基于ARM11的嵌入式linux系统移植与实现--笔记三
- 移植linux2.6.29内核+yaffs2文件系统过程
- linux 内核移植和根文件系统的制作
- 【转载】移植多款轻量级 Web服务器到ARM-Linux系统
- Linux芯片级移植与底层驱动(基于3.7.4内核) --SMP多核启动以及CPU热插拔驱动