您的位置:首页 > 运维架构 > Linux

移植交换芯片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 (),在文件系统中增加设备属性。
利用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: