编译uboot时遇到问题:/home/book/test/u-boot-2012.04.01/include/asm/io.h:79: multiple definition of `__raw_writesb'
很明显是多个文件包含同一个头文件io.h导致的,在编译器连接时,会将工程中所有的符号整合在一起,由于文件中有重名变量,于是就出现了重复定义的错误。
查看io.h文件:vim /home/book/test/u-boot-2012.04.01/include/asm/io.h,发现存在编译条件设置
#ifndef __ASM_ARM_IO_H
#define __ASM_ARM_IO_H
......
#endif /* __ASM_ARM_IO_H */
不是这个问题。那问题出在哪儿?
查看代码,发现在io.h文件中定义了几个变量(extern inline void __raw_writesb ...),而这个.h文件被多个文件包含,链接时就造成重复定义错误。
解决办法:
1、修改io.h文件:
注释掉下面几个变量定义
extern inline void __raw_writesb(unsigned int addr, const void *data, int bytelen)
{
uint8_t *buf = (uint8_t *)data;
while(bytelen--)
__arch_putb(*buf++, addr);
}
extern inline void __raw_writesw(unsigned int addr, const void *data, int wordlen)
{
uint16_t *buf = (uint16_t *)data;
while(wordlen--)
__arch_putw(*buf++, addr);
}
extern inline void __raw_writesl(unsigned int addr, const void *data, int longlen)
{
uint32_t *buf = (uint32_t *)data;
while(longlen--)
__arch_putl(*buf++, addr);
}
extern inline void __raw_readsb(unsigned int addr, void *data, int bytelen)
{
uint8_t *buf = (uint8_t *)data;
while(bytelen--)
*buf++ = __arch_getb(addr);
}
extern inline void __raw_readsw(unsigned int addr, void *data, int wordlen)
{
uint16_t *buf = (uint16_t *)data;
while(wordlen--)
*buf++ = __arch_getw(addr);
}
extern inline void __raw_readsl(unsigned int addr, void *data, int longlen)
{
uint32_t *buf = (uint32_t *)data;
while(longlen--)
*buf++ = __arch_getl(addr);
}
添加变量声明:
extern void __raw_writesb(unsigned int addr, const void *data, int bytelen);
extern void __raw_writesw(unsigned int addr, const void *data, int wordlen);
extern void __raw_writesl(unsigned int addr, const void *data, int longlen);
extern void __raw_readsb(unsigned int addr, void *data, int bytelen);
extern void __raw_readsw(unsigned int addr, void *data, int wordlen);
extern void __raw_readsl(unsigned int addr, void *data, int longlen);
2、在/home/book/test/u-boot-2012.04.01/arch/arm/cpu/arm920t/s3c24x0/目录下创建io.c文件,将注释掉的变量在io.c文件中定义
/* * (C) Copyright 2020 Wang Chuanbing */
#include <common.h>
#include <asm/io.h>
#include <asm/arch/s3c24x0_cpu.h>
void __raw_writesb(unsigned int addr, const void *data, int bytelen)
{
uint8_t *buf = (uint8_t *)data;
while(bytelen--)
__arch_putb(*buf++, addr);
}
void __raw_writesw(unsigned int addr, const void *data, int wordlen)
{
uint16_t *buf = (uint16_t *)data;
while(wordlen--)
__arch_putw(*buf++, addr);
}
void __raw_writesl(unsigned int addr, const void *data, int longlen)
{
uint32_t *buf = (uint32_t *)data;
while(longlen--)
__arch_putl(*buf++, addr);
}
void __raw_readsb(unsigned int addr, void *data, int bytelen)
{
uint8_t *buf = (uint8_t *)data;
while(bytelen--)
*buf++ = __arch_getb(addr);
}
void __raw_readsw(unsigned int addr, void *data, int wordlen)
{
uint16_t *buf = (uint16_t *)data;
while(wordlen--)
*buf++ = __arch_getw(addr);
}
void __raw_readsl(unsigned int addr, void *data, int longlen)
{
uint32_t *buf = (uint32_t *)data;
while(longlen--)
*buf++ = __arch_getl(addr);
}
3、添加io.c文件到同一目录下的Makefile文件中
COBJS-$(CONFIG_USE_IRQ) += interrupts.o
COBJS-$(CONFIG_DISPLAY_CPUINFO) += cpu_info.o
COBJS-y += io.o
COBJS-y += speed.o
COBJS-y += timer.o
COBJS-y += usb.o
COBJS-y += usb_ohci.o
重新编译后问题解决