How to build kernel module for Cortex A8?

1

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?

  • i am just a beginner in embedded systems,
  • i tried to follow some links but all failed
  • i don't actually know the steps to do that because i am not familiar with Linux

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)
{
}
arm
beagleboneblack
cortex-a8
asked on Stack Overflow Mar 2, 2015 by khalil • edited Apr 19, 2015 by TheCodeArtist

1 Answer

1

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.

answered on Stack Overflow Apr 19, 2015 by Sam Protsenko

User contributions licensed under CC BY-SA 3.0