カーネルはバイナリを実行できません(エラー-8)。

カーネルはバイナリを実行できません(エラー-8)。

私のプラットフォーム:

SOC = STM32H743 (ARMv7E-M | Cortex-M7)
Board = Waveshare CoreH7XXI 
Linux Kernel = 5.8.10 (stable 2020-09-17)
initial defconfig file = stm32_defconfig
rootfs = built using busybox | busybox compiled using  arm-linux-gnueabihf-gcc

私は次のようにrootfsを作成しました。このガイド

私のカーネルはinitファイル>>>/linuxrcまたは/sbin/init

問題がビジボックスファイルで発生しないことを確認するために、フラグを-mcpu=cortex-m7含むC helloworldプログラムを作成し、それを使用してコンパイルしarm-linux-gnueabi-gccましたが、カーネルがパニックに陥り、-8エラー(Exec形式エラー)が発生しました。

私のbusyboxファイルはすべてbusyboxバイナリにリンクされており、バイナリは32ビットarmに対して正しくコンパイルされています。

$ readelf -A bin/busybox
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "Cortex-M7"
  Tag_CPU_arch: v7E-M
  Tag_CPU_arch_profile: Microcontroller
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_CPU_unaligned_access: v6

カーネルエラー:

[    0.925859] Run /linuxrc as init process
[    0.943257] Kernel panic - not syncing: Requested init /linuxrc failed (error -8).
[    0.950654] ---[ end Kernel panic - not syncing: Requested init /linuxrc failed (error -8). ]---

私のHello Worldプログラム:

$ readelf -A hello
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7E-M"
  Tag_CPU_arch: v7E-M
  Tag_CPU_arch_profile: Microcontroller
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_CPU_unaligned_access: v6

カーネルエラー:

[    1.189550] Run /hello as init process
[    1.198670] Kernel panic - not syncing: Requested init /hello failed (error -8).
[    1.205977] ---[ end Kernel panic - not syncing: Requested init /hello failed (error -8). ]---

カーネルがバイナリを実行できないのはなぜですか?

ベストアンサー1

問題は、一般的な静的エルフ形式にコンパイルすることです。 FDPIC-ELF実行可能ファイルにコンパイルする必要があります(MMUがないため、場所に依存しない実行可能ファイル(FDPIC)が必要です)。

FDPIC ELF は ET_EXEC タイプではありません。これはET_DYNタイプ(共有されることを意味)であり、Linux動的ローダーによってロードされます。

フラグを追加し-mfdpicて閉じます。静的バイナリビルドbusyboxのkconfigメニューから。

-mfdpicフラグは、arm-uclinux-fdpicabiツールチェーンでデフォルトで有効になっています。

おすすめ記事