extranotes
b) Reserve 1 Mbyte of kernel memory for your driver (Similar to PSTORE)
root@apalis-imx8:~$ cat /proc/iomem
....
8020_0000-83ffffff : System RAM
8028_0000-8161ffff : Kernel code
8162_0000-8188ffff : reserved
8189_0000-81a85fff : Kernel data
8640_0000-87ffffff : System RAM
9000_0000-901fffff : System RAM
9050_0000-91ffffff : System RAM
94c0_0000-94ffffff : System RAM
9540_0000-ffffffff : System RAM
9600_0000-d1ffffff : reserved
f960_3000-fd62afff : reserved
8_8000_0000-8ffffffff : System RAM
8_fae0_0000-8fb5fffff : reserved
8_fb7f_e000-8ff5fffff : reserved
8_ff6d_b000-8ff73afff : reserved
8_ff73_b000-8ff73bfff : reserved
8_ff73_c000-8ff7cbfff : reserved
8_ff7c_e000-8ff7cefff : reserved
8_ff7c_f000-8ff7d3fff : reserved
8_ff7d_4000-8ff7d4fff : reserved
8_ff7d_5000-8ffffffff : reserved
check available memory of 1 MB which is not reserved, e.g. 8_8000_0000
Now in device tree
pstore and ramoops
The ramoops driver allows us to store kernel oopses, the kernel console output and user messages in a reserved memory region inside RAM
configs:
CONFIG_PSTORE=y
CONFIG_PSTORE_CONSOLE=y
CONFIG_PSTORE_PMSG=y
CONFIG_PSTORE_RAM=y
device tree
reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
ranges;
ramoops@0x880000000 {
compatible = "ramoops";
reg = <0 0x880000000 0 0x100000>;
record-size = <0x4000>;
console-size = <0x4000>;
ftrace-size = <0x4000>;
};
};
or from cmdline
ramoops.mem_address=0x30000000 ramoops.mem_size=0x100000 memmap=0x100000$0x30000000
record-size - kernel dmesg
console-size - console output from the kernel
pmsg-size - user messages
After crash mount pstore
mount -t pstore pstore /mnt/
then
cat /mnt/dmesg-ramoops-0
and it will dump store dmesg
---------------------------------------------
DMA and cache
----------------------------------------------
https://stackoverflow.com/questions/8265657/how-does-copy-from-user-from-the-linux-kernel-work-internally
copy_from_user: copy user data to kernel
The implementation of copy_from_user() system call is done using two buffers from different address spaces:
The user-space buffer in user virtual address space.
The kernel-space buffer in kernel virtual address space.
When the copy_from_user() system call is invoked, data is copied from user buffer to kernel buffer.
implementation is here: arch/arm64/lib/copy_from_user.S
SYM_FUNC_START(__arch_copy_from_user)
add end, x0, x2
mov srcin, x1
#include "copy_template.S"
mov x0, #0 // Nothing to copy
ret
// Exception fixups
9997: cmp dst, dstin
b.ne 9998f
// Before being absolutely sure we couldn't copy anything, try harder
USER(9998f, ldtrb tmp1w, [srcin])
strb tmp1w, [dst], #1
9998: sub x0, end, dst // bytes not copied
ret
SYM_FUNC_END(__arch_copy_from_user)
EXPORT_SYMBOL(__arch_copy_from_user)
copy_to_user: copy kernel data to user
copy_to_user() works in exactly the same way, except that the source and destination addresses are swapped - it reads from kernel addresses and writes to userspace addresses.
The only check that is done in both is that the userspace address really is below the kernel/user split; there is no need to check for addresses belonging to other user processes, because copy_*_user() are called only in process context,
which means that all addresses are either kernel addresses or belong to the current process
implementation is here: arch/arm64/lib/copy_to_user.S
SYM_FUNC_START(__arch_copy_to_user)
add end, x0, x2
mov srcin, x1
#include "copy_template.S"
mov x0, #0
ret
// Exception fixups
9997: cmp dst, dstin
b.ne 9998f
// Before being absolutely sure we couldn't copy anything, try harder
ldrb tmp1w, [srcin]
USER(9998f, sttrb tmp1w, [dst])
add dst, dst, #1
9998: sub x0, end, dst // bytes not copied
ret
SYM_FUNC_END(__arch_copy_to_user)
EXPORT_SYMBOL(__arch_copy_to_user)
-----------------------------------------------------------------------
linux scheduler
https://blog.csdn.net/weixin_44390164/article/details/132253387?spm=1001.2101.3001.6650.5&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-5-132253387-blog-105787081.235%5Ev43%5Epc_blog_bottom_relevance_base1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-5-132253387-blog-105787081.235%5Ev43%5Epc_blog_bottom_relevance_base1
https://blog.csdn.net/wellt606/article/details/132331378?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-132331378-blog-132253387.235%5Ev43%5Epc_blog_bottom_relevance_base1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-132331378-blog-132253387.235%5Ev43%5Epc_blog_bottom_relevance_base1
-----------------------------------------------------------------------
system calls:
----------------------------------------------------------------------
Watchdog:
On Linux-based systems, the standard user space interface to the watchdog is the /dev/watchdog file,
through which a daemon will notify the kernel watchdog driver that the
user space is still alive. The watchdog starts right after the file is opened, and gets pinged
by periodically writing into this file.
When the notification occurs, the underlying driver will notify the watchdog device,
which will result in resetting its timeout; the watchdog will then wait for yet another
timeout duration prior to resetting the system. However, if for any reason the user
space does not perform the notification before the timeout is elapsed, the watchdog will
reset the system (causing a reboot).
--------------------------------------------------------------------
Linux Device Driver code to load another module: request_module
http://embeddedguruji.blogspot.com/2019/05/linux-device-driver-code-to-load.html
------------------------------------------------------------------
memory barrier
https://developer.arm.com/documentation/den0042/a/Memory-Ordering/Memory-barriers
-----------------------------------------------------------------
What kind of driver you have written
accelerometer, fuel guage as i2c client: https://github.com/tejasatgithub/Linux-i2c-client-driver/blob/master/src/i2c_client_driver.c
pwm driver for brightness
pstore driver
device tree manipulator driver
touch driver
bootinfo driver
Comments
Post a Comment