feat(lab01): init skeleton
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
images
|
||||
buildroot-images
|
||||
solutions/*/app
|
||||
solutions/
|
||||
src/*/app
|
||||
.obj
|
||||
.deleted
|
||||
|
||||
@@ -36,3 +37,4 @@ solutions/**/build
|
||||
|
||||
boot-scripts/boot.cifs
|
||||
boot-scripts/boot.net
|
||||
|
||||
|
||||
14
src/.clang-format
Normal file
14
src/.clang-format
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
IndentWidth: 4
|
||||
---
|
||||
Language: Cpp
|
||||
ColumnLimit: 80
|
||||
BreakBeforeBraces: Custom
|
||||
AlignConsecutiveAssignments: true
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterFunction: true
|
||||
33
src/01-skeleton/.clangd
Normal file
33
src/01-skeleton/.clangd
Normal file
@@ -0,0 +1,33 @@
|
||||
CompileFlags:
|
||||
Add:
|
||||
# Architecture and cross-compilation
|
||||
- "--target=aarch64-linux-gnu"
|
||||
|
||||
# Exclude standard library
|
||||
- "-nostdinc"
|
||||
|
||||
# Mandatory kernel definitions
|
||||
- "-D__KERNEL__"
|
||||
- "-DMODULE"
|
||||
- "-DCONFIG_CC_HAS_K_CONSTRAINT=1"
|
||||
|
||||
# Force-included files
|
||||
- "-include"
|
||||
- "/buildroot/output/build/linux-5.15.148/include/linux/compiler-version.h"
|
||||
- "-include"
|
||||
- "/buildroot/output/build/linux-5.15.148/include/linux/kconfig.h"
|
||||
- "-include"
|
||||
- "/buildroot/output/build/linux-5.15.148/include/linux/compiler_types.h"
|
||||
|
||||
# Kernel include paths
|
||||
- "-I/buildroot/output/build/linux-5.15.148/arch/arm64/include"
|
||||
- "-I/buildroot/output/build/linux-5.15.148/arch/arm64/include/generated"
|
||||
- "-I/buildroot/output/build/linux-5.15.148/include"
|
||||
- "-I/buildroot/output/build/linux-5.15.148/arch/arm64/include/uapi"
|
||||
- "-I/buildroot/output/build/linux-5.15.148/arch/arm64/include/generated/uapi"
|
||||
- "-I/buildroot/output/build/linux-5.15.148/include/uapi"
|
||||
- "-I/buildroot/output/build/linux-5.15.148/include/generated/uapi"
|
||||
|
||||
# GCC compiler system include path
|
||||
- "-isystem"
|
||||
- "/buildroot/output/host/lib/gcc/aarch64-buildroot-linux-gnu/11.3.0/include"
|
||||
30
src/01-skeleton/Makefile
Normal file
30
src/01-skeleton/Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
export PATH := /buildroot/output/host/usr/sbin$\
|
||||
:/buildroot/output/host/usr/bin/$\
|
||||
:/buildroot/output/host/sbin$\
|
||||
:/buildroot/output/host/bin/$\
|
||||
:$(PATH)
|
||||
|
||||
# Part executed when called from kernel build system:
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
obj-m += mymodule.o ## name of the generated module
|
||||
|
||||
mymodule-objs := skeleton.o ## list of objects needed for that module
|
||||
CFLAGS_skeleton.o := -DDEBUG
|
||||
|
||||
# Part executed when called from standard make in module source directory:
|
||||
else
|
||||
include ../kernel_settings
|
||||
PWD := $(shell pwd)
|
||||
|
||||
all:
|
||||
$(MAKE) -C $(KDIR) M=$(PWD) ARCH=$(CPU) CROSS_COMPILE=$(TOOLS) modules
|
||||
|
||||
clean:
|
||||
$(MAKE) -C $(KDIR) M=$(PWD) clean
|
||||
echo $(PATH)
|
||||
|
||||
install:
|
||||
$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install
|
||||
|
||||
endif
|
||||
|
||||
31
src/01-skeleton/skeleton.c
Normal file
31
src/01-skeleton/skeleton.c
Normal file
@@ -0,0 +1,31 @@
|
||||
// skeleton.c
|
||||
#include <linux/module.h> // needed by all modules
|
||||
#include <linux/init.h> // needed for macros
|
||||
#include <linux/kernel.h> // needed for debugging
|
||||
|
||||
#include <linux/moduleparam.h> // needed for module parameters
|
||||
|
||||
static char* text = "dummy text";
|
||||
module_param(text, charp, 0664);
|
||||
static int elements = 1;
|
||||
module_param(elements, int, 0);
|
||||
|
||||
static int __init skeleton_init(void)
|
||||
{
|
||||
pr_info ("Linux module 01 skeleton loaded\n");
|
||||
pr_debug (" text: %s\n elements: %d\n", text, elements);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit skeleton_exit(void)
|
||||
{
|
||||
pr_info ("Linux module skeleton unloaded\n");
|
||||
}
|
||||
|
||||
module_init (skeleton_init);
|
||||
module_exit (skeleton_exit);
|
||||
|
||||
MODULE_AUTHOR ("Daniel Gachet <daniel.gachet@hefr.ch>");
|
||||
MODULE_DESCRIPTION ("Module skeleton");
|
||||
MODULE_LICENSE ("GPL");
|
||||
|
||||
5
src/Makefile
Normal file
5
src/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
DIRS=$(filter-out Makefile, $(wildcard *))
|
||||
|
||||
all clean install:
|
||||
for dir in $(DIRS); do $(MAKE) $@ -C $$dir; done
|
||||
|
||||
5
src/buildroot_path
Normal file
5
src/buildroot_path
Normal file
@@ -0,0 +1,5 @@
|
||||
export PATH := /buildroot/output/host/usr/sbin$\
|
||||
:/buildroot/output/host/usr/bin/$\
|
||||
:/buildroot/output/host/sbin$\
|
||||
:/buildroot/output/host/bin/$\
|
||||
:$(PATH)
|
||||
8
src/kernel_settings
Normal file
8
src/kernel_settings
Normal file
@@ -0,0 +1,8 @@
|
||||
CVER := aarch64-buildroot-linux-gnu-
|
||||
KVER := 5.15.148
|
||||
CPU := arm64
|
||||
|
||||
KDIR := /buildroot/output/build/linux-$(KVER)/
|
||||
TOOLS := /buildroot/output/host/usr/bin/$(CVER)
|
||||
MODPATH := /rootfs
|
||||
#MODPATH := /buildroot/output/target
|
||||
14
src/nanopi.cmake
Normal file
14
src/nanopi.cmake
Normal file
@@ -0,0 +1,14 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
|
||||
find_program(CMAKE_C_COMPILER aarch64-linux-gcc)
|
||||
find_program(CMAKE_CXX_COMPILER aarch64-linux-g++)
|
||||
set(CMAKE_FIND_ROOT_PATH /buildroot/output/host)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
set(CMAKE_C_FLAGS "-Wall -Wextra -g -O0 -MD -std=gnu17")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=cortex-a53 -funwind-tables")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -g -O0 -MD -std=gnu++17")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=cortex-a53 -funwind-tables")
|
||||
5
src/set_host_path
Normal file
5
src/set_host_path
Normal file
@@ -0,0 +1,5 @@
|
||||
export PATH := /buildroot/output/host/usr/sbin$\
|
||||
:/buildroot/output/host/usr/bin/$\
|
||||
:/buildroot/output/host/sbin$\
|
||||
:/buildroot/output/host/bin/$\
|
||||
:$(PATH)
|
||||
Reference in New Issue
Block a user