On 09/23/2010 07:42 PM, Adam wrote:
> I am trying to compile the android source after writing my own system
> call, __NR_helloworld , the compilation goes smoothly and new kernel
> image is created arch/arm/boot/zImage. I am able to boot from new
> kernel image as well .. using "emulator -avd NameOfYourAVD -kernel
> arch/arm/boot/zImage -ramdisk ~/android-sdk/platforms/android/images/
> ramdisk.img -show-kernel".
>
> How can I compile a small program, that uses __NR_helloworld, using
> cross compiler against the new kernel image that i created ?
> arm-none-linux-gnueabi-gcc -static -o hello hello.c is giving
> compilation error :(
>
> Steps followed to write new system call :
>
> 1. edit include/asm-generic/unistd.h - ADDED
>
> #define __NR_helloworld 242
> __SYSCALL(__NR_helloworld, sys_helloworld)
>
> incremented __NR_syscalls to 243
>
> 2. edit arch/arm/kernel/calls.S - Added
>
> CALL(sys_helloworld) in the end after perf_event_open call.
>
> 3. created mycalls/helloworld.c
>
> #include <linux/kernel.h>
> #include <linux/linkage.h>
> asmlinkage int sys_helloworld(){
> printk(KERN_DEBUG "Hello World!");
> return(1);
> }
>
> 4. created mycalls/Makefile
> obj-y := helloworld.o
>
> 5. edited the kernel make file to include mycalls folder.
>
> core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ mycalls/
>
> 6. Compile the source - make -j2 ARCH=arm CROSS_COMPILE=arm-none-linux-
> gnueabi-
>
> 7. arch/arm/boot/zImage - new kernel image is created !
>
>
> Testing new helloworld system call.
>
> 1. write hello.c
>
> #include <linux/errno.h>
> #include <sys/syscall.h>
> #include <linux/unistd.h>
>
> /* For testing your syscall */
>
> int helloworld()
> {
> return syscall(__NR_helloworld);
> }
>
> int main()
> {
> helloworld();
> return 0;
> }
>
> 2. compile it - arm-none-linux-gnueabi-gcc -static -o hello hello.c
>
> 3. step 2 is erroring out with - error: '__NR_helloworld' undeclared,
> I suspect it is not getting the new kernel image location ?
I just did something like this (actually, didn't add my own
syscall, but needed to use one that bionic didn't support).
I think your problem is that the compiler is not picking up
the new include/asm-generic/unistd.h
You may want to look at the "compilation plan" for the compiler
to see where it's looking for include files. Try:
gcc -### <the rest of your command line goes here>
(See http://elinux.org/GCC_Tips for details.)
FYI, for my work I did the following (which worked):
1. created my own new external module in my source tree:
mkdir external/hello ; cp external/ping/* external/hello
and rename/edit Android.mk and ping.c to refer to/be
hello.c
2. made a version of my own C-wrapper for the syscall
cp bionic/libc/arch-arm/syscalls/__llseek.S external/hello/readahead.S
and edit the syscall number in the file.
You should choose a C wrapper that matches the function
signature for your syscall.
I just used a constant instead of using a #defined value
(ie, I was trying to use readahead, so I changed the following:
ldr r7, =__NR__llseek
to
/* __NR_readahead on ARM is 225 */
ldr r7, =225
Add readahead.S to external/hello/Android.mk
3. compiled my program
'mm' in source directory
Then copy to target and run.
I hope this helps.
-- Tim
=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Network Entertainment
=============================
--
unsubscribe: [email protected]
website: http://groups.google.com/group/android-kernel