mkimage 时报错invalid entry point -n

本文介绍了一个在Ubuntu 14.04上编译内核时遇到的invalidentrypoint-n错误,并详细分析了该错误产生的原因及解决方法。通过对比Ubuntu 12.04与14.04的不同之处,最终发现是因为readelf输出的Entry字段被汉化导致的问题。

在最后阶段出现了"invalid entry point -n"的错误,而我在ubuntu12.04上面是可以生成镜像的。以下是出错现场的信息



LZMA 4.57  Copyright (c) 1999-2007 Igor Pavlov  2007-12-06
echo Making uImage...
Making uImage...
cd util && mkuImage.sh /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../boot/u-boot/tools /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../linux/kernels/mips-linux-2.6.31 _mi124_f1e lzma
+ MKIMAGE=/home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../boot/u-boot/tools/mkimage
+ VMLINUX=/home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../linux/kernels/mips-linux-2.6.31/vmlinux
+ VMLINUXBIN=/home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../linux/kernels/mips-linux-2.6.31/arch/mips/boot/vmlinux.bin
+ '[' -z /tftpboot/zhangdanfeng ']'
+ echo /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../build/util/mkuImage.sh Using TFTPPATH=/tftpboot/zhangdanfeng
/home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../build/util/mkuImage.sh Using TFTPPATH=/tftpboot/zhangdanfeng
++ grep Entry
++ readelf -a /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../linux/kernels/mips-linux-2.6.31/vmlinux
++ head -1
++ cut -d: -f 2
+ ENTRY=
++ grep '\[ 1\]'
++ readelf -a /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../linux/kernels/mips-linux-2.6.31/vmlinux
++ head -1
++ cut '-d ' -f 26
+ LDADDR=80002000
+ '[' 4 -gt 3 ']'
+ suffix=_mi124_f1e
+ '[' xxlzma = xxlzma -o xx_mi124_f1e = xxlzma ']'
+ echo '**** Generating vmlinux_mi124_f1e.lzma.uImage ********'
**** Generating vmlinux_mi124_f1e.lzma.uImage ********
+ /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../boot/u-boot/tools/mkimage -A mips -O linux -T kernel -C lzma -a 0x80002000 -e -n 'Linux Kernel Image' -d /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../linux/kernels/mips-linux-2.6.31/arch/mips/boot/vmlinux.bin.lzma /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../images/mi124/vmlinux_mi124_f1e.lzma.uImage
/home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../boot/u-boot/tools/mkimage: invalid entry point -n
+ cp /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../images/mi124/vmlinux_mi124_f1e.lzma.uImage /tftpboot/zhangdanfeng
cp: 无法获取'/home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../images/mi124/vmlinux_mi124_f1e.lzma.uImage' 的文件状态(stat): 没有那个文件或目录


后来我将*argv全部打印出来发现:在ubuntu12.04下,Makefile文件中执行的语句展开后是

/home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../boot/u-boot/tools/mkimage -A mips -O linux -T kernel -C lzma -a 0x80002000 -e -n 'Linux Kernel Image' -d /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../linux/kernels/mips-linux-2.6.31/arch/mips/boot/vmlinux.bin.lzma /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../images/mi124/vmlinux_mi124_f1e.lzma.uImage

argc的值是18,第12个参数“-e”后面紧接着的是代表入口地址的16进制参数;

但是在ubuntu14.04下,Makefile文件中执行的语句展开后是

**** Generating vmlinux_mi124_f1e.lzma.uImage ********
+ /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../boot/u-boot/tools/mkimage -A mips -O linux -T kernel -C lzma -a 0x80002000 -e -n 'Linux Kernel Image' -d /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../linux/kernels/mips-linux-2.6.31/arch/mips/boot/vmlinux.bin.lzma /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../images/mi124/vmlinux_mi124_f1e.lzma.uImage
/home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../boot/u-boot/tools/mkimage: invalid entry point -n
+ cp /home/zhangdanfeng/work/gaoju/rc_9342_wifi/sdk/build/../images/mi124/vmlinux_mi124_f1e.lzma.uImage /tftpboot/zhangdanfeng

argc的值是17,正是“-e”参数后缺少了入口地址参数,而紧接着“-n”。所以程序就报告了“ nvalid entry point -n”,但是为何会缺少一个参数?

答案就在Makefile里面找。Makefile中通过$(shell readelf -h $(ROOTDIR)/$(LINUXDIR)/vmlinux | grep "Entry" | awk '{print $$4}') 查找入口点地址,但是我们在ubuntu14.04中readelf文件vmlinux才发现Entry竟然被汉化成了“入口点地址”,所以grep Entry肯定找不到啦。最后把“Entry”改成“入口点地址”,再把$$4改成$$2就可以完成编译了。

这种问题着实让人哭笑不得,看来做开发的系统最好还是别汉化。开发中出现疑难异常问题的时候也可以从系统的语言环境考虑下。

--- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -37,6 +37,7 @@ struct mkimage_params params = { .arch = IH_ARCH_PPC, .type = IH_TYPE_KERNEL, .comp = IH_COMP_GZIP, + .magic = IH_MAGIC, .dtc = MKIMAGE_DEFAULT_DTC_OPTIONS, .imagename = "", }; @@ -186,6 +187,16 @@ main (int argc, char **argv) genimg_get_comp_id (*++argv)) < 0) usage (); goto NXTARG; + case 'M': + if (--argc <=0) + usage (); + params.magic = strtoul (*++argv, &ptr, 16); + if (*ptr) { + fprintf (stderr, + "%s: invalid magic %s\n", + params.cmdname, *argv); + } + goto NXTARG; case 'D': if (--argc <= 0) usage (); @@ -596,12 +607,13 @@ usage () fprintf (stderr, "Usage: %s -l image\n" " -l ==> list image header information\n", params.cmdname); - fprintf (stderr, " %s [-x] -A arch -O os -T type -C comp " + fprintf (stderr, " %s [-x] -A arch -O os -T type -C comp -M magic " "-a addr -e ep -n name -d data_file[:data_file...] image\n" " -A ==> set architecture to 'arch'\n" " -O ==> set operating system to 'os'\n" " -T ==> set image type to 'type'\n" " -C ==> set compression type 'comp'\n" + " -M ==> set image magic to 'magic'\n" " -a ==> set load address to 'addr' (hex)\n" " -e ==> set entry point to 'ep' (hex)\n" " -n ==> set image name to 'name'\n" --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -65,6 +65,7 @@ struct mkimage_params { int arch; int type; int comp; + unsigned int magic; char *dtc; unsigned int addr; unsigned int ep; --- a/tools/default_image.c +++ b/tools/default_image.c @@ -111,7 +111,7 @@ static void image_set_header(void *ptr, sbuf->st_size - sizeof(image_header_t)); /* Build new header */ - image_set_magic(hdr, IH_MAGIC); + image_set_magic(hdr, params->magic); image_set_time(hdr, sbuf->st_mtime); image_set_size(hdr, sbuf->st_size - sizeof(image_header_t)); image_set_load(hdr, params->addr); 他修改的文件在哪
最新发布
11-11
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

武溪嵌人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值