1

I need to add some board-specific code to a Linux kernel which I am building.

(I know I should be using device-tree already, but the driver I'm inspired by doesn't and I'm already learning a dozen new things before breakfast. Adding device-tree will also add another set of changes to debug. Once I have my platform-driver/drivers working using a board file, I will convert them to device tree.)

I have a file called arch/arm/myboard/myboard.c.

Where do I find existing board files in make menuconfig? (Such as http://lxr.free-electrons.com/source/arch/arm/mach-imx/mach-mx31ads.c?v=4.4 ?)

How do I make my board appear here also.

artless noise
  • 21,212
  • 6
  • 68
  • 105
fadedbee
  • 42,671
  • 44
  • 178
  • 308
  • 1
    Take a look at Kconfig and Makefile in the http://lxr.free-electrons.com/source/arch/arm/mach-imx/?v=4.4. For example Kconfig declare MACH_MX31MOBOARD variable and that variable is used in Makefile to build board specific code. – alexander Oct 24 '16 at 09:57
  • 1
    Actually you can just hard code the platform info in the device driver for now, and use DT when you want them configurable. – user3528438 Oct 24 '16 at 11:34
  • @user3528438 Great idea, this will save me a lot of time. Make it an answer and I'll accept it. – fadedbee Oct 24 '16 at 14:41
  • 1
    You need to patch the driver to support Device Tree. It's really easiest and right way. – 0andriy Oct 24 '16 at 21:40
  • @user3528438 Hardcode?! – 0andriy Oct 24 '16 at 21:41
  • 1
    @chrisdew I wouldn't call it a great idea. How is device/driver matching is supposed to happen? You driver's `probe()` function won't be executed. Sure, you can add some `module_init()` or something like that, but this way you would miss the whole point of **driver**, reducing it to just some dull module. Yes, you should do one step at a time, but I'd argue that the order is off. First, create device tree and initial code for your platform, and only then develop your driver. [See this for details](http://free-electrons.com/pub/conferences/2015/captronic/captronic-porting-linux-on-arm.pdf#f). – Sam Protsenko Oct 24 '16 at 22:09

1 Answers1

4

Take a look at the Makefile in the same directory. For mach-mx31ads.c, it has,

# i.MX31 based machines
 obj-$(CONFIG_MACH_MX31ADS) += mach-mx31ads.o

The Kconfig has a corresponding entry,

 config MACH_MX31ADS
         bool "Support MX31ADS platforms"
         default y
         select IMX_HAVE_PLATFORM_IMX_I2C
         select IMX_HAVE_PLATFORM_IMX_SSI
         select IMX_HAVE_PLATFORM_IMX_UART
         select SOC_IMX31
         help
           Include support for MX31ADS platform. This includes specific
           configurations for the board and its peripherals.

Adding these will give your board a Kconfig menu item and build the file. The only other missing piece is a machine type. You need to add this to arm/tools/mach-type which is processed by the kernel makefile, using the gen-mach-types script, to create a generated/mach-type.h. You use this in your board file to create a static machine description (put in a special section).

 MACHINE_START(MX31ADS, "Freescale MX31ADS")
         /* Maintainer: Freescale Semiconductor, Inc. */
         .atag_offset = 0x100,
         .map_io = mx31ads_map_io,
         .init_early = imx31_init_early,
         .init_irq = mx31ads_init_irq,
         .init_time      = mx31ads_timer_init,
         .init_machine = mx31ads_init,
         .restart        = mxc_restart,
 MACHINE_END

The machine_desc structure is found in arch.h. You don't need to add all the elements as they won't be called if not present. The kernel init looks a the machine ATAG and iterates through the sections to match the machine that the boot loader passes in. Locating the machine_desc is done in assembler very early in the linux boot.

artless noise
  • 21,212
  • 6
  • 68
  • 105