This shows you the differences between two versions of the page.
ass:laboratoare:04 [2023/07/22 00:24] florin.stancu |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Lab 04 - Linux kernel development ===== | ||
- | |||
- | ===== Objectives ===== | ||
- | |||
- | * Learn Linux kernel development basics; | ||
- | * Build your own Linux kernel module; | ||
- | * Understand userspace device types; | ||
- | * Use MMIO to communicate with the IMX UART peripheral! | ||
- | |||
- | ===== Contents ===== | ||
- | |||
- | {{page>:ass:laboratoare:04:tasks:nav&nofooter&noeditbutton}} | ||
- | |||
- | ===== Lecture ===== | ||
- | |||
- | No lecture available :( | ||
- | |||
- | ===== Tasks ===== | ||
- | |||
- | Let's build a Linux kernel module and load in onto our board! | ||
- | |||
- | ==== 00. Preparation ==== | ||
- | |||
- | First, you need to have the Linux source code for the same version of the kernel you're running your board on. | ||
- | |||
- | You can check the version by running ''uname -a'' on the imx8 device (we will use ''v6.4'' in our example). | ||
- | |||
- | Check your linux source code using ''git status'' to see if you're running the same one: | ||
- | <code> | ||
- | # git status | ||
- | HEAD detached at v6.4 | ||
- | </code> | ||
- | |||
- | If you need to recompile the kernel, check out the desired tag. | ||
- | |||
- | **Next (optional)**, it's going to be useful to have ssh installed inside the rootfs. | ||
- | |||
- | Use buildroot's ''menuconfig'' to install ''PACKAGE_OPENSSH'' (all of them). | ||
- | |||
- | In either case (kernel / buildroot recompilation), you will need to regenerate the [[:ass:laboratoare:02#task_d_-_fit_image|linux.itb image]] with your new binaries. | ||
- | |||
- | ==== 01. Your first kernel module? ==== | ||
- | |||
- | [[https://www.kernel.org/doc/html/latest/kbuild/modules.html|Read some of this]] and create your external module's makefile. | ||
- | |||
- | <note warning> | ||
- | **DO NOT FORGET** TO ADD ''ARCH=arm64'' to the kbuild make invocation! | ||
- | |||
- | If you don't do so, the kernel's ''.config'' will be reset and you'll probably need to recompile the kernel if you do anything more on the kernel tree. | ||
- | </note> | ||
- | |||
- | TODO | ||
- | |||
- | ==== 02. Making a simple character device ==== | ||
- | |||
- | [[https://www.google.com/search?q=linux+kernel+character+device+example|Google]] for some inspiration on Linux kernel sample character device modules. | ||
- | |||
- | Next: build it! | ||
- | |||
- | Upload it onto your board and test it using ''insmod''! | ||
- | |||
- | TODO | ||
- | |||
- | ==== 03. Writing to a serial device (UART) ==== | ||
- | |||
- | Download & read the [[https://drive.google.com/file/d/1_hOAcGqI9MfIomBiNO6H0EVqqU5Kj7yQ/view|i.MX8M's Reference Manual]], chapter **16.2**. | ||
- | //Ahem// not all of it, check the memory map / register definition for ''UTXD'' and ''UTS''. | ||
- | |||
- | Next, we will enhance our character device to print the using IMX UART peripheral using a simple MMIO interface. | ||
- | Useful resources for mapping, reading & writing IO memory: https://www.kernel.org/doc/html/latest/driver-api/device-io.html | ||
- | |||
- | TODO | ||