osx 下编译 rk3399 openwrt 记录

2 篇文章 0 订阅
2 篇文章 0 订阅

最新的 openwrt 已经支持 rockchip

但在 macos 下编译时,有错误:

__u64 未定义

In file included from include/linux/byteorder/little_endian.h:14:
include/linux/byteorder/swab.h:135:41: error: unknown type name '__u64'; did you mean '__s64'?
static __inline__ __u64 __swab64p(const __u64 *x)
                                        ^
/Volumes/works/openwrt_trunk/staging_dir/host/include/asm/types.h:19:44: note: '__s64' declared here
__extension__ typedef __signed__ long long __s64;

修改:openwrt_trunk/staging_dir/host/include/asm/types.h

#ifdef __GNUC__
// add by manfeel
__extension__ typedef unsigned long long __u64;
__extension__ typedef __signed__ long long __s64;
#else

单独运行:make package/boot/uboot-rockchip/compile V=s
又出现新的错误:

/bin/sh: line 1: 69638 Segmentation fault: 11

  CFGCHK  u-boot.cfg
./"arch/arm/mach-rockchip/make_fit_atf.py" \
arch/arm/dts/rk3399-nanopi-r4s.dtb > u-boot.its
  COPY    u-boot.bin
  MKIMAGE u-boot.img
/bin/sh: line 1: 69638 Segmentation fault: 11  ./tools/mkimage -f auto -A arm -T firmware -C none -O u-boot -a 0x00200000 -e 0x00200000 -p 0x0 -n "U-Boot 2021.07""-OpenWrt-r19352-d7eba8059b for evb_rk3399 board" -E -b arch/arm/dts/rk3399-nanopi-r4s.dtb -d u-boot-nodtb.bin u-boot.img > /dev/null
make[3]: *** [Makefile:1423: u-boot.img] Error 139
make[3]: Leaving directory '/Volumes/works/openwrt_trunk/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r4s-rk3399/u-boot-2021.07'
make[2]: *** [Makefile:110: /Volumes/works/openwrt_trunk/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r4s-rk3399/u-boot-2021.07/.built] Error 2
make[2]: Leaving directory '/Volumes/works/openwrt_trunk/package/boot/uboot-rockchip'
time: package/boot/uboot-rockchip/nanopi-r4s-rk3399/compile#2.15#1.66#16.04
    ERROR: package/boot/uboot-rockchip failed to build (build variant: nanopi-r4s-rk3399).

就是在执行:./tools/mkimage -f auto -A arm -T firmware -C none -O u-boot -a 0x00200000 -e 0x00200000 -p 0x0 -n "U-Boot 2021.07""-OpenWrt-r19352-d7eba8059b for evb_rk3399 board" -E -b arch/arm/dts/rk3399-nanopi-r4s.dtb -d u-boot-nodtb.bin u-boot.img > /dev/null
的时候出现的 segfault!
奇怪的是,进入目录:~/works/openwrt_trunk/build_dir/target-aarch64_generic_musl/u-boot-nanopi-r4s-rk3399/u-boot-2021.07
单独执行:./tools/mkimage是可以执行的,说明命令本身没有问题,难道是部分参数导致的
进入:~/Library/Logs/DiagnosticReports/目录,找到对应的crash文件,分析内容:

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000100031978
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [53288]

VM Regions Near 0x100031978:
--> 
    __TEXT                 000000010d9c3000-000000010d9ef000 [  176K] r-x/r-x SM=COW  /Volumes/VOLUME/*

Application Specific Information:
dyld2 mode

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   mkimage                           0x000000010d9cd609 imagetool_get_type + 105

imagetool_get_type函数的问题?

struct image_type_params *imagetool_get_type(int type)
{
    struct image_type_params **curr;
    INIT_SECTION(image_type);
    struct image_type_params **start = __start_image_type;
    struct image_type_params **end = __stop_image_type;

    for (curr = start; curr != end; curr++) {
        if ((*curr)->check_image_type) {
            if (!(*curr)->check_image_type(type))
                return *curr;
        }
    }
    return NULL;
}

相关文件加入诊断信息,继续单独编译:make package/boot/uboot-rockchip/compile V=s
发现start和end分别指向:start = 0x100031978, end = 0x100031a40
通过IDA反编译mkimage:

image_type:0000000100031978 ; ===========================================================================
image_type:0000000100031978
image_type:0000000100031978 ; Segment type: Regular
image_type:0000000100031978 ; Segment permissions: Read/Write
image_type:0000000100031978 image_type      segment qword public '' use64
image_type:0000000100031978                 assume cs:image_type
image_type:0000000100031978                 ;org 100031978h
image_type:0000000100031978                 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
image_type:0000000100031978 _image_type_ptr_aisimage dq offset _image_type_aisimage
image_type:0000000100031980 _image_type_ptr_atmelimage dq offset _image_type_atmelimage
image_type:0000000100031988 _image_type_ptr_fitimage dq offset _image_type_fitimage
image_type:0000000100031990 _image_type_ptr_defimage dq offset _image_type_defimage
image_type:0000000100031998 _image_type_ptr_imximage dq offset _image_type_imximage
image_type:00000001000319A0 _image_type_ptr_imx8image dq offset _image_type_imx8image
image_type:00000001000319A8 _image_type_ptr_imx8mimage dq offset _image_type_imx8mimage
image_type:00000001000319B0 _image_type_ptr_kwbimage dq offset _image_type_kwbimage
image_type:00000001000319B8 _image_type_ptr_lpc32xximage dq offset _image_type_lpc32xximage
image_type:00000001000319C0 _image_type_ptr_omapimage dq offset _image_type_omapimage
image_type:00000001000319C8 _image_type_ptr_pblimage dq offset _image_type_pblimage
image_type:00000001000319D0 _image_type_ptr_vybridimage dq offset _image_type_vybridimage
image_type:00000001000319D8 _image_type_ptr_stm32image dq offset _image_type_stm32image
image_type:00000001000319E0 _image_type_ptr_rkimage dq offset _image_type_rkimage
image_type:00000001000319E8 _image_type_ptr_rksd dq offset _image_type_rksd
image_type:00000001000319F0 _image_type_ptr_rkspi dq offset _image_type_rkspi
image_type:00000001000319F8 _image_type_ptr_socfpgaimage dq offset _image_type_socfpgaimage
image_type:0000000100031A00 _image_type_ptr_socfpgaimage_v1 dq offset _image_type_socfpgaimage_v1
image_type:0000000100031A08 _image_type_ptr_sunxi_egon dq offset _image_type_sunxi_egon
image_type:0000000100031A10 _image_type_ptr_ublimage dq offset _image_type_ublimage
image_type:0000000100031A18 _image_type_ptr_zynqimage dq offset _image_type_zynqimage
image_type:0000000100031A20 _image_type_ptr_zynqmpimage dq offset _image_type_zynqmpimage
image_type:0000000100031A28 _image_type_ptr_zynqmpbif dq offset _image_type_zynqmpbif
image_type:0000000100031A30 _image_type_ptr_gpimage dq offset _image_type_gpimage
image_type:0000000100031A38 _image_type_ptr_mtk_image dq offset _image_type_mtk_image
image_type:0000000100031A38 image_type      ends
image_type:0000000100031A38
__bss:0000000100031A40 ; ===========================================================================

只要读取到这个区域,就发生segfault!

问题多半出在section的处理上

但是,这个地址上的代码https://stackoverflow.com/questions/17669593/how-to-get-a-pointer-to-a-binary-section-in-mac-os-x
是可以成功编译和运行的:

#include <stdio.h>

extern int start_mysection __asm("section$start$__DATA$__mysection");
extern int stop_mysection  __asm("section$end$__DATA$__mysection");

// If you don't reference x, y and z explicitly, they'll be dead-stripped.
// Prevent that with the "used" attribute.
static int x __attribute__((used,section("__DATA,__mysection"))) = 4;
static int y __attribute__((used,section("__DATA,__mysection"))) = 10;
static int z __attribute__((used,section("__DATA,__mysection"))) = 22;

int main(void)
{
    long sz = &stop_mysection - &start_mysection;
    long i;

    printf("Section size is %ld\n", sz);

    for (i=0; i < sz; ++i) {
        printf("%d\n", (&start_mysection)[i]);
    }

    return 0;
}

最后确定就是INIT_SECTION宏的问题!

修改如下:
imagetool.h(注意:section的起始指针只有一个*,非常重要!)
取消 INIT_SECTION的宏定义,用 __asm("section$start$__DATA$image_type") 来获取!

#if defined(__MACH__)
#define INIT_SECTION(name)
#define SECTION(name)   __attribute__((used,section("__DATA," #name)))
extern struct image_type_params* __start_image_type __asm("section$start$__DATA$image_type");
extern struct image_type_params* __stop_image_type __asm("section$end$__DATA$image_type");
#else

imagetool.c所有 __start_image_type 和 __stop_image_type 前面加上&

    struct image_type_params **start = &__start_image_type;
    struct image_type_params **end = &__stop_image_type;

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值