2017-12-21 6 views
2

기존 장치 (mips arch)에 몇 가지 기능을 추가했습니다. 몇 가지 SDK를 시험해 보았습니다. 현재로서는 몇 가지 진도가 있지만, insmod returns 0 (성공) 및 lsmod 보여줍니다하지만 printk 또는 create_proc_entry 작동하지 않습니다 ....하지만 섹션 .gnu.linkonce.this_module 본 : 모듈 이름 제외 - 유용한 정보가 없습니다 - 섹션은 0x0으로 채워집니다.커널 모듈이로드되지 않았지만 (insmod는 0을 반환합니다.)

섹션 .gnu.linkonce.this_module의 디바이스 크기가 .ko 파일의 원시 .ko 파일에서 8 바이트로 작다는 것을 알았지 만,이 섹션이 구조 모듈에 대한 임시로드 정보로 사용된다는 사실에 따르면 내 의견에 상관 없습니다 ...

https://ufile.io/eco1s 여러 파일이 있습니다. khelloworld.ko - 내 helloworld 모듈 - procfs 항목을 작성하십시오. khelloworld.ko - rootfs (/tmp/test.file) 기본 모듈에 파일을 작성하십시오. xt_mark.ko md5.ko cbc. 코

나는 커널 구성이없는 -하지만 난

#include <linux/module.h> 
#include <linux/kernel.h> 
#include <linux/proc_fs.h> /* Necessary because we use the proc fs */ 
#include <linux/init.h>  /* Needed for the macros */ 

#define procfs_name "khelloworld" 


MODULE_LICENSE("GPL"); 
MODULE_INFO(vermagic, "2.6.32.68 mod_unload MIPS32_R2 32BIT "); 
MODULE_AUTHOR  ("XAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); 


struct proc_dir_entry *Our_Proc_File; 

static int 
procfile_read(char *buffer, 
     char **buffer_location, 
     off_t offset, int buffer_length, int *eof, void *data); 

    static int __init khelloworld_init(void) { 
    printk(KERN_INFO "try to create /proc \n"); 
    Our_Proc_File = create_proc_entry(procfs_name, 0644, NULL); 

    if (Our_Proc_File == NULL) { 
     remove_proc_entry(procfs_name, NULL); 
     printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", 
      procfs_name); 
     return -ENOMEM; 
    } 

    Our_Proc_File->read_proc = procfile_read; 
    Our_Proc_File->owner  = THIS_MODULE; 
    Our_Proc_File->mode  = S_IFREG | S_IRUGO; 
    Our_Proc_File->uid  = 0; 
    Our_Proc_File->gid  = 0; 
    Our_Proc_File->size  = 37; 

    printk(KERN_INFO "/proc/%s created\n", procfs_name);  
    return 3; /* everything is ok */ 
} 

static void __exit khelloworld_exit(void) { 
    remove_proc_entry(procfs_name, NULL); 
    printk(KERN_INFO "/proc/%s removed\n", procfs_name); 
} 


module_init(khelloworld_init); 
module_exit(khelloworld_exit); 

int 
procfile_read(char *buffer, 
     char **buffer_location, 
     off_t offset, int buffer_length, int *eof, void *data) 
{ 
    int ret; 

    printk(KERN_INFO "procfile_read (/proc/%s) called\n", procfs_name); 

    /* 
    * We give all of our information in one go, so if the 
    * user asks us if we have more information the 
    * answer should always be no. 
    * 
    * This is important because the standard read 
    * function from the library would continue to issue 
    * the read system call until the kernel replies 
    * that it has no more information, or until its 
    * buffer is filled. 
    */ 
    if (offset > 0) { 
     /* we have finished to read, return 0 */ 
     ret = 0; 
    } else { 
     /* fill the buffer, return the buffer size */ 
     ret = sprintf(buffer, "HelloWorld!\n"); 
    } 

    return ret; 
} 
+1

스택 오버플로에 오신 것을 환영합니다! 여기서 우리는 문제의 코드와 다른 정보 (빌드 로그와 같은)가 ** 링크되지 않은 ** 질문 자체에 포함되도록합니다. 귀하의 질문을 편집하여 그 문제를 해결하십시오. – Tsyvarev

답변

3

readelf -a 당신의 init 함수에 대한 재배치 항목이보다 다르다는 것을 보여주고 난 단지 버전을 알고 ... 그 모듈을 컴파일 할 필요가 기본 모듈 케이스 :

xt_mark.ko 

Relocation section '.rel.gnu.linkonce.this_module' at offset 0x958 contains 2 entries: 
Offset  Info Type   Sym.Value Sym. Name 
000000bc 00001502 R_MIPS_32   00000000 init_module 
00000130 00001402 R_MIPS_32   00000000 cleanup_module 


khelloworld.ko 

Relocation section '.rel.gnu.linkonce.this_module' at offset 0xafc contains 2 entries: 
Offset  Info Type   Sym.Value Sym. Name 
000000ac 00002502 R_MIPS_32   00000000 init_module 
0000010c 00002402 R_MIPS_32   00000000 cleanup_module 

네이티브 모듈의 경우 init_module 포인터가 module 구조체의 오프셋 0xbc에있는 반면 모듈에서 오프셋 0xac에있는 방법에 유의하십시오. 결과적으로 로더는 init 함수를 찾지 못하고 호출하지 않습니다.

설명했듯이 here은 빌드 환경과 기본 빌드 환경 간의 커널 구성 차이로 인한 것일 수 있습니다. CONFIG_UNUSED_SYMBOLS이 원인 일 가능성이 큽니다 (module 정의 here 참조).

또는 (자신의 책임하에) 결과 모듈에 0xac을 0xbc로 변경하는 바이너리 패치를 적용 할 수 있습니다.

관련 문제