I want to compile this code which enables cycles counters on ARM Cortex A8 through Debian OS on target. I wrote this code in /home
and want to compile it.
How can i compile it and where should i put the output file?
Code:
#include <linux/module.h>
#include <linux/kernel.h>
static int OldState;
int __init init_module(void)
{
/* enable user-mode access */
asm ("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(1));
/* disable counter overflow interrupts (just in case)*/
asm ("MCR p15, 0, %0, C9, C14, 2\n\t" :: "r"(0x8000000f));
printk(KERN_INFO "user-mode access to performance registers enabled\n");
return 0;
}
void cleanup_module(void)
{
}
You need ARM toolchain (cross-compiler) for this. It will compile sources for ARM architecture on your x86 machine. See this and this.
Once you installed ARM toolchain, provide CROSS_COMPILE
environment variable to make
(or just do something like export CROSS_COMPILE=arm-none-eabi-
in your shell before running make
). Kernel build system will use this variable as prefix for tools like gcc
, as
, ld
etc. This way your module will be built for ARM architecture. Use file
tool on your module file (.ko
) to be sure it was built for ARM.
User contributions licensed under CC BY-SA 3.0