I've to add some functionality to an existing device (mips arch) - I've tryed several SDK's and at this moment I have some progress, but: insmod returns 0(success) and lsmod shows them, but aither printk nor create_proc_entry doesn't work .... BUT I've viewed section .gnu.linkonce.this_module: except module name - there is no usefull info - section is filled with 0x0's
I've found that in native .ko files in device size of section .gnu.linkonce.this_module is smaller into 8 bytes - but according to the fact that section is used for temporary loading info to struct module - there is not matter in my oppinion ...
https://ufile.io/eco1s there are several files: khelloworld.ko - my helloworld module - try to create procfs entry khelloworld.ko - try to create file in rootfs (/tmp/test.file) native modules: xt_mark.ko md5.ko cbc.ko
I don't have kernel configuration - but I need to compile that module... I know only the version
#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;
}