Linux移植总结--Linux中asm和arch的软链接

@

问题

Linux内核中,.c文件引用.h文件的问题让人困惑:

include <asm/aaa.h>实际用的是asm-arm/aaa.h

include <asm/arch/memory.h>实际用的是include/asm-arm/arch-s3c2410/memory.h

原因

网上查找资料,说是对asm、arch、mach建立了软链接,引用的时候就会跳到指定文件夹。

哪里实现的软链接呢?在Makefile中加warning,make uImage时可以在控制台打印信息。

1、顶层Makefile,使asm链接为asm-arm

include/asm:
	@echo '  SYMLINK $@ -> include/asm-$(ARCH)'
	$(Q)if [ ! -d include ]; then mkdir -p include; fi;
	@ln -fsn asm-$(ARCH) $@
$(warning "@@ the value of ARCH is $(ARCH)")

2、arch/arm/Makefile,使arch链接为arch-s3c2410 ,使mach链接为mach-s3c2410

ifeq ($(incdir-y),)
incdir-y := $(machine-y)
endif
INCDIR   := arch-$(incdir-y)
$(warning "@@ the value of arch is $(INCDIR)")

ifneq ($(machine-y),)
MACHINE  := arch/arm/mach-$(machine-y)/
else
MACHINE  :=
endif
$(warning "@@ the value of MACHINE is $(MACHINE)")

打印如下:

/linux/arch/arm/Makefile:150: "@@ the value of arch is arch-smxx"
/linux/arch/arm/Makefile:157: "@@ the value of MACHINE is arch/arm/mach-smxx/"
Makefile:886: "@@ the value of ARCH is arm"

移植注意

我是建立自己的板子目录才遇到这个问题。
arch/arm/Makefile中,我定义自己的板子名字:

machine-$(CONFIG_ARCH_SMXX)	   := smxx  (对标:s3c2410)

这样arch = arch-smxx,MACHINE = arch/arm/mach-smxx/

该Makefile文件有这句话:

core-y				+= $(MACHINE)

就等于

core-y	+= arch/arm/mach-smxx/

我之前还单独加了句core-y += arch/arm/mach-smxx/,结果就会报

target 'arch/arm/mach-smxx' given more than once in the same rule

posted @ 2022-03-02 09:58  solonj  阅读(488)  评论(0编辑  收藏  举报