3842 views|3 replies

187

Posts

0

Resources
The OP
 

It is actually very simple to transplant the driver of Feiling embedded i.MX8MP development board [Copy link]

Engineers may need to transplant drivers when developing the Feiling embedded OKMX8MP-C development board . To prevent users from affecting the development progress due to not understanding the process of transplanting drivers, today I will take writing a hello driver as an example to demonstrate the process of transplanting drivers. Friends who have needs can refer to this method to operate by themselves.

01

Enter the drivers directory of the source code and create a directory called hello:

forlinx@ubuntu:~$  cd  /home/forlinx/work/OK8MP-linux-sdk/OK8MP-linux-kernel/driversforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$mkdir  hello

02

Enter the hello directory and create hello.c:forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$ cd helloforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$ vi hello.c

Write the following content in hello.c:

#include  <linux/init.h>#include  <linux/module.h>static  int hello_init(void){printk(KERN_ALERT  "Hello world\n");return  0;}static  void hello_exit(void){printk(KERN_ALERT  "Goodbye world\n");}module_init(hello_init);module_exit(hello_exit);MODULE_LICENSE("Dual  BSD/GPL");

Program meaning: insmod driver prints Hello world when mounted, rmmod driver prints Goodbye world when uninstalled

03

Create two files, Kconfig and Makefile, in this folder.

forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$  vi  Kconfig

Write the following content in the Kconfig file:

config  HAVE_HELLOtristate       "hello driver"helpThis  hello  driver  is  just  to  show  how  to  develop  driver  process.

This  driver  can  also  be  built  as  a  module.  If  so,  the  module will  be  called  .default  y#endmenu

This means that if CONFIG_HAVE_HELLO is enabled, the hellodrivers menu will be displayed in the kernel trimming configuration file and compiled into the kernel by default:

y: compile into the kernel

m: compile to module .ko file

n: indicates not to compile and not to enable.

forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$  vi  Kconfig

Write the following content in the Makefile:

obj-$(CONFIG_HAVE_HELLO)        +=      hello.o

Notice:

The name of the macro definition should be the same as that in Kconfig. Add the file name to be compiled at the end. Because the kernel will automatically add the prefix CONFIG, we also need to add CONFIG_ in front of the name here, indicating that when CONFIG_HAVE_HELLO is enabled, the file specified by the compilation rule is hello.c.

Give the three added files permissions:

forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$  chmod  777 hello.cforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$  chmod  777 Kconfigforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$  chmod  777 Makefile

04

Edit the top-level Kconfig and Makefile files of drivers.

forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers/hello$  cd  ..forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$  vi Kconfig

Write the following content in the Kconfig file:

source  "drivers/counter/Kconfig"source  "drivers/mxc/Kconfig"source  "drivers/hello/Kconfig"    //在endmenu前添加hello文件夹的配置文件解析endmenu

In this way, the configuration system will parse the Kconfig in the hello folder according to this configuration.

Edit the Makefile:

forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$  vi Makefile

Write the following content in the Makefile:

obj-$(CONFIG_COUNTER)           += counter/obj-y                           += mxc/obj-$(CONFIG_HAVE_HELLO)        +=      hello/     //在Makefile最后加入这一句

The purpose of this sentence is to find the source file when CONFIG_HAVE_HELLO is enabled. Combined with the module Makefile under the hello file, a hierarchical Makefile is formed. Note that the / is not missing. Adding the name of the custom folder here means compiling this folder into the kernel.

5

Start compiling:

forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/drivers$  cd ../..forlinx@ubuntu:~/work/OK8MP-linux-sdk$  .  /opt/fsl-imx-xwayland/5.4-zeus/environment-setup-aarch64-poky-linuxforlinx@ubuntu:~/work/OK8MP-linux-sdk$  .  environment-setup-aarch64-poky-linuxforlinx@ubuntu:~/work/OK8MP-linux-sdk$  cd  OK8MP-linux-kernelforlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel$  make modulesscripts/kconfig/conf --syncconfig Kconfigdrivers/hello/Kconfig:7:warning:  ignoring unsupported character ''drivers/hello/Kconfig:7:warning:  ignoring unsupported character ''drivers/hello/Kconfig:7:warning:  ignoring unsupported character ''drivers/hello/Kconfig:7:warning:  ignoring unsupported character ''** Restart config...*** Device Drivers*Trust the bootloader  to initialize Linux's CRNG (RANDOM_TRUST_BOOTLOADER) [N/y/?] nPlatform support for  Chrome hardware (transitional) (MFD_CROS_EC) [Y/n/m/?] yTrusted Execution  Environment support (TEE) [Y/n/m/?] yhello driver  (HAVE_HELLO) [Y/n/m/?] (NEW) m    //将hello驱动编译进内核就配置为mCALL   scripts/checksyscalls.shCALL   scripts/atomic/check-atomics.shCHK      include/generated/compile.hGZIP   kernel/config_data.gzCC     kernel/configs.o[…]LD      vmlinuxSORTEX  vmlinuxSYSMAP  System.mapBuilding modules,  stage 2.MODPOST 536 modulesCC [M] drivers/hello/hello.mod.oLD [M] drivers/hello/hello.ko

After the compilation is complete, you can see the compiled driver in the OK8MP-linux-kernel/drivers/hello directory:

forlinx@ubuntu:~/work/OK8MP-linux-sdk/OK8MP-linux-kernel/$  ls drivers/hellohello.c  hello.ko  hello.mod  hello.mod.c  hello.mod.o  hello.o  Kconfig  Makefile modules.order
6

Copy hello.ko to the development board using a USB flash drive or TF card for verification:

rootK8MP:~#cd/run/media/sda1///进入U盘的路径下root@OK8MP:/run/media/sda1#insmodhello.ko//挂载hello.ko[138.679964]Helloworld          //挂载驱动打印信息root@OK8MP:/run/media/sda1#rmmodhello.ko//卸载hello.ko[142.022115]Goodbyeworld //卸载驱动打印信息root@OK8MP:/run/media/sda1#

From the above test, we can see that the hello.ko driver can run normally.

The above is the process of writing and adding a driver by yourself, which I demonstrated to you. If you want to transplant a certain module, you can ask the module manufacturer for the ready-made driver .c file, and then configure Makefile and Kconfig according to the above steps.

This post is from ARM Technology

Latest reply

Thanks for sharing, I learned a lot, very good content, keep it up! ! ! !   Details Published on 2024-8-27 19:17
 

6841

Posts

11

Resources
2
 
Should this compilation be compiled together with the firmware, or should it be compiled separately? If it is compiled in full, will it take a long time?
This post is from ARM Technology
 
 
 

9

Posts

0

Resources
3
 

Thanks for sharing, I learned a lot!!

This post is from ARM Technology
 
 
 

419

Posts

0

Resources
4
 

Thanks for sharing, I learned a lot, very good content, keep it up! ! ! !

This post is from ARM Technology
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Design of synthetic frequency source using PLL technology

Abstract: This paper introduces the frequency division phase-locked frequency synthesis technology. Through the analysis ...

Smart Camera Structural Design--Physical Assembly

After fine-tuning various details, we made a sample of a light-curing 3D and a CNC aluminum alloy sample using a machini ...

Sign up for a gift! Rohde & Schwarz online seminar: Latest measurement techniques for phase noise and clock jitter

Phase noise is one of the key indicators to characterize frequency sources, and has a significant impact on the performa ...

Embedded Qt-Make a stopwatch

This post was last edited by DDZZ669 on 2022-8-7 15:55 Previous article: Embedded Qt - Write and run your first ARM-Qt ...

41 "Wanli" Raspberry Pi car - ROS learning (ROSBridge controls the little turtle)

This post was last edited by lb8820265 on 2022-11-3 22:29 Previously, we introduced how to control the turtle using t ...

RF PCB Design Issues

Top floor661870 Middle layer 1 GND661869 Bottom layer661871 The middle 2-layer power supply661872As shown in the pictur ...

Last three days to register and get a gift: 2023 Renesas Electronics MCU/MPU Industrial Application Technology Seminar

2023 Renesas Electronics MCU/MPU Industrial Application Technology Seminar is now open for registration~ The Renesas Ele ...

[National Technology Automotive MCU N32A455 Development Board] 2. Drive LCD screen

1. Development Board Test - Automotive Electronics Continuing from the previous article, my homework requires the use o ...

【Follow me Season 2 Episode 1】Task submission post

This post was last edited by Alohaq on 2024-9-2 00:30 1. Introduction The mainboard used in Follow me Season 2 Episode ...

【Follow me Season 2 Episode 1】Basic 1: Colorful LED Marquee

This post was last edited by crimsonsnow on 2024-9-1 19:42 Control onboard neopixel LED Use the neopixel extension libr ...

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list