openwrt作为一个基于linux开发的比较完善的嵌入式系统,可以快速移植到各种平台上。初次下载开源代码后,简单浏览后很是诧异,居然没看到uboot和kernel部分的代码,甚至没看到任何模块的代码,最多只是些patch和配置文件。
按照文档编译后,发现多了些工程目录,进而发现了很多源码,猜测到大概是Makefile或feed脚本在编译时在线下载的代码。为了后来者,初次入门openwrt少踩坑,完成此章,内容多为我入门的困惑与解答。
1. uboot和kernel在哪里?
事实上,拿到marvell release代码后会看到:
$ tree -L 1 marvell/
marvell/
├── fastpath
├── fota
├── linux
├── lte-telephony
├── obm
├── services
├── swd
├── uboot
└── webui
这些明显是marvell自己定制过的一些代码包,针对这个平台算是找到了正确的代码位置,但我们并不了解这个过程,并且开源代码部分是没有这种结构的,所以我们要继续探究下去,提出问题:
- 官方release的openwrt没有定制的情况下uboot和kernel在哪?
- marvell这种定制是如何实现的?
在目录结构和功能不了解的情况下会感觉无从下手而四处乱摸,通过上一章了解了目录结构,很自然的就会想到package
目录,进去看看:
$ cd package
$ tree -L 1 boot
boot/
├── uboot-mvebu
├── uboot-mxs
├── uboot-omap
├── uboot-oxnas
├── ...
└── yamonenv
最终发现,package/boot/uboot-mmp/
:
$ cat package/boot/uboot-mmp/Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=u-boot
PKG_VERSION:=2014
PKG_RELEASE:=1
USE_SOURCE_DIR:=$(MRVLDIR)/uboot
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
include $(INCLUDE_DIR)/package.mk
这里面看到了’MRVLDIR’,查询后发现MRVLDIR:=$(TOPDIR)/marvell
,
$ ls -l build_dir/target-arm_cortex-a7+neon-vfpv4_uClibc-1.0.25_eabi/u-boot-nezha3_dkb/
total 0
lrwxrwxrwx 1 tjd tjd 56 May 15 15:56 u-boot-2014 -> /home/tjd/datadisk/marvell/OpenWrt/openwrt/marvell/uboot
确认无疑了!!
package/boot/uboot-mmp/
就是marvell的uboot定义的位置,变量USE_SOURCE_DIR
指定了uboot使用的源码。
知道了marvell定制uboot源码的方法,再看一下官方release版本的uboot,已Beaglebone black板项目为例:
$ cat package/boot/uboot-omap/Makefile
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_VERSION:=2017.01
PKG_RELEASE:=2
PKG_HASH:=6c425175f93a4bcf2ec9faf5658ef279633dbd7856a293d95bd1ff516528ecf2
include $(INCLUDE_DIR)/u-boot.mk
include $(INCLUDE_DIR)/package.mk
define U-Boot/Default
BUILD_TARGET:=omap
UBOOT_IMAGE:=u-boot.img MLO
UENV:=default
endef
define U-Boot/omap4_panda
NAME:=Pandaboard
BUILD_DEVICES:=omap4-panda
endef
define U-Boot/am335x_boneblack
NAME:=TI AM335x BeagleBone Black
BUILD_DEVICES:=am335x-boneblack
endef
...
很遗憾,这里没有USE_SOURCE_DIR
指定源码位置,只是指定了使用的uboot的版本号,目录中也没有源码:
package/boot/uboot-omap/
├── files
│ └── uEnv-default.txt
├── Makefile
└── patches
├── 101-disable-thumb-omap3.patch
├── 102-minify-spl.patch
├── 103-disable-fat-write-spl.patch
├── 104-omap3-overo-enable-thumb.patch
└── 105-serial-ns16550-bugfix-ns16550-fifo-not-enabled.patch
2 directories, 7 files
这里保存了针对bbb的uboot相关patch,联想到与硬件相关的内容是以patch存在的,u-boot应该是官方发布的原版代码,上一章提到了dl
目录保存了从网络上下载的代码包,编译时会解压源码包到build_dir
中,现在看一下:
$ ls build_dir/target-arm_cortex-a8+vfpv3_musl_eabi/u-boot-am335x_boneblack/u-boot-2017.01/
api cmd configs drivers fs Kconfig MAINTAINERS MLO.byteswap README spl tools u-boot.cfg u-boot.lds u-boot.srec
arch common disk dts include lib Makefile net scripts System.map u-boot u-boot.cfg.configs u-boot.map u-boot.sym
board config.mk doc examples Kbuild Licenses MLO post snapshot.commit test u-boot.bin u-boot.img u-boot-nodtb.bin
前面看到package/boot/uboot-omap/
中有patch,是不是已经合入了呢? 对比看看:
$ cat package/boot/uboot-omap/patches/101-disable-thumb-omap3.patch
Index: u-boot-2017.01/include/configs/ti_omap3_common.h
===================================================================
--- u-boot-2017.01.orig/include/configs/ti_omap3_common.h
+++ u-boot-2017.01/include/configs/ti_omap3_common.h
@@ -80,4 +80,9 @@
/* Now bring in the rest of the common code. */
#include <configs/ti_armv7_omap.h>
+/* beagleboard doesnt boot with thumb */
+#ifdef CONFIG_SYS_THUMB_BUILD
+#undef CONFIG_SYS_THUMB_BUILD
+#endif
+
#endif /* __CONFIG_TI_OMAP3_COMMON_H__ */
$ diff dl/u-boot-2017.01_unpack/include/configs/ti_omap3_common.h build_dir/target-arm_cortex-a8+vfpv3_musl_eabi/u-boot-am335x_boneblack/u-boot-2017.01/include/configs/ti_omap3_common.h
82a83,87
> /* beagleboard doesnt boot with thumb */
> #ifdef CONFIG_SYS_THUMB_BUILD
> #undef CONFIG_SYS_THUMB_BUILD
> #endif
看来patch是已经打上去了。
- 官方的uboot先解压到
build_dir
中,再打上package/boot/uboot-xxx/patches
中的patch,再编译。- marvell通过变量
USE_SOURCE_D