为 Arm/Raspberry PI 扩展 Rasbian 内核(Linux 内核 3.10.28)

编程入门 行业动态 更新时间:2024-10-17 09:48:06
本文介绍了为 Arm/Raspberry PI 扩展 Rasbian 内核(Linux 内核 3.10.28) - 如何正确添加自己的系统调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我需要向 Raspbian Linux 内核添加一个自己的系统调用.现在我在搜索了大约 2 天找到解决方案后被困住了.

I need to add an own system call to the Raspbian Linux Kernel. Now I am stuck after searching for about 2 days to find a solution.

添加系统调用,我基本上是按照大纲(http://elinux/RPi_Kernel_Compilation)使用来自以下 git 存储库的内核源代码:

To add a system call, I am basically following the general outline (http://elinux/RPi_Kernel_Compilation) using the kernel sources from the following git repo:

git://github/raspberrypi/tools.git

git://github/raspberrypi/tools.git

我已经使用 crosstool-ng (http://www.kitware/blog/home/post/426).

I have installed a cross-compile environment using crosstool-ng (http://www.kitware/blog/home/post/426).

以上所有这些都有效.我能够编译和部署一个新内核.此外,我还可以为 Raspbian 进行交叉编译.

All these above works. I am able to compile and deploy a new kernel. I am furthermore able to cross-compile for the Raspbian.

我正在尝试添加一个hello world"系统调用.该函数驻留在它自己的实现文件(kernel/helloworld.?)中并实现为:

I am trying to add a 'hello world' system call. The function resides in its own implementation files (kernel/helloworld.?) and are implemented as:

helloworld.c:

helloworld.c:

#include <linux/linkage.h>
#include <linux/kernel.h>
#include <linux/random.h>
#include "helloworld.h"

asmlinkage long sys_helloworld(){
  printk (KERN_EMERG "hello world!");
  return get_random_int()*4;
}

helloworld.h:

helloworld.h:

#ifndef HELLO_WORLD_H
#define HELLO_WORLD_H
asmlinkage long sys_helloworld(void);
#endif

Makefile 相应地进行了扩展.

The Makefile is extended accordingly.

我现在卡在错误信息中

AS      arch/arm/kernel/entry-common.o
arch/arm/kernel/entry-common.S: Assembler messages:
arch/arm/kernel/entry-common.S:104: Error: __NR_syscalls is not equal to the size of the syscall table
make[1]: *** [arch/arm/kernel/entry-common.o] Error 1

按照编写新系统调用中的建议,我添加了以下内容:

By following the advice in Writing a new system call, I added the following:

arch/arm/kernel/calls.S

arch/arm/kernel/calls.S

CALL(sys_helloworld)

arch/arm/include/uapi/asm/unistd.h

arch/arm/include/uapi/asm/unistd.h

#define __NR_helloworld                 (__NR_SYSCALL_BASE+380)

include/uapi/asm-generic/unistd.h

include/uapi/asm-generic/unistd.h

#define __NR_helloworld 274
__SYSCALL(__NR_helloworld, sys_helloworld)

#define __NR_syscalls 275

arch/x86/syscalls/syscall_32.tbl

arch/x86/syscalls/syscall_32.tbl

351     i386    helloworld              sys_helloworld

我现在一直在解决错误.

I am now stuck in solving the error.

删除calls.S中的那一行时,内核编译正常;虽然我无法调用系统调用.添加上述行时,出现上述错误.

When removing the line in calls.S, the kernel compiles fine; though I can't invoke the system call. When adding the line stated above, I am getting the mentioned error.

供参考:用于测试系统调用的客户端代码是:

For reference: The client-code for testing the system call is:

#include <linux/unistd.h>
#include <stdio.h>
#include <sys/syscall.h>

int main (int argc, char* argv[])
{
    int i=atoi(argv[1]);
    int j=-1;
    printf("invocing kernel function %i\n", i);
    j=syscall(i); /* 350 is our system calls offset number */
    printf("invoked. Return is %i. Bye.\n", j);

    return 0;
}

所有其他系统调用(例如,1 == sys_exit)都可以正常工作.

All other system calls (e.g., 1 == sys_exit) work fine.

任何想法我错过了什么?例如,我不完全了解如何实现 rasens 答案.

Any ideas what I am missing? E.g., I don't fully get how to implement rasens answer.

推荐答案

_NR_syscalls 定义在 arch/arm/include/asm/unistd.h 文件中此值将始终是 __NR_last_syscall+1.因此,在您的情况下,_NR_syscalls 应修改为 381,但由于 syscall 表中的填充,此更改也会产生相同的错误.因此将其定义为 384.这可以解决编译错误.以下更改不是必需的:

_NR_syscalls defined in arch/arm/include/asm/unistd.h file this value will always be __NR_last_syscall+1. Hence in your case _NR_syscalls should be modified to 381, but this change will also give the same error because of padding in syscall table. Hence define it to 384. This slove the compilation error. Below changes are not necessary:

include/uapi/asm-generic/unistd.h

#define __NR_helloworld 274
__SYSCALL(__NR_helloworld, sys_helloworld)

#define __NR_syscalls 275

arch/x86/syscalls/syscall_32.tbl

351     i386    helloworld              sys_helloworld

这篇关于为 Arm/Raspberry PI 扩展 Rasbian 内核(Linux 内核 3.10.28) - 如何正确添加自己的系统调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-16 14:22:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/889162.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内核   PI   Arm   Raspberry   Rasbian

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!