mirror of
https://github.com/polhenarejos/pico-rng.git
synced 2026-04-09 17:25:51 +02:00
Added linux kernel module
This commit is contained in:
@@ -3,9 +3,11 @@ cmake_minimum_required(VERSION 3.13)
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
project(pico_rng C CXX ASM)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
pico_sdk_init()
|
||||
|
||||
add_subdirectory(firmware)
|
||||
add_subdirectory(driver)
|
||||
|
||||
49
driver/CMakeLists.txt
Normal file
49
driver/CMakeLists.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
project(pico_rng_driver LANGUAGES C)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Find kernel headers
|
||||
execute_process(
|
||||
COMMAND uname -r
|
||||
OUTPUT_VARIABLE KERNEL_RELEASE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
# Find the headers
|
||||
find_path(KERNELHEADERS_DIR
|
||||
include/linux/user.h
|
||||
PATHS /usr/src/linux-headers-${KERNEL_RELEASE}
|
||||
)
|
||||
|
||||
message(STATUS "Kernel release: ${KERNEL_RELEASE}")
|
||||
message(STATUS "Kernel headers: ${KERNELHEADERS_DIR}")
|
||||
|
||||
if (KERNELHEADERS_DIR)
|
||||
set(KERNELHEADERS_INCLUDE_DIRS
|
||||
${KERNELHEADERS_DIR}/include
|
||||
${KERNELHEADERS_DIR}/arch/x86/include
|
||||
CACHE PATH "Kernel headers include dirs"
|
||||
)
|
||||
set(KERNELHEADERS_FOUND 1 CACHE STRING "Set to 1 if kernel headers were found")
|
||||
else (KERNELHEADERS_DIR)
|
||||
set(KERNELHEADERS_FOUND 0 CACHE STRING "Set to 1 if kernel headers were found")
|
||||
endif (KERNELHEADERS_DIR)
|
||||
|
||||
mark_as_advanced(KERNELHEADERS_FOUND)
|
||||
|
||||
#find_package(KernelHeaders REQUIRED)
|
||||
include_directories(${KERNELHEADERS_INCLUDE_DIRS})
|
||||
|
||||
set(DRIVER_FILE pico_rng.ko)
|
||||
set(KBUILD_CMD $(MAKE) -C ${KERNELHEADERS_DIR} modules M=${CMAKE_CURRENT_BINARY_DIR} src=${CMAKE_CURRENT_SOURCE_DIR})
|
||||
#FILE(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/Kbuild "obj-m := pico_rng.o")
|
||||
|
||||
add_custom_command(OUTPUT ${DRIVER_FILE}
|
||||
COMMAND ${KBUILD_CMD}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS pico_rng.c VERBATIM)
|
||||
|
||||
add_custom_target(pico_rng_driver ALL DEPENDS ${DRIVER_FILE})
|
||||
|
||||
1
driver/Kbuild
Normal file
1
driver/Kbuild
Normal file
@@ -0,0 +1 @@
|
||||
obj-m := pico_rng.o
|
||||
23
driver/pico_rng.c
Normal file
23
driver/pico_rng.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Mickey Malone");
|
||||
MODULE_DESCRIPTION("Random number generator using a Raspberry Pi Pico");
|
||||
MODULE_VERSION("1.0");
|
||||
|
||||
static int __init driver_init(void)
|
||||
{
|
||||
printk(KERN_INFO "Raspberry Pi Pico RNG\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit driver_exit(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
module_init(driver_init);
|
||||
module_exit(driver_exit);
|
||||
|
||||
Reference in New Issue
Block a user