Skip to content

Instantly share code, notes, and snippets.

@jannson
Last active August 29, 2015 14:01
Show Gist options
  • Save jannson/fae09a3c10f5695e1ea6 to your computer and use it in GitHub Desktop.
Save jannson/fae09a3c10f5695e1ea6 to your computer and use it in GitHub Desktop.
openwrt kernel test
//static int __init populate_rootfs(void)
{/* Just test hear */
int fd, cnt;
char* buf = NULL;
fd = sys_open("/etc/preinit", O_RDONLY, 0);
buf = (char*)kmalloc(1024, GFP_KERNEL);
cnt = sys_read(fd, buf, 1024);
if(cnt == 1024)
cnt = 1023;
if(cnt > 0)
{
buf[cnt+1] = '\0';
printk("%s#%d: unpack ok, buf=%s\n", __FUNCTION__, __LINE__, buf);
}
else
{
printk("%s#%d: unpack error\n", __FUNCTION__, __LINE__);
}
sys_close(fd);
}
//main.c
static void run_init_process(const char *init_filename)
{
int i = 2;
argv_init[0] = init_filename;
envp_init[i++] = "LD_TRACE_LOADED_OBJECTS=1";
envp_init[i++] = "LD_TRACE_PRELINKING=1";
envp_init[i++] = "LD_WARN=";
envp_init[i++] = NULL;
kernel_execve(init_filename, argv_init, envp_init);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment