LinuxForum.Fans
Тема

Создание модуля для недоступного в исходниках ядра

Автор: Zolg 12 сообщений 6767 просмотров
25.03.2014 18:20 · отредактировано #373957

Есть железяка, работающая под linux (с очень большой вероятностью - на основе MontaVista). Ядро 2.6.37 (очень врядли ванильное). Исходников нет, на GPL производитель клал. Процессор в железяке ARM (TI811X). Есть возможность исполнять скрипты и бинарники от рута. Этим возможности взаимодействия исчерпываются (консоли нет). Linux сильно урезан.
Желая возможности железки расширить решил подпихнуть ей недостающие для полного счастья модули ядра.

Не буду описывать всего долгого пути, однако пока что он закончился в следующем тупике:
Используя ванильное ядро 2.6.37 собираю хрестоматийный printk(KERN_ALERT "Hello, world\n"); модуль.

  • vermagic совпадает со штатными бинарными модулями железяки (vermagic=2.6.37 mod_unload ARMv7 )
  • insmod отрабатывает без ошибок
  • в /proc/modules модуль появляется (hello 657 0 - Live 0xbf30b000)
  • но судя по всему код из module_init() никогда не выполняется

причем я сначала грешил на неработу printk() в железяке (хотя в родных модулях printk() отрабатывает нормально) и как маркер решил использовать обращение к null pointer (kernel panic сигнализировал бы о выполнении кода), но нет: модуль числится в загруженных, а система работает как ни в чем не бывало.

Что это вообще за чертовщина может быть ?

25.03.2014 20:00 #373981

в порядке идеи, можно выцыганить один или несколько родных модулей и посмотреть objdump'ом что в них есть... может наведёт на какие-то мысли...

на всякий пожарный, дай код и вывод objdump -t своего hello.ko, а то может забыл что-то... например module_init(); =)

26.03.2014 14:10 #374093

hello.c:

Показать
text
#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void) { printk(KERN_ALERT "Hello, world\n"); return 0; }

static void hello_exit(void)

{ printk(KERN_ALERT "Goodbye, cruel world\n"); }

module_init(hello_init); module_exit(hello_exit);

objdump -x hello.ko:

Показать
text

hello.ko:     file format elf32-littlearm
hello.ko
architecture: arm, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000
private flags = 5000000: [Version5 EABI]

Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000004c 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 1 .modinfo 00000044 00000000 00000000 00000080 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 2 .rodata.str1.4 00000030 00000000 00000000 000000c4 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .data 00000000 00000000 00000000 000000f4 2**0 CONTENTS, ALLOC, LOAD, DATA 4 .gnu.linkonce.this_module 0000015c 00000000 00000000 000000f4 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA, LINK_ONCE_DISCARD 5 .note.gnu.build-id 00000024 00000000 00000000 00000250 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 6 .bss 00000000 00000000 00000000 00000274 2**0 ALLOC 7 .debug_frame 00000050 00000000 00000000 00000274 2**2 CONTENTS, RELOC, READONLY, DEBUGGING 8 .debug_info 00001f55 00000000 00000000 000002c4 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 9 .debug_abbrev 000003d4 00000000 00000000 00002219 2**0 CONTENTS, READONLY, DEBUGGING 10 .debug_loc 00000058 00000000 00000000 000025ed 2**0 CONTENTS, READONLY, DEBUGGING 11 .debug_aranges 00000038 00000000 00000000 00002645 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 12 .debug_line 000003ba 00000000 00000000 0000267d 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 13 .debug_str 000017a3 00000000 00000000 00002a37 2**0 CONTENTS, READONLY, DEBUGGING 14 .comment 00000056 00000000 00000000 000041da 2**0 CONTENTS, READONLY 15 .note.GNU-stack 00000000 00000000 00000000 00004230 2**0 CONTENTS, READONLY 16 .ARM.attributes 0000002f 00000000 00000000 00004230 2**0 CONTENTS, READONLY SYMBOL TABLE: 00000000 l d .text 00000000 .text 00000000 l d .modinfo 00000000 .modinfo 00000000 l d .rodata.str1.4 00000000 .rodata.str1.4 00000000 l d .data 00000000 .data 00000000 l d .gnu.linkonce.this_module 00000000 .gnu.linkonce.this_module 00000000 l d .note.gnu.build-id 00000000 .note.gnu.build-id 00000000 l d .bss 00000000 .bss 00000000 l d .debug_frame 00000000 .debug_frame 00000000 l d .debug_info 00000000 .debug_info 00000000 l d .debug_abbrev 00000000 .debug_abbrev 00000000 l d .debug_loc 00000000 .debug_loc 00000000 l d .debug_aranges 00000000 .debug_aranges 00000000 l d .debug_line 00000000 .debug_line 00000000 l d .debug_str 00000000 .debug_str 00000000 l d .comment 00000000 .comment 00000000 l d .note.GNU-stack 00000000 .note.GNU-stack 00000000 l d .ARM.attributes 00000000 .ARM.attributes 00000000 l df *ABS* 00000000 hello.c 00000000 l F .text 00000028 hello_init 00000000 l .rodata.str1.4 00000000 .LC0 00000028 l F .text 00000024 hello_exit 00000014 l .rodata.str1.4 00000000 .LC1 00000000 l O .modinfo 00000015 __mod_license4 00000000 l df *ABS* 00000000 hello.mod.c 00000018 l O .modinfo 00000009 __module_depends 00000021 l O .modinfo 00000022 __mod_vermagic5 00000000 l df *ABS* 00000000 00000000 g O .gnu.linkonce.this_module 0000015c __this_module 00000028 g F .text 00000024 cleanup_module 00000000 g F .text 00000028 init_module 00000000 *UND* 00000000 printk 00000000 *UND* 00000000 __gnu_mcount_nc

RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 00000010 R_ARM_CALL __gnu_mcount_nc 00000014 R_ARM_MOVW_ABS_NC .LC0 00000018 R_ARM_MOVT_ABS .LC0 0000001c R_ARM_CALL printk 00000038 R_ARM_CALL __gnu_mcount_nc 0000003c R_ARM_MOVW_ABS_NC .LC1 00000040 R_ARM_MOVT_ABS .LC1 00000044 R_ARM_CALL printk

RELOCATION RECORDS FOR [.gnu.linkonce.this_module]: OFFSET TYPE VALUE 000000d4 R_ARM_ABS32 init_module 0000014c R_ARM_ABS32 cleanup_module

RELOCATION RECORDS FOR [.debug_frame]: OFFSET TYPE VALUE 00000014 R_ARM_ABS32 .debug_frame 00000018 R_ARM_ABS32 .text 00000034 R_ARM_ABS32 .debug_frame 00000038 R_ARM_ABS32 .text

RELOCATION RECORDS FOR [.debug_info]: OFFSET TYPE VALUE вырезал нафиг

RELOCATION RECORDS FOR [.debug_aranges]: OFFSET TYPE VALUE 00000006 R_ARM_ABS32 .debug_info 00000010 R_ARM_ABS32 .text 00000026 R_ARM_ABS32 .debug_info

RELOCATION RECORDS FOR [.debug_line]: OFFSET TYPE VALUE 0000018e R_ARM_ABS32 .text

objdump -x vfat.ko (модуль из штатной прошивки):

Показать
text

vfat.ko:     file format elf32-littlearm
vfat.ko
architecture: arm, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000
private flags = 5000000: [Version5 EABI]

Sections: Idx Name Size VMA LMA File off Algn 0 .text 00001ad8 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 1 .exit.text 00000024 00000000 00000000 00001b0c 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 2 .init.text 0000001c 00000000 00000000 00001b30 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 3 .rodata 000000a4 00000000 00000000 00001b4c 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA 4 .modinfo 00000078 00000000 00000000 00001bf0 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 5 .rodata.str1.1 00000044 00000000 00000000 00001c68 2**0 CONTENTS, ALLOC, LOAD, READONLY, DATA 6 __mcount_loc 00000050 00000000 00000000 00001cac 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA 7 .data 00000024 00000000 00000000 00001cfc 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 8 .gnu.linkonce.this_module 00000144 00000000 00000000 00001d20 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA, LINK_ONCE_DISCARD 9 .note.gnu.build-id 00000024 00000000 00000000 00001e64 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 10 .bss 00000000 00000000 00000000 00001e88 2**0 ALLOC 11 .note.GNU-stack 00000000 00000000 00000000 00001e88 2**0 CONTENTS, READONLY, CODE 12 .ARM.attributes 0000002d 00000000 00000000 00001e88 2**0 CONTENTS, READONLY 13 .comment 00000050 00000000 00000000 00001eb5 2**0 CONTENTS, READONLY SYMBOL TABLE: 00000000 l d .text 00000000 .text 00000000 l d .exit.text 00000000 .exit.text 00000000 l d .init.text 00000000 .init.text 00000000 l d .rodata 00000000 .rodata 00000000 l d .modinfo 00000000 .modinfo 00000000 l d .rodata.str1.1 00000000 .rodata.str1.1 00000000 l d __mcount_loc 00000000 __mcount_loc 00000000 l d .data 00000000 .data 00000000 l d .gnu.linkonce.this_module 00000000 .gnu.linkonce.this_module 00000000 l d .note.gnu.build-id 00000000 .note.gnu.build-id 00000000 l d .bss 00000000 .bss 00000000 l d .note.GNU-stack 00000000 .note.GNU-stack 00000000 l d .ARM.attributes 00000000 .ARM.attributes 00000000 l d .comment 00000000 .comment 00000000 l df *ABS* 00000000 namei_vfat.c 0000003c l F .text 0000002c vfat_revalidate 00000068 l F .text 00000050 vfat_revalidate_ci 000000b8 l F .text 00000044 vfat_striptail_len 000000fc l F .text 00000060 vfat_hash 0000015c l F .text 00000080 vfat_hashi 000001dc l F .text 000000a0 vfat_cmpi 0000027c l F .text 00000028 vfat_skip_char 00000000 l F .exit.text 00000024 exit_vfat_fs 000002a4 l F .text 00000030 vfat_mount 000002d4 l F .text 00000088 vfat_fill_super 0000035c l F .text 00000058 vfat_cmp 000003b4 l F .text 00000048 vfat_find 000003fc l F .text 000000b8 vfat_rmdir 000004b4 l F .text 0000009c vfat_unlink 00000550 l F .text 00000048 vfat_find_form 00000598 l F .text 00000da0 vfat_add_entry 00001338 l F .text 000003cc vfat_rename 00001704 l F .text 00000114 vfat_create 00001818 l F .text 00000154 vfat_mkdir 0000196c l F .text 0000016c vfat_lookup 00000000 l F .init.text 0000001c init_vfat_fs 00000000 l O .rodata 00000060 vfat_dir_inode_operations 00000060 l O .rodata 0000001c vfat_ci_dentry_ops 0000007c l O .rodata 0000001c vfat_dentry_ops 00000098 l O .rodata 0000000c __func__.19990 00000000 l O .modinfo 00000016 __mod_author1101 00000016 l O .modinfo 00000024 __mod_description1100 0000003a l O .modinfo 0000000c __mod_license1099 00000000 l O .data 00000024 vfat_fs_type 00000000 l F .text 0000003c vfat_revalidate_shortname 00000000 l df *ABS* 00000000 vfat.mod.c 00000048 l O .modinfo 0000000c __module_depends 00000054 l O .modinfo 00000022 __mod_vermagic5 00000000 *UND* 00000000 d_instantiate 00000000 *UND* 00000000 fat_dir_empty 00000000 g O .gnu.linkonce.this_module 00000144 __this_module 00000000 *UND* 00000000 snprintf 00000000 *UND* 00000000 fat_time_unix2fat 00000000 *UND* 00000000 lock_super 00000000 *UND* 00000000 unregister_filesystem 00000000 *UND* 00000000 fat_get_dotdot_entry 00000000 *UND* 00000000 fat_free_clusters 00000000 *UND* 00000000 fat_setattr 00000000 g F .exit.text 00000024 cleanup_module 00000000 *UND* 00000000 d_splice_alias 00000000 *UND* 00000000 memcpy 00000000 *UND* 00000000 kfree 00000000 *UND* 00000000 iput 00000000 *UND* 00000000 __fat_fs_error 00000000 *UND* 00000000 register_filesystem 00000000 *UND* 00000000 fat_scan 00000000 g F .init.text 0000001c init_module 00000000 *UND* 00000000 fat_search_long 00000000 *UND* 00000000 __bug 00000000 *UND* 00000000 kill_block_super 00000000 *UND* 00000000 kmem_cache_alloc 00000000 *UND* 00000000 __aeabi_idiv 00000000 *UND* 00000000 __brelse 00000000 *UND* 00000000 fat_getattr 00000000 *UND* 00000000 sync_dirty_buffer 00000000 *UND* 00000000 kmem_cache_free 00000000 *UND* 00000000 strncmp 00000000 *UND* 00000000 d_move 00000000 *UND* 00000000 fat_attach 00000000 *UND* 00000000 _ctype 00000000 *UND* 00000000 kmem_cache_alloc_notrace 00000000 *UND* 00000000 fat_build_inode 00000000 *UND* 00000000 fat_fill_super 00000000 *UND* 00000000 memset 00000000 *UND* 00000000 fat_alloc_new_dir 00000000 *UND* 00000000 fat_remove_entries 00000000 *UND* 00000000 jiffies 00000000 *UND* 00000000 fat_add_entries 00000000 *UND* 00000000 fat_sync_inode 00000000 *UND* 00000000 mount_bdev 00000000 *UND* 00000000 unlock_super 00000000 *UND* 00000000 names_cachep 00000000 *UND* 00000000 __gnu_mcount_nc 00000000 *UND* 00000000 d_find_alias 00000000 *UND* 00000000 dput 00000000 *UND* 00000000 __tracepoint_kmalloc 00000000 *UND* 00000000 __mark_inode_dirty 00000000 *UND* 00000000 mark_buffer_dirty_inode 00000000 *UND* 00000000 __aeabi_idivmod 00000000 *UND* 00000000 utf8s_to_utf16s 00000000 *UND* 00000000 get_seconds 00000000 *UND* 00000000 kmalloc_caches 00000000 *UND* 00000000 fat_detach

RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 00000010 R_ARM_CALL __gnu_mcount_nc 0000004c R_ARM_CALL __gnu_mcount_nc 00000078 R_ARM_CALL __gnu_mcount_nc 000000c8 R_ARM_CALL __gnu_mcount_nc 0000010c R_ARM_CALL __gnu_mcount_nc 0000016c R_ARM_CALL __gnu_mcount_nc 000001ec R_ARM_CALL __gnu_mcount_nc 0000028c R_ARM_CALL __gnu_mcount_nc 000002b8 R_ARM_CALL __gnu_mcount_nc 000002c4 R_ARM_CALL mount_bdev 000002d0 R_ARM_ABS32 vfat_fill_super 000002e8 R_ARM_CALL __gnu_mcount_nc 000002f8 R_ARM_CALL lock_super 00000314 R_ARM_CALL fat_fill_super 00000340 R_ARM_CALL unlock_super 00000350 R_ARM_ABS32 .rodata 00000354 R_ARM_ABS32 .rodata 00000358 R_ARM_ABS32 .rodata 0000036c R_ARM_CALL __gnu_mcount_nc 000003a4 R_ARM_CALL strncmp 000003c4 R_ARM_CALL __gnu_mcount_nc 000003f4 R_ARM_CALL fat_search_long 00000410 R_ARM_CALL __gnu_mcount_nc 00000428 R_ARM_CALL lock_super 00000430 R_ARM_CALL fat_dir_empty 00000460 R_ARM_CALL fat_remove_entries 0000047c R_ARM_CALL get_seconds 0000049c R_ARM_CALL fat_detach 000004a4 R_ARM_CALL unlock_super 000004c8 R_ARM_CALL __gnu_mcount_nc 000004e4 R_ARM_CALL lock_super 00000508 R_ARM_CALL fat_remove_entries 00000518 R_ARM_CALL get_seconds 00000538 R_ARM_CALL fat_detach 00000540 R_ARM_CALL unlock_super 00000564 R_ARM_CALL __gnu_mcount_nc 0000056c R_ARM_CALL fat_scan 00000588 R_ARM_CALL __brelse 000005ac R_ARM_CALL __gnu_mcount_nc 000005f8 R_ARM_CALL kmem_cache_alloc_notrace 00000680 R_ARM_CALL kmem_cache_alloc 000006bc R_ARM_CALL utf8s_to_utf16s 0000084c R_ARM_CALL __aeabi_idivmod 00000878 R_ARM_CALL __aeabi_idivmod 00000e10 R_ARM_CALL memset 00000e20 R_ARM_CALL memcpy 00000e30 R_ARM_CALL memcpy 00000f00 R_ARM_CALL __bug 00000fc4 R_ARM_CALL snprintf 00000fd4 R_ARM_CALL memcpy 0000102c R_ARM_CALL memcpy 0000103c R_ARM_CALL memcpy 0000104c R_ARM_CALL memcpy 000010cc R_ARM_CALL fat_time_unix2fat 00001128 R_ARM_CALL kmem_cache_free 00001144 R_ARM_CALL fat_add_entries 00001190 R_ARM_CALL fat_sync_inode 000011a0 R_ARM_CALL __mark_inode_dirty 000011a8 R_ARM_CALL kfree 000012fc R_ARM_CALL __aeabi_idiv 00001318 R_ARM_ABS32 kmalloc_caches 0000131c R_ARM_ABS32 __tracepoint_kmalloc 00001320 R_ARM_ABS32 .text 00001324 R_ARM_ABS32 names_cachep 00001328 R_ARM_ABS32 _ctype 0000132c R_ARM_ABS32 .rodata.str1.1 00001330 R_ARM_ABS32 jiffies 00001334 R_ARM_ABS32 .rodata.str1.1 0000134c R_ARM_CALL __gnu_mcount_nc 00001388 R_ARM_CALL lock_super 000013dc R_ARM_CALL fat_get_dotdot_entry 000013ec R_ARM_CALL get_seconds 00001410 R_ARM_CALL fat_dir_empty 00001428 R_ARM_CALL fat_detach 00001484 R_ARM_CALL fat_detach 00001490 R_ARM_CALL fat_attach 000014b4 R_ARM_CALL fat_sync_inode 000014d0 R_ARM_CALL __mark_inode_dirty 000014fc R_ARM_CALL mark_buffer_dirty_inode 00001520 R_ARM_CALL sync_dirty_buffer 00001550 R_ARM_CALL fat_remove_entries 000015b4 R_ARM_CALL fat_sync_inode 000015c4 R_ARM_CALL __mark_inode_dirty 00001604 R_ARM_CALL __brelse 00001614 R_ARM_CALL __brelse 00001624 R_ARM_CALL __brelse 0000162c R_ARM_CALL unlock_super 00001668 R_ARM_CALL mark_buffer_dirty_inode 00001670 R_ARM_CALL sync_dirty_buffer 0000167c R_ARM_CALL fat_detach 00001688 R_ARM_CALL fat_attach 0000169c R_ARM_CALL fat_attach 000016ac R_ARM_CALL fat_sync_inode 000016c0 R_ARM_CALL fat_remove_entries 000016f4 R_ARM_CALL __fat_fs_error 000016fc R_ARM_ABS32 .rodata.str1.1 00001700 R_ARM_ABS32 .rodata 00001718 R_ARM_CALL __gnu_mcount_nc 0000172c R_ARM_CALL lock_super 00001730 R_ARM_CALL get_seconds 0000178c R_ARM_CALL fat_build_inode 000017a0 R_ARM_CALL __brelse 00001800 R_ARM_CALL d_instantiate 00001808 R_ARM_CALL unlock_super 0000182c R_ARM_CALL __gnu_mcount_nc 00001844 R_ARM_CALL lock_super 00001848 R_ARM_CALL get_seconds 00001860 R_ARM_CALL fat_alloc_new_dir 000018c8 R_ARM_CALL fat_build_inode 000018dc R_ARM_CALL __brelse 00001944 R_ARM_CALL d_instantiate 00001954 R_ARM_CALL fat_free_clusters 0000195c R_ARM_CALL unlock_super 00001980 R_ARM_CALL __gnu_mcount_nc 00001994 R_ARM_CALL lock_super 000019cc R_ARM_CALL fat_build_inode 000019e0 R_ARM_CALL __brelse 000019f4 R_ARM_CALL d_find_alias 00001a24 R_ARM_CALL __bug 00001a40 R_ARM_CALL d_move 00001a48 R_ARM_CALL iput 00001a54 R_ARM_CALL dput 00001a5c R_ARM_CALL unlock_super 00001a84 R_ARM_CALL d_splice_alias 00001ab4 R_ARM_CALL unlock_super 00001ad4 R_ARM_ABS32 .rodata.str1.1

RELOCATION RECORDS FOR [.exit.text]: OFFSET TYPE VALUE 00000010 R_ARM_CALL __gnu_mcount_nc 00000018 R_ARM_CALL unregister_filesystem 00000020 R_ARM_ABS32 .data

RELOCATION RECORDS FOR [.init.text]: OFFSET TYPE VALUE 00000010 R_ARM_CALL register_filesystem 00000018 R_ARM_ABS32 .data

RELOCATION RECORDS FOR [.rodata]: OFFSET TYPE VALUE 00000000 R_ARM_ABS32 vfat_create 00000004 R_ARM_ABS32 vfat_lookup 0000000c R_ARM_ABS32 vfat_unlink 00000014 R_ARM_ABS32 vfat_mkdir 00000018 R_ARM_ABS32 vfat_rmdir 00000020 R_ARM_ABS32 vfat_rename 0000003c R_ARM_ABS32 fat_setattr 00000040 R_ARM_ABS32 fat_getattr 00000060 R_ARM_ABS32 vfat_revalidate_ci 00000064 R_ARM_ABS32 vfat_hashi 00000068 R_ARM_ABS32 vfat_cmpi 0000007c R_ARM_ABS32 vfat_revalidate 00000080 R_ARM_ABS32 vfat_hash 00000084 R_ARM_ABS32 vfat_cmp

RELOCATION RECORDS FOR [__mcount_loc]: OFFSET TYPE VALUE 00000000 R_ARM_ABS32 vfat_revalidate_shortname 00000004 R_ARM_ABS32 vfat_revalidate_shortname 00000008 R_ARM_ABS32 vfat_revalidate_shortname 0000000c R_ARM_ABS32 vfat_revalidate_shortname 00000010 R_ARM_ABS32 vfat_revalidate_shortname 00000014 R_ARM_ABS32 vfat_revalidate_shortname 00000018 R_ARM_ABS32 vfat_revalidate_shortname 0000001c R_ARM_ABS32 vfat_revalidate_shortname 00000020 R_ARM_ABS32 vfat_revalidate_shortname 00000024 R_ARM_ABS32 vfat_revalidate_shortname 00000028 R_ARM_ABS32 vfat_revalidate_shortname 0000002c R_ARM_ABS32 vfat_revalidate_shortname 00000030 R_ARM_ABS32 vfat_revalidate_shortname 00000034 R_ARM_ABS32 vfat_revalidate_shortname 00000038 R_ARM_ABS32 vfat_revalidate_shortname 0000003c R_ARM_ABS32 vfat_revalidate_shortname 00000040 R_ARM_ABS32 vfat_revalidate_shortname 00000044 R_ARM_ABS32 vfat_revalidate_shortname 00000048 R_ARM_ABS32 vfat_revalidate_shortname 0000004c R_ARM_ABS32 vfat_revalidate_shortname

RELOCATION RECORDS FOR [.data]: OFFSET TYPE VALUE 00000000 R_ARM_ABS32 .rodata.str1.1 0000000c R_ARM_ABS32 vfat_mount 00000010 R_ARM_ABS32 kill_block_super 00000014 R_ARM_ABS32 __this_module

RELOCATION RECORDS FOR [.gnu.linkonce.this_module]: OFFSET TYPE VALUE 000000bc R_ARM_ABS32 init_module 00000134 R_ARM_ABS32 cleanup_module

заранее спасибо

26.03.2014 18:41 · отредактировано #374116

Обратил внимание, на то, что в hello-модуле init находится в секции .text (а не .init.text), подправил. Но, увы, на результат не повлияло.

правленый hello.c:

Показать
text
#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("Dual BSD/GPL");

static int __init hello_init(void) { printk(KERN_ALERT "Hello, world\n"); return 0; }

static void __exit hello_exit(void)

{ printk(KERN_ALERT "Goodbye, cruel world\n"); }

module_init(hello_init); module_exit(hello_exit);

objdump -x правленого hello.ko:

Показать
text

hello.ko:     file format elf32-littlearm
hello.ko
architecture: arm, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000
private flags = 5000000: [Version5 EABI]

Sections: Idx Name Size VMA LMA File off Algn 0 .text 00000000 00000000 00000000 00000034 2**0 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .init.text 00000020 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 2 .exit.text 00000024 00000000 00000000 00000054 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 3 .rodata.str1.4 00000030 00000000 00000000 00000078 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 4 .modinfo 00000050 00000000 00000000 000000a8 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 5 .data 00000000 00000000 00000000 000000f8 2**0 CONTENTS, ALLOC, LOAD, DATA 6 .gnu.linkonce.this_module 0000015c 00000000 00000000 000000f8 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA, LINK_ONCE_DISCARD 7 .note.gnu.build-id 00000024 00000000 00000000 00000254 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 8 .bss 00000000 00000000 00000000 00000278 2**0 ALLOC 9 .debug_frame 00000050 00000000 00000000 00000278 2**2 CONTENTS, RELOC, READONLY, DEBUGGING 10 .debug_info 00001dfd 00000000 00000000 000002c8 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 11 .debug_abbrev 000003a0 00000000 00000000 000020c5 2**0 CONTENTS, READONLY, DEBUGGING 12 .debug_loc 00000058 00000000 00000000 00002465 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 13 .debug_aranges 00000040 00000000 00000000 000024bd 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 14 .debug_ranges 00000018 00000000 00000000 000024fd 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 15 .debug_line 000003ad 00000000 00000000 00002515 2**0 CONTENTS, RELOC, READONLY, DEBUGGING 16 .debug_str 000014d6 00000000 00000000 000028c2 2**0 CONTENTS, READONLY, DEBUGGING 17 .comment 00000056 00000000 00000000 00003d98 2**0 CONTENTS, READONLY 18 .note.GNU-stack 00000000 00000000 00000000 00003dee 2**0 CONTENTS, READONLY 19 .ARM.attributes 0000002f 00000000 00000000 00003dee 2**0 CONTENTS, READONLY SYMBOL TABLE: 00000000 l d .text 00000000 .text 00000000 l d .init.text 00000000 .init.text 00000000 l d .exit.text 00000000 .exit.text 00000000 l d .rodata.str1.4 00000000 .rodata.str1.4 00000000 l d .modinfo 00000000 .modinfo 00000000 l d .data 00000000 .data 00000000 l d .gnu.linkonce.this_module 00000000 .gnu.linkonce.this_module 00000000 l d .note.gnu.build-id 00000000 .note.gnu.build-id 00000000 l d .bss 00000000 .bss 00000000 l d .debug_frame 00000000 .debug_frame 00000000 l d .debug_info 00000000 .debug_info 00000000 l d .debug_abbrev 00000000 .debug_abbrev 00000000 l d .debug_loc 00000000 .debug_loc 00000000 l d .debug_aranges 00000000 .debug_aranges 00000000 l d .debug_ranges 00000000 .debug_ranges 00000000 l d .debug_line 00000000 .debug_line 00000000 l d .debug_str 00000000 .debug_str 00000000 l d .comment 00000000 .comment 00000000 l d .note.GNU-stack 00000000 .note.GNU-stack 00000000 l d .ARM.attributes 00000000 .ARM.attributes 00000000 l df *ABS* 00000000 hello.c 00000000 l F .init.text 00000020 hello_init 00000000 l F .exit.text 00000024 hello_exit 00000000 l df *ABS* 00000000 hello.mod.c 00000000 l O .modinfo 00000023 __mod_srcversion23 00000024 l O .modinfo 00000009 __module_depends 0000002d l O .modinfo 00000022 __mod_vermagic5 00000000 l df *ABS* 00000000 00000000 g O .gnu.linkonce.this_module 0000015c __this_module 00000000 g F .exit.text 00000024 cleanup_module 00000000 g F .init.text 00000020 init_module 00000000 *UND* 00000000 printk 00000000 *UND* 00000000 __gnu_mcount_nc

RELOCATION RECORDS FOR [.init.text]: OFFSET TYPE VALUE 00000010 R_ARM_CALL printk 0000001c R_ARM_ABS32 .rodata.str1.4

RELOCATION RECORDS FOR [.exit.text]: OFFSET TYPE VALUE 00000010 R_ARM_CALL __gnu_mcount_nc 00000018 R_ARM_CALL printk 00000020 R_ARM_ABS32 .rodata.str1.4

RELOCATION RECORDS FOR [.gnu.linkonce.this_module]: OFFSET TYPE VALUE 000000d4 R_ARM_ABS32 init_module 0000014c R_ARM_ABS32 cleanup_module

RELOCATION RECORDS FOR [.debug_frame]: OFFSET TYPE VALUE 00000014 R_ARM_ABS32 .debug_frame 00000018 R_ARM_ABS32 .init.text 00000034 R_ARM_ABS32 .debug_frame 00000038 R_ARM_ABS32 .exit.text

RELOCATION RECORDS FOR [.debug_info]: OFFSET TYPE VALUE вырезал

RELOCATION RECORDS FOR [.debug_aranges]: OFFSET TYPE VALUE 00000006 R_ARM_ABS32 .debug_info 00000010 R_ARM_ABS32 .init.text 00000018 R_ARM_ABS32 .exit.text 0000002e R_ARM_ABS32 .debug_info

RELOCATION RECORDS FOR [.debug_ranges]: OFFSET TYPE VALUE 00000000 R_ARM_ABS32 .init.text 00000004 R_ARM_ABS32 .init.text 00000008 R_ARM_ABS32 .exit.text 0000000c R_ARM_ABS32 .exit.text

RELOCATION RECORDS FOR [.debug_line]: OFFSET TYPE VALUE 00000174 R_ARM_ABS32 .init.text 00000183 R_ARM_ABS32 .exit.text

ну и собственно вариант hello.c, при котором по идее должна возникать kernel panic, но вместо этого система работает как ни в чем не бывало, а модуль числится загруженным:

Показать
text
#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("Dual BSD/GPL");

static int __init hello_init(void) { volatile int* nullPtr = NULL; *nullPtr = 0x1234; /* printk(KERN_ALERT "Hello, world\n"); */ return 0; }

static void __exit hello_exit(void)

{ printk(KERN_ALERT "Goodbye, cruel world\n"); }

module_init(hello_init); module_exit(hello_exit);

и дизассемблинг module_init (чтоб удостовериться, что компилятор обращение к nullPtr не съел):

Показать
text
.init.text:00000004                 EXPORT init_module
.init.text:00000004 init_module                             ; DATA XREF: .gnu.linkonce.this_module:__this_moduleo
.init.text:00000004
.init.text:00000004 oldR11          = -0xC
.init.text:00000004 oldSP           = -8
.init.text:00000004 oldLR           = -4
.init.text:00000004
.init.text:00000004                 MOV     R12, SP
.init.text:00000008                 STMFD   SP!, {R11,R12,LR,PC}
.init.text:0000000C                 SUB     R11, R12, #4
.init.text:00000010                 MOV     R3, #0
.init.text:00000014                 MOV     R2, #0x1234
.init.text:00000018                 MOV     R0, R3
.init.text:0000001C                 STR     R2, [R3]
.init.text:00000020                 LDMFD   SP, {R11,SP,PC}
.init.text:00000020 ; End of function init_module

27.03.2014 11:33 #374189
"Zolg" написал:
Обратил внимание, на то, что в hello-модуле init находится в секции .text (а не .init.text), подправил. Но, увы, на результат не повлияло.

тоже сначала подумал, но т.к. это только маркер __init, то он, понятно, ни чего не делает...
гм... быстро идеи кончились... =((

27.03.2014 12:16 #374196

Грешил еще на возможную проверку контрольных сумм/подписей, но нет: родной модуль с патченым (в бинарнике) module_init ведет себя совершенно предсказуемо.

27.03.2014 12:31 #374198

может в дополнению к objdump'у курнуть вывод readelf, хотя не уверен, что там что-то новое будет...

27.03.2014 13:26 #374207

нашел представляющимися мне могущими иметь значение различия в атрибутах aeabi:

самосборный модуль:

Показать
text
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_PCS_wchar_t: 4
  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_ABI_optimization_goals: Aggressive Speed
  Tag_CPU_unaligned_access: v6

родной:

Показать
text
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_PCS_wchar_t: 4
  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_enum_size: int
  Tag_ABI_optimization_goals: Aggressive Size
  Tag_DIV_use: Not allowed

А какими опциями конфигурации на параметры ARM EABI влиять можно ?

27.03.2014 14:23 #374213
"Zolg" написал:
А какими опциями конфигурации на параметры ARM EABI влиять можно ?

точно не знаю... я бы начал копать в сторону опций gcc, но на скорую руку ничего не нашёл...

28.03.2014 12:53 #374325

Ура, заработало !

text
<1>[   13.497392] Hello, world

Правда, в чем конкретно была проблема, увы не скажу: в недрах TI шного сайта нашел исходники ядра для evaluation board по мотивам которой, как подозреваю, железяка и была сделана. Да-да, версия в техасовских исходниках 2.6.37.
Собрал я модуль с ними, перекинул на устройство и... опять нихрена не заработало.
Но на сей раз не заработало по-другому, в логах появились ошибки, по итогам изучения которых был подкручен конфиг и все завелось.
Fat-Zer большое спасибо за то, что не дал застрять в тупике.

30.03.2014 14:58 #374698
Zolg написал:
Есть железяка, работающая под linux (с очень большой вероятностью - на основе MontaVista). Ядро 2.6.37 (очень врядли ванильное). Исходников нет, на GPL производитель клал.

Вообще то, для написания модулей ядра сами исходники ядра совершенно не нужны. *OK*
Достаточно хэдеров, ... и некоторой сообразительности.
Посмотрите здесь: Драйверы и модули ядра Linux (обновление)

31.03.2014 10:42 #374787

Спасибо, Кэп.
Только вот, незадача: мне почему-то не очень улыбается с нуля писать функционал из штатных модулей ядра, которые Clarion забыл скомпилировать (и исходники он кстати целиком зажал, вместе с хедерами).

Войдите или зарегистрируйтесь, чтобы ответить.