Initial commit
This commit is contained in:
23
.devcontainer/devcontainer.json
Normal file
23
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "csel",
|
||||||
|
"dockerComposeFile": "docker-compose.yml",
|
||||||
|
"service": "toolchain",
|
||||||
|
"workspaceFolder": "/workspace",
|
||||||
|
"shutdownAction": "stopCompose",
|
||||||
|
"remoteUser": "root",
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"settings": {},
|
||||||
|
"extensions": [
|
||||||
|
"ms-vscode-remote.remote-containers",
|
||||||
|
"ms-vscode-remote.remote-ssh",
|
||||||
|
"ms-vscode-remote.remote-ssh-edit",
|
||||||
|
"ms-vscode-remote.remote-wsl",
|
||||||
|
"ms-vscode.cpptools",
|
||||||
|
"ms-vscode.cpptools-extension-pack",
|
||||||
|
"dan-c-underwood.arm",
|
||||||
|
"editorconfig.editorconfig"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
55
.devcontainer/docker-compose.yml
Normal file
55
.devcontainer/docker-compose.yml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
services:
|
||||||
|
toolchain:
|
||||||
|
image: csel/toolchain
|
||||||
|
build:
|
||||||
|
context: toolchain
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
privileged: true
|
||||||
|
volumes:
|
||||||
|
- ..:/workspace:cached
|
||||||
|
- buildroot:/buildroot
|
||||||
|
- rootfs:/rootfs
|
||||||
|
- home:/root-home
|
||||||
|
|
||||||
|
# Overrides default command so things don't shut down after the process ends.
|
||||||
|
command: /bin/sh -c "while sleep 1000; do :; done"
|
||||||
|
|
||||||
|
samba:
|
||||||
|
image: dperson/samba
|
||||||
|
environment:
|
||||||
|
USERID: 0
|
||||||
|
GROUPID: 0
|
||||||
|
command: >-
|
||||||
|
-S
|
||||||
|
-u "root;toor"
|
||||||
|
-s "buildroot;/buildroot;no;no"
|
||||||
|
-s "rootfs;/rootfs;no;no"
|
||||||
|
-s "workspace;/workspace;no;no"
|
||||||
|
-s "home;/root-home;no;no"
|
||||||
|
-g "unix extensions = yes"
|
||||||
|
-g "vfs objects = catia fruit"
|
||||||
|
ports:
|
||||||
|
- "139:139"
|
||||||
|
- "1445:445"
|
||||||
|
volumes:
|
||||||
|
- ..:/workspace
|
||||||
|
- buildroot:/buildroot
|
||||||
|
- rootfs:/rootfs
|
||||||
|
- home:/root-home
|
||||||
|
|
||||||
|
tftp:
|
||||||
|
image: csel/tftp
|
||||||
|
build:
|
||||||
|
context: tftp
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
ports:
|
||||||
|
- "69:69/udp"
|
||||||
|
# - "10000-10010:10000-10010/udp"
|
||||||
|
volumes:
|
||||||
|
- buildroot:/buildroot
|
||||||
|
command: "dnsmasq --no-daemon --enable-tftp --tftp-root=/buildroot --tftp-no-blocksize --tftp-single-port --log-facility=- --log-dhcp"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
buildroot: {}
|
||||||
|
rootfs: {}
|
||||||
|
home: {}
|
||||||
11
.devcontainer/tftp/Dockerfile
Normal file
11
.devcontainer/tftp/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# https://github.com/devcontainers/images/tree/main/src/cpp
|
||||||
|
ARG VARIANT=ubuntu-24.04
|
||||||
|
FROM mcr.microsoft.com/devcontainers/base:${VARIANT}
|
||||||
|
|
||||||
|
EXPOSE 69/udp
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
export DEBIAN_FRONTEND=noninteractive && \
|
||||||
|
apt-get -y install --no-install-recommends \
|
||||||
|
dnsmasq \
|
||||||
|
tcpdump
|
||||||
31
.devcontainer/toolchain/Dockerfile
Normal file
31
.devcontainer/toolchain/Dockerfile
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# https://github.com/devcontainers/images/tree/main/src/cpp
|
||||||
|
ARG VARIANT=ubuntu-24.04
|
||||||
|
FROM mcr.microsoft.com/devcontainers/cpp:${VARIANT}
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
export DEBIAN_FRONTEND=noninteractive && \
|
||||||
|
apt-get -y install --no-install-recommends \
|
||||||
|
autoconf \
|
||||||
|
automake \
|
||||||
|
bc \
|
||||||
|
bison \
|
||||||
|
clang-format \
|
||||||
|
cpio \
|
||||||
|
device-tree-compiler \
|
||||||
|
file \
|
||||||
|
flex \
|
||||||
|
just \
|
||||||
|
libfl-dev \
|
||||||
|
libglib2.0-dev \
|
||||||
|
libssl-dev \
|
||||||
|
libubootenv-tool \
|
||||||
|
libyaml-dev \
|
||||||
|
mercurial \
|
||||||
|
python3-dev \
|
||||||
|
rsync \
|
||||||
|
swig \
|
||||||
|
u-boot-tools \
|
||||||
|
wget
|
||||||
|
|
||||||
|
COPY scripts/* /usr/local/bin/
|
||||||
|
RUN chmod +x /usr/local/bin/*
|
||||||
8
.devcontainer/toolchain/scripts/delete-buildroot.sh
Executable file
8
.devcontainer/toolchain/scripts/delete-buildroot.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
find /buildroot/ -maxdepth 1 -mindepth 1 -exec rm -rf -- {} +
|
||||||
8
.devcontainer/toolchain/scripts/delete-rootfs.sh
Executable file
8
.devcontainer/toolchain/scripts/delete-rootfs.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
find /rootfs/ -maxdepth 1 -mindepth 1 -exec rm -rf -- {} +
|
||||||
8
.devcontainer/toolchain/scripts/extract-rootfs.sh
Executable file
8
.devcontainer/toolchain/scripts/extract-rootfs.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
tar xf /buildroot/output/images/rootfs.tar -C /rootfs/
|
||||||
16
.devcontainer/toolchain/scripts/get-buildroot.sh
Executable file
16
.devcontainer/toolchain/scripts/get-buildroot.sh
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
git clone https://gitlab.com/buildroot.org/buildroot.git /buildroot
|
||||||
|
|
||||||
|
cd /buildroot
|
||||||
|
git checkout -b csel 2022.08.3
|
||||||
|
|
||||||
|
rsync -a /workspace/config/board/ /buildroot/board/
|
||||||
|
rsync -a /workspace/config/configs/ /buildroot/configs/
|
||||||
|
|
||||||
|
make csel_defconfig
|
||||||
34
.devcontainer/toolchain/scripts/get-go.sh
Executable file
34
.devcontainer/toolchain/scripts/get-go.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
GO_VERSION=1.24.1
|
||||||
|
|
||||||
|
remove_go() {
|
||||||
|
rm -rf /usr/local/go
|
||||||
|
rm -f /etc/profile.d/go.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
install_go() {
|
||||||
|
remove_go
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
|
||||||
|
if [ "$ARCH" = "x86_64" ]; then
|
||||||
|
ARCH="amd64"
|
||||||
|
elif [ "$ARCH" = "aarch64" ]; then
|
||||||
|
ARCH="arm64"
|
||||||
|
else
|
||||||
|
echo "Unsupported architecture: ${ARCH}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Installing Go ${GO_VERSION} for ${ARCH}"
|
||||||
|
curl -sSfL https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz | tar -C /usr/local -xz
|
||||||
|
echo "Go ${GO_VERSION} installed successfully"
|
||||||
|
echo "export PATH=\$PATH:/usr/local/go/bin" >> /etc/profile.d/go.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
install_go
|
||||||
32
.devcontainer/toolchain/scripts/get-zig.sh
Executable file
32
.devcontainer/toolchain/scripts/get-zig.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
ZIG_VERSION=0.14.0
|
||||||
|
|
||||||
|
remove_zig() {
|
||||||
|
rm -rf /usr/local/bin/zio
|
||||||
|
rm -rf /usr/local/lib/zig
|
||||||
|
rm -rf /usr/local/share/zig
|
||||||
|
}
|
||||||
|
|
||||||
|
install_zig() {
|
||||||
|
remove_zig
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
TMP=$(mktemp -d)
|
||||||
|
echo "Installing Zig ${ZIG_VERSION} for ${ARCH}"
|
||||||
|
echo "Downloading files to ${TMP}"
|
||||||
|
curl -sSfL https://ziglang.org/download/${ZIG_VERSION}/zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz | tar -xJ -C $TMP
|
||||||
|
cp -a $TMP/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig
|
||||||
|
cp -a $TMP/zig-linux-${ARCH}-${ZIG_VERSION}/lib /usr/local/lib/zig
|
||||||
|
mkdir -p /usr/local/share/zig
|
||||||
|
cp -a $TMP/zig-linux-${ARCH}-${ZIG_VERSION}/doc /usr/local/share/zig
|
||||||
|
cp -a $TMP/zig-linux-${ARCH}-${ZIG_VERSION}/README.md /usr/local/share/zig
|
||||||
|
cp -a $TMP/zig-linux-${ARCH}-${ZIG_VERSION}/LICENSE /usr/local/share/zig
|
||||||
|
# rm -rf $TMP
|
||||||
|
}
|
||||||
|
|
||||||
|
install_zig
|
||||||
8
.devcontainer/toolchain/scripts/sync-images.sh
Executable file
8
.devcontainer/toolchain/scripts/sync-images.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
rsync -rlt --progress --delete /buildroot/output/images/ /workspace/buildroot-images
|
||||||
34
.devcontainer/toolchain/scripts/sync-rootfs.sh
Normal file
34
.devcontainer/toolchain/scripts/sync-rootfs.sh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
SRC=/buildroot/output/target/
|
||||||
|
DST=/rootfs/
|
||||||
|
RSYNC_IGNORE=/workspace/rsyncignore
|
||||||
|
|
||||||
|
# Copy all non-existing files from SRC to DST
|
||||||
|
rsync -rlpgoD --itemize-changes \
|
||||||
|
--ignore-existing \
|
||||||
|
--exclude=THIS_IS_NOT_YOUR_ROOT_FILESYSTEM \
|
||||||
|
$SRC $DST
|
||||||
|
|
||||||
|
RSYNC_OPT=""
|
||||||
|
if [[ -f $RSYNC_IGNORE ]]; then
|
||||||
|
RSYNC_OPT="--exclude-from=$RSYNC_IGNORE"
|
||||||
|
echo "Using rsyncignore"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update all existing files in DST from SRC
|
||||||
|
rsync -crlpgoD --itemize-changes \
|
||||||
|
--exclude=/etc/ssh/** \
|
||||||
|
--exclude=/etc/hostname \
|
||||||
|
--exclude=/etc/group \
|
||||||
|
--exclude=/etc/passwd \
|
||||||
|
--exclude=/etc/shadow \
|
||||||
|
--exclude=/etc/fstab \
|
||||||
|
--exclude=/run/lock \
|
||||||
|
--exclude=THIS_IS_NOT_YOUR_ROOT_FILESYSTEM \
|
||||||
|
$RSYNC_OPT $SRC $DST
|
||||||
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
images
|
||||||
|
buildroot-images
|
||||||
|
src/*/app
|
||||||
|
.obj
|
||||||
|
.deleted
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
src/**/.Module.*
|
||||||
|
src/**/Module.symvers
|
||||||
|
src/**/.mymodule.*
|
||||||
|
src/**/mymodule.*
|
||||||
|
src/**/.modules.*
|
||||||
|
src/**/.*.cmd*
|
||||||
|
src/**/app
|
||||||
|
src/**/core
|
||||||
|
src/**/modules.order
|
||||||
|
src/**/.skeleton.*
|
||||||
|
|
||||||
|
src/**/*.o
|
||||||
|
src/**/*.dtb
|
||||||
|
src/**/*.ovl
|
||||||
|
|
||||||
|
src/02_modules/procstat/procstat
|
||||||
|
src/02_modules/procstat/procstat_s
|
||||||
|
|
||||||
|
src/03_drivers/sample01/main1
|
||||||
|
src/03_drivers/sample01/main2
|
||||||
|
src/03_drivers/sample01/main3
|
||||||
|
|
||||||
|
.zig-cache
|
||||||
|
|
||||||
|
src/**/build
|
||||||
|
|
||||||
|
/SOLUTION
|
||||||
30
.vscode/c_cpp_properties.json
vendored
Normal file
30
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/buildroot/output/host/bin/aarch64-linux-gcc",
|
||||||
|
"cStandard": "gnu17",
|
||||||
|
"cppStandard": "gnu++17",
|
||||||
|
"intelliSenseMode": "linux-gcc-arm64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Linux-Kernel",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"/buildroot/output/build/linux-headers-5.15.148/include",
|
||||||
|
"/buildroot/output/build/linux-headers-5.15.148/arch/arm64/include",
|
||||||
|
"/buildroot/output/build/linux-headers-5.15.148/arch/arm64/include/generated",
|
||||||
|
"/buildroot/output/build/linux-headers-5.15.148/**"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/buildroot/output/host/bin/aarch64-linux-gcc",
|
||||||
|
"cStandard": "gnu11",
|
||||||
|
"intelliSenseMode": "linux-gcc-arm64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
12
.vscode/extensions.json
vendored
Normal file
12
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"ms-vscode-remote.remote-containers",
|
||||||
|
"ms-vscode-remote.remote-ssh",
|
||||||
|
"ms-vscode-remote.remote-ssh-edit",
|
||||||
|
"ms-vscode-remote.remote-wsl",
|
||||||
|
"ms-vscode.cpptools",
|
||||||
|
"ms-vscode.cpptools-extension-pack",
|
||||||
|
"dan-c-underwood.arm",
|
||||||
|
"editorconfig.editorconfig"
|
||||||
|
]
|
||||||
|
}
|
||||||
39
README.md
Normal file
39
README.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Workspace for CSEL
|
||||||
|
|
||||||
|
> :warning: **Open this project in a Docker Container**
|
||||||
|
|
||||||
|
## Cheat Sheet for developers
|
||||||
|
|
||||||
|
Configure with the default settings:
|
||||||
|
|
||||||
|
```
|
||||||
|
cd /buildroot
|
||||||
|
make csel_defconfig
|
||||||
|
```
|
||||||
|
|
||||||
|
Make changes if you want:
|
||||||
|
|
||||||
|
```
|
||||||
|
make menuconfig
|
||||||
|
```
|
||||||
|
|
||||||
|
Build:
|
||||||
|
|
||||||
|
```
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
If you change the configuration and want to keep it in the workspace, do the following:
|
||||||
|
|
||||||
|
```
|
||||||
|
make savedefconfig
|
||||||
|
cp /buildroot/configs/csel_defconfig /workspace/config/configs/
|
||||||
|
```
|
||||||
|
|
||||||
|
When the build is done, copy the images from buildroot to the workspace
|
||||||
|
|
||||||
|
```
|
||||||
|
sync-images.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
You can now "burn" the Compact Flash using [BalenaEtcher](https://www.balena.io/etcher/)
|
||||||
6
config/board/friendlyarm/nanopi-neo-plus2/boot.cmd
Normal file
6
config/board/friendlyarm/nanopi-neo-plus2/boot.cmd
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
setenv bootargs console=ttyS0,115200 earlyprintk root=/dev/mmcblk2p2 rootwait
|
||||||
|
|
||||||
|
fatload mmc 0 $kernel_addr_r Image
|
||||||
|
fatload mmc 0 $fdt_addr_r nanopi-neo-plus2.dtb
|
||||||
|
|
||||||
|
booti $kernel_addr_r - $fdt_addr_r
|
||||||
41
config/board/friendlyarm/nanopi-neo-plus2/genimage.cfg
Normal file
41
config/board/friendlyarm/nanopi-neo-plus2/genimage.cfg
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
image boot.vfat {
|
||||||
|
vfat {
|
||||||
|
label = "boot"
|
||||||
|
files = {
|
||||||
|
"Image",
|
||||||
|
"nanopi-neo-plus2.dtb",
|
||||||
|
"boot.scr"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size = 64M
|
||||||
|
}
|
||||||
|
|
||||||
|
image sdcard.img {
|
||||||
|
hdimage {
|
||||||
|
}
|
||||||
|
|
||||||
|
partition spl {
|
||||||
|
in-partition-table = "no"
|
||||||
|
image = "sunxi-spl.bin"
|
||||||
|
offset = 8K
|
||||||
|
}
|
||||||
|
|
||||||
|
partition u-boot {
|
||||||
|
in-partition-table = "no"
|
||||||
|
image = "u-boot.itb"
|
||||||
|
offset = 40K
|
||||||
|
size = 1M # 1MB - 40KB
|
||||||
|
}
|
||||||
|
|
||||||
|
partition boot {
|
||||||
|
partition-type = 0xC
|
||||||
|
bootable = "true"
|
||||||
|
image = "boot.vfat"
|
||||||
|
}
|
||||||
|
|
||||||
|
partition rootfs {
|
||||||
|
partition-type = 0x83
|
||||||
|
image = "rootfs.ext4"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#
|
||||||
|
# wireless core
|
||||||
|
#
|
||||||
|
CONFIG_WIRELESS=y
|
||||||
|
CONFIG_CFG80211=y
|
||||||
|
CONFIG_MAC80211=y
|
||||||
|
CONFIG_CFG80211_WEXT=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# wireless drivers
|
||||||
|
#
|
||||||
|
CONFIG_WLAN=y
|
||||||
|
CONFIG_WLAN_VENDOR_BROADCOM=y
|
||||||
|
CONFIG_BRCMFMAC=m
|
||||||
|
|
||||||
|
#
|
||||||
|
# enable GPIO sysfs
|
||||||
|
#
|
||||||
|
CONFIG_EMBEDDED=y
|
||||||
|
CONFIG_GPIO_SYSFS=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# enable CIFS/SAMBA
|
||||||
|
#
|
||||||
|
CONFIG_CIFS=y
|
||||||
|
CONFIG_CIFS_XATTR=y
|
||||||
|
CONFIG_CIFS_POSIX=y
|
||||||
|
CONFIG_CIFS_ROOT=y
|
||||||
|
|
||||||
|
#
|
||||||
|
# network interface device drivers (to mount rootfs)
|
||||||
|
#
|
||||||
|
CONFIG_NET_VENDOR_STMICRO=y
|
||||||
|
CONFIG_STMMAC_ETH=y
|
||||||
|
CONFIG_STMMAC_PLATFORM=y
|
||||||
|
CONFIG_DWMAC_SUNXI=y
|
||||||
|
CONFIG_DWMAC_SUN8I=y
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
#include "allwinner/sun50i-h5-nanopi-neo-plus2.dts"
|
||||||
|
|
||||||
|
/ {
|
||||||
|
/delete-node/ leds;
|
||||||
|
};
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
diff --git a/services/std_svc/psci/psci_private.h b/services/std_svc/psci/psci_private.h
|
||||||
|
index 24a5604e7..806cfb4fb 100644
|
||||||
|
--- a/services/std_svc/psci/psci_private.h
|
||||||
|
+++ b/services/std_svc/psci/psci_private.h
|
||||||
|
@@ -101,7 +101,7 @@ void psci_acquire_afflvl_locks(int start_afflvl,
|
||||||
|
aff_map_node_t *mpidr_nodes[]);
|
||||||
|
void psci_release_afflvl_locks(int start_afflvl,
|
||||||
|
int end_afflvl,
|
||||||
|
- mpidr_aff_map_nodes_t mpidr_nodes);
|
||||||
|
+ aff_map_node_t *mpidr_nodes[]);
|
||||||
|
void psci_print_affinity_map(void);
|
||||||
|
void psci_set_max_phys_off_afflvl(uint32_t afflvl);
|
||||||
|
uint32_t psci_find_max_phys_off_afflvl(uint32_t start_afflvl,
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
*****************************************************
|
||||||
|
__ __ ____ _____ ____ ____ _____ _
|
||||||
|
| \/ / ___|| ____| / ___/ ___|| ____| |
|
||||||
|
| |\/| \___ \| _| _____| | \___ \| _| | |
|
||||||
|
| | | |___) | |__|_____| |___ ___) | |___| |___
|
||||||
|
|_| |_|____/|_____| \____|____/|_____|_____|
|
||||||
|
|
||||||
|
*****************************************************
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# interface file auto-generated by buildroot for CSEL
|
||||||
|
|
||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
|
||||||
|
auto eth0
|
||||||
|
iface eth0 inet static
|
||||||
|
address 192.168.53.14
|
||||||
|
netmask 255.255.255.0
|
||||||
|
gateway 192.168.53.4
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
# sshd_config for csel
|
||||||
|
|
||||||
|
# This is the sshd server system-wide configuration file. See
|
||||||
|
# sshd_config(5) for more information.
|
||||||
|
|
||||||
|
# This sshd was compiled with PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
||||||
|
|
||||||
|
# The strategy used for options in the default sshd_config shipped with
|
||||||
|
# OpenSSH is to specify options with their default value where
|
||||||
|
# possible, but leave them commented. Uncommented options override the
|
||||||
|
# default value.
|
||||||
|
|
||||||
|
#Port 22
|
||||||
|
#AddressFamily any
|
||||||
|
#ListenAddress 0.0.0.0
|
||||||
|
#ListenAddress ::
|
||||||
|
|
||||||
|
#HostKey /etc/ssh/ssh_host_rsa_key
|
||||||
|
#HostKey /etc/ssh/ssh_host_ecdsa_key
|
||||||
|
#HostKey /etc/ssh/ssh_host_ed25519_key
|
||||||
|
|
||||||
|
# Ciphers and keying
|
||||||
|
#RekeyLimit default none
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
#SyslogFacility AUTH
|
||||||
|
#LogLevel INFO
|
||||||
|
|
||||||
|
# Authentication:
|
||||||
|
|
||||||
|
#LoginGraceTime 2m
|
||||||
|
#PermitRootLogin prohibit-password
|
||||||
|
PermitRootLogin yes
|
||||||
|
#StrictModes yes
|
||||||
|
#MaxAuthTries 6
|
||||||
|
#MaxSessions 10
|
||||||
|
|
||||||
|
#PubkeyAuthentication yes
|
||||||
|
|
||||||
|
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
|
||||||
|
# but this is overridden so installations will only check .ssh/authorized_keys
|
||||||
|
AuthorizedKeysFile .ssh/authorized_keys
|
||||||
|
|
||||||
|
#AuthorizedPrincipalsFile none
|
||||||
|
|
||||||
|
#AuthorizedKeysCommand none
|
||||||
|
#AuthorizedKeysCommandUser nobody
|
||||||
|
|
||||||
|
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
|
||||||
|
#HostbasedAuthentication no
|
||||||
|
# Change to yes if you don't trust ~/.ssh/known_hosts for
|
||||||
|
# HostbasedAuthentication
|
||||||
|
#IgnoreUserKnownHosts no
|
||||||
|
# Don't read the user's ~/.rhosts and ~/.shosts files
|
||||||
|
#IgnoreRhosts yes
|
||||||
|
|
||||||
|
# To disable tunneled clear text passwords, change to no here!
|
||||||
|
#PasswordAuthentication yes
|
||||||
|
PermitEmptyPasswords yes
|
||||||
|
|
||||||
|
# Change to no to disable s/key passwords
|
||||||
|
#KbdInteractiveAuthentication yes
|
||||||
|
|
||||||
|
# Kerberos options
|
||||||
|
#KerberosAuthentication no
|
||||||
|
#KerberosOrLocalPasswd yes
|
||||||
|
#KerberosTicketCleanup yes
|
||||||
|
#KerberosGetAFSToken no
|
||||||
|
|
||||||
|
# GSSAPI options
|
||||||
|
#GSSAPIAuthentication no
|
||||||
|
#GSSAPICleanupCredentials yes
|
||||||
|
|
||||||
|
# Set this to 'yes' to enable PAM authentication, account processing,
|
||||||
|
# and session processing. If this is enabled, PAM authentication will
|
||||||
|
# be allowed through the KbdInteractiveAuthentication and
|
||||||
|
# PasswordAuthentication. Depending on your PAM configuration,
|
||||||
|
# PAM authentication via KbdInteractiveAuthentication may bypass
|
||||||
|
# the setting of "PermitRootLogin without-password".
|
||||||
|
# If you just want the PAM account and session checks to run without
|
||||||
|
# PAM authentication, then enable this but set PasswordAuthentication
|
||||||
|
# and KbdInteractiveAuthentication to 'no'.
|
||||||
|
#UsePAM no
|
||||||
|
|
||||||
|
#AllowAgentForwarding yes
|
||||||
|
#AllowTcpForwarding yes
|
||||||
|
#GatewayPorts no
|
||||||
|
#X11Forwarding no
|
||||||
|
#X11DisplayOffset 10
|
||||||
|
#X11UseLocalhost yes
|
||||||
|
#PermitTTY yes
|
||||||
|
#PrintMotd yes
|
||||||
|
#PrintLastLog yes
|
||||||
|
#TCPKeepAlive yes
|
||||||
|
#PermitUserEnvironment no
|
||||||
|
#Compression delayed
|
||||||
|
#ClientAliveInterval 0
|
||||||
|
#ClientAliveCountMax 3
|
||||||
|
#UseDNS no
|
||||||
|
#PidFile /var/run/sshd.pid
|
||||||
|
#MaxStartups 10:30:100
|
||||||
|
#PermitTunnel no
|
||||||
|
#ChrootDirectory none
|
||||||
|
#VersionAddendum none
|
||||||
|
|
||||||
|
# no default banner path
|
||||||
|
#Banner none
|
||||||
|
|
||||||
|
# override default of no subsystems
|
||||||
|
Subsystem sftp /usr/libexec/sftp-server
|
||||||
|
|
||||||
|
# Example of overriding settings on a per-user basis
|
||||||
|
#Match User anoncvs
|
||||||
|
# X11Forwarding no
|
||||||
|
# AllowTcpForwarding no
|
||||||
|
# PermitTTY no
|
||||||
|
# ForceCommand cvs server
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Save env to SD Card
|
||||||
|
CONFIG_ENV_FAT_DEVICE_AND_PART="0:auto"
|
||||||
110
config/configs/csel_defconfig
Normal file
110
config/configs/csel_defconfig
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
BR2_aarch64=y
|
||||||
|
BR2_ARM_FPU_VFPV4=y
|
||||||
|
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
|
||||||
|
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_15=y
|
||||||
|
BR2_PACKAGE_GLIBC_UTILS=y
|
||||||
|
BR2_TOOLCHAIN_BUILDROOT_CXX=y
|
||||||
|
BR2_PACKAGE_HOST_GDB=y
|
||||||
|
BR2_PACKAGE_HOST_GDB_TUI=y
|
||||||
|
BR2_PACKAGE_HOST_GDB_PYTHON3=y
|
||||||
|
BR2_GLOBAL_PATCH_DIR="board/friendlyarm/nanopi-neo-plus2/patches"
|
||||||
|
BR2_SSP_NONE=y
|
||||||
|
BR2_TARGET_GENERIC_HOSTNAME="csel"
|
||||||
|
BR2_TARGET_GENERIC_ISSUE="Welcome to FriendlyARM Nanopi NEO Plus2"
|
||||||
|
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y
|
||||||
|
BR2_ROOTFS_OVERLAY="board/friendlyarm/nanopi-neo-plus2/rootfs_overlay"
|
||||||
|
BR2_ROOTFS_POST_BUILD_SCRIPT="board/friendlyarm/nanopi-neo-plus2/post-build.sh"
|
||||||
|
BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
|
||||||
|
BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/friendlyarm/nanopi-neo-plus2/genimage.cfg"
|
||||||
|
BR2_LINUX_KERNEL=y
|
||||||
|
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
|
||||||
|
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.15.148"
|
||||||
|
BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y
|
||||||
|
BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/friendlyarm/nanopi-neo-plus2/linux-extras.config"
|
||||||
|
BR2_LINUX_KERNEL_DTS_SUPPORT=y
|
||||||
|
BR2_LINUX_KERNEL_INTREE_DTS_NAME="allwinner/sun50i-h5-nanopi-neo-plus2"
|
||||||
|
BR2_LINUX_KERNEL_CUSTOM_DTS_PATH="board/friendlyarm/nanopi-neo-plus2/nanopi-neo-plus2.dts"
|
||||||
|
BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT=y
|
||||||
|
BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
|
||||||
|
BR2_PACKAGE_LINUX_TOOLS_PERF=y
|
||||||
|
BR2_PACKAGE_LINUX_TOOLS_PERF_TUI=y
|
||||||
|
BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
|
||||||
|
BR2_PACKAGE_GDB=y
|
||||||
|
BR2_PACKAGE_GDB_SERVER=y
|
||||||
|
BR2_PACKAGE_GDB_DEBUGGER=y
|
||||||
|
BR2_PACKAGE_GDB_TUI=y
|
||||||
|
BR2_PACKAGE_LSOF=y
|
||||||
|
BR2_PACKAGE_LTRACE=y
|
||||||
|
BR2_PACKAGE_STRACE=y
|
||||||
|
BR2_PACKAGE_VALGRIND=y
|
||||||
|
BR2_PACKAGE_DOSFSTOOLS=y
|
||||||
|
BR2_PACKAGE_DOSFSTOOLS_FATLABEL=y
|
||||||
|
BR2_PACKAGE_DOSFSTOOLS_FSCK_FAT=y
|
||||||
|
BR2_PACKAGE_DOSFSTOOLS_MKFS_FAT=y
|
||||||
|
BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y
|
||||||
|
BR2_PACKAGE_E2TOOLS=y
|
||||||
|
BR2_PACKAGE_SSHFS=y
|
||||||
|
BR2_PACKAGE_LINUX_FIRMWARE=y
|
||||||
|
BR2_PACKAGE_LINUX_FIRMWARE_BRCM_BCM43XXX=y
|
||||||
|
BR2_PACKAGE_I2C_TOOLS=y
|
||||||
|
BR2_PACKAGE_UBOOT_TOOLS=y
|
||||||
|
BR2_PACKAGE_UBOOT_TOOLS_FIT_SUPPORT=y
|
||||||
|
BR2_PACKAGE_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT=y
|
||||||
|
BR2_PACKAGE_UBOOT_TOOLS_FIT_CHECK_SIGN=y
|
||||||
|
BR2_PACKAGE_MYSQL=y
|
||||||
|
BR2_PACKAGE_MARIADB=y
|
||||||
|
BR2_PACKAGE_SQLITE=y
|
||||||
|
BR2_PACKAGE_SQLITE_STAT4=y
|
||||||
|
BR2_PACKAGE_SQLITE_ENABLE_COLUMN_METADATA=y
|
||||||
|
BR2_PACKAGE_SQLITE_ENABLE_FTS3=y
|
||||||
|
BR2_PACKAGE_SQLITE_ENABLE_JSON1=y
|
||||||
|
BR2_PACKAGE_SQLITE_ENABLE_UNLOCK_NOTIFY=y
|
||||||
|
BR2_PACKAGE_SQLITE_SECURE_DELETE=y
|
||||||
|
BR2_PACKAGE_EXPAT=y
|
||||||
|
BR2_PACKAGE_JSON_C=y
|
||||||
|
BR2_PACKAGE_JSONCPP=y
|
||||||
|
BR2_PACKAGE_LIBYAML=y
|
||||||
|
BR2_PACKAGE_YAML_CPP=y
|
||||||
|
BR2_PACKAGE_IFUPDOWN=y
|
||||||
|
BR2_PACKAGE_IPTABLES=y
|
||||||
|
BR2_PACKAGE_IPTABLES_BPF_NFSYNPROXY=y
|
||||||
|
BR2_PACKAGE_IPTABLES_NFTABLES=y
|
||||||
|
BR2_PACKAGE_IPUTILS=y
|
||||||
|
BR2_PACKAGE_IW=y
|
||||||
|
BR2_PACKAGE_WIRELESS_TOOLS=y
|
||||||
|
BR2_PACKAGE_WIRELESS_TOOLS_LIB=y
|
||||||
|
BR2_PACKAGE_WPA_SUPPLICANT=y
|
||||||
|
BR2_PACKAGE_WPA_SUPPLICANT_CLI=y
|
||||||
|
BR2_PACKAGE_FILE=y
|
||||||
|
BR2_PACKAGE_COREUTILS=y
|
||||||
|
BR2_PACKAGE_HTOP=y
|
||||||
|
BR2_PACKAGE_PROCPS_NG=y
|
||||||
|
BR2_TARGET_ROOTFS_EXT2=y
|
||||||
|
BR2_TARGET_ROOTFS_EXT2_4=y
|
||||||
|
BR2_TARGET_ROOTFS_EXT2_SIZE="2G"
|
||||||
|
BR2_TARGET_ARM_TRUSTED_FIRMWARE=y
|
||||||
|
BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_GIT=y
|
||||||
|
BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_REPO_URL="https://github.com/apritzel/arm-trusted-firmware.git"
|
||||||
|
BR2_TARGET_ARM_TRUSTED_FIRMWARE_CUSTOM_REPO_VERSION="aa75c8da415158a94b82a430b2b40000778e851f"
|
||||||
|
BR2_TARGET_ARM_TRUSTED_FIRMWARE_PLATFORM="sun50iw1p1"
|
||||||
|
BR2_TARGET_UBOOT=y
|
||||||
|
BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y
|
||||||
|
BR2_TARGET_UBOOT_CUSTOM_VERSION=y
|
||||||
|
BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2020.10"
|
||||||
|
BR2_TARGET_UBOOT_BOARD_DEFCONFIG="nanopi_neo_plus2"
|
||||||
|
BR2_TARGET_UBOOT_CONFIG_FRAGMENT_FILES="board/friendlyarm/nanopi-neo-plus2/uboot-extras.config"
|
||||||
|
BR2_TARGET_UBOOT_NEEDS_DTC=y
|
||||||
|
BR2_TARGET_UBOOT_NEEDS_PYLIBFDT=y
|
||||||
|
BR2_TARGET_UBOOT_NEEDS_ATF_BL31=y
|
||||||
|
BR2_TARGET_UBOOT_FORMAT_CUSTOM=y
|
||||||
|
BR2_TARGET_UBOOT_FORMAT_CUSTOM_NAME="u-boot.itb"
|
||||||
|
BR2_TARGET_UBOOT_SPL=y
|
||||||
|
BR2_TARGET_UBOOT_SPL_NAME="spl/sunxi-spl.bin"
|
||||||
|
BR2_PACKAGE_HOST_DOSFSTOOLS=y
|
||||||
|
BR2_PACKAGE_HOST_GENIMAGE=y
|
||||||
|
BR2_PACKAGE_HOST_MTOOLS=y
|
||||||
|
BR2_PACKAGE_HOST_UBOOT_TOOLS=y
|
||||||
|
BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SUPPORT=y
|
||||||
|
BR2_PACKAGE_HOST_UBOOT_TOOLS_FIT_SIGNATURE_SUPPORT=y
|
||||||
|
BR2_PACKAGE_HOST_UBOOT_TOOLS_BOOT_SCRIPT=y
|
||||||
|
BR2_PACKAGE_HOST_UBOOT_TOOLS_BOOT_SCRIPT_SOURCE="board/friendlyarm/nanopi-neo-plus2/boot.cmd"
|
||||||
32
env-all.code-workspace
Normal file
32
env-all.code-workspace
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/backtrace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/core_dumps"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/daemon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/fibonacci"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/memory_leaks"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/process"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/system_calls"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/tracing"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
11
env-core_dumps.code-workspace
Normal file
11
env-core_dumps.code-workspace
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/core_dumps"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
11
env-fibonacci.code-workspace
Normal file
11
env-fibonacci.code-workspace
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/01_environment/fibonacci"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
||||||
16
modules-ex1.code-workspace
Normal file
16
modules-ex1.code-workspace
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "src/02_modules/exercice01"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"files.associations": {
|
||||||
|
"moduleparam.h": "c",
|
||||||
|
"ranges": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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
|
||||||
4
src/01_environment/Makefile
Normal file
4
src/01_environment/Makefile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
DIRS=$(filter-out Makefile appl.mk dot-vscode, $(wildcard *))
|
||||||
|
all clean clean_all:
|
||||||
|
for dir in $(DIRS); do $(MAKE) $@ -C $$dir; done
|
||||||
|
|
||||||
45
src/01_environment/appl.mk
Normal file
45
src/01_environment/appl.mk
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
CFLAGS=-Wall -Wextra -g -c -O0 -MD -std=gnu11
|
||||||
|
CFLAGS+=$(EXTRA_CFLAGS)
|
||||||
|
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CFLAGS+=-mcpu=cortex-a53 -funwind-tables
|
||||||
|
##CFLAGS+=-O2 -fno-omit-frame-pointer
|
||||||
|
OBJDIR=.obj/nano
|
||||||
|
EXEC=$(EXE)
|
||||||
|
|
||||||
|
ifeq ($(target),host)
|
||||||
|
EXEC=$(EXE)_h
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(TOOLCHAIN)gcc
|
||||||
|
LD=$(TOOLCHAIN)gcc
|
||||||
|
AR=$(TOOLCHAIN)ar
|
||||||
|
STRIP=$(TOOLCHAIN)strip
|
||||||
|
|
||||||
|
OBJDIR=.obj/$(target)
|
||||||
|
OBJS= $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
$(OBJDIR)/%o: %c
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: $(OBJDIR)/ $(EXEC)
|
||||||
|
|
||||||
|
$(EXEC): $(OBJS) $(LINKER_SCRIPT)
|
||||||
|
$(LD) $(OBJS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
$(OBJDIR)/:
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf $(OBJDIR) $(EXEC) $(EXEC)_s *~
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
rm -Rf .obj $(EXE) $(EXE)_s $(EXE)_a $(EXE)_a_s $(EXE)_h $(EXE)_h_s
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all clean clean_all
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
21
src/01_environment/backtrace/.vscode/launch.json
vendored
Normal file
21
src/01_environment/backtrace/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/backtrace/.vscode/tasks.json
vendored
Normal file
14
src/01_environment/backtrace/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
src/01_environment/backtrace/CMakeLists.txt
Normal file
5
src/01_environment/backtrace/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(backtrace)
|
||||||
|
|
||||||
|
include(../../nanopi.cmake)
|
||||||
|
add_executable(backtrace main.c)
|
||||||
5
src/01_environment/backtrace/Makefile
Normal file
5
src/01_environment/backtrace/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
EXE=app
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
# Include the standard application Makefile for the CSEL1 labs
|
||||||
|
include ../appl.mk
|
||||||
5
src/01_environment/backtrace/justfile
Normal file
5
src/01_environment/backtrace/justfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build:
|
||||||
|
cmake -S . -B build && cmake --build build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
63
src/01_environment/backtrace/main.c
Normal file
63
src/01_environment/backtrace/main.c
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Module: MA-CSEL1 - Building Embedded Systems under Linux
|
||||||
|
*
|
||||||
|
* Abstract: Introduction to the Embedded Linux Development Environment
|
||||||
|
*
|
||||||
|
* Purpose: Backtracing demo program.
|
||||||
|
*
|
||||||
|
* Autĥor: Daniel Gachet
|
||||||
|
* Date: 28.08.2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <execinfo.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#define SIZE 1000
|
||||||
|
|
||||||
|
void signal_handler(int __attribute__((unused)) sig)
|
||||||
|
{
|
||||||
|
void* buffer[SIZE];
|
||||||
|
int nptrs = backtrace(buffer, SIZE);
|
||||||
|
printf("backtrace() returned %d addresses\n", nptrs);
|
||||||
|
backtrace_symbols_fd (buffer, nptrs, STDOUT_FILENO);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void access_data()
|
||||||
|
{
|
||||||
|
int* p=0;
|
||||||
|
*p=10;
|
||||||
|
}
|
||||||
|
|
||||||
|
void call (int n)
|
||||||
|
{
|
||||||
|
if (n>0) call (n-1);
|
||||||
|
access_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
signal(SIGSEGV, signal_handler); // Invalid memory segment access
|
||||||
|
|
||||||
|
call(10);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
32
src/01_environment/core_dumps/.vscode/launch.json
vendored
Normal file
32
src/01_environment/core_dumps/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "(gdb) debug Core Dumped",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb",
|
||||||
|
"coreDumpPath": "${workspaceFolder}/core"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/core_dumps/.vscode/tasks.json
vendored
Normal file
14
src/01_environment/core_dumps/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
src/01_environment/core_dumps/CMakeLists.txt
Normal file
5
src/01_environment/core_dumps/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(core-dumps)
|
||||||
|
|
||||||
|
include(../../nanopi.cmake)
|
||||||
|
add_executable(core-dumps core_dumps.c)
|
||||||
5
src/01_environment/core_dumps/Makefile
Normal file
5
src/01_environment/core_dumps/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
EXE=app
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
# Include the standard application Makefile for the CSEL1 labs
|
||||||
|
include ../appl.mk
|
||||||
45
src/01_environment/core_dumps/core_dumps.c
Normal file
45
src/01_environment/core_dumps/core_dumps.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Module: MA-CSEL1 - Building Embedded Systems under Linux
|
||||||
|
*
|
||||||
|
* Abstract: Introduction to the Embedded Linux Development Environment
|
||||||
|
*
|
||||||
|
* Purpose: Core dump demo program.
|
||||||
|
* Before to call this demo program don't forget set
|
||||||
|
* $ ulimit -c 10000
|
||||||
|
*
|
||||||
|
* Autĥor: Daniel Gachet
|
||||||
|
* Date: 28.08.2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
void access_data()
|
||||||
|
{
|
||||||
|
int* p=0;
|
||||||
|
*p=10;
|
||||||
|
}
|
||||||
|
|
||||||
|
void call (int n)
|
||||||
|
{
|
||||||
|
if (n>0) call (n-1);
|
||||||
|
access_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
call(10);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
5
src/01_environment/core_dumps/justfile
Normal file
5
src/01_environment/core_dumps/justfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build:
|
||||||
|
cmake -S . -B build && cmake --build build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
21
src/01_environment/daemon/.vscode/launch.json
vendored
Normal file
21
src/01_environment/daemon/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/daemon/.vscode/tasks.json
vendored
Normal file
14
src/01_environment/daemon/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
src/01_environment/daemon/CMakeLists.txt
Normal file
5
src/01_environment/daemon/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(daemon)
|
||||||
|
|
||||||
|
include(../../nanopi.cmake)
|
||||||
|
add_executable(daemon daemon.c)
|
||||||
5
src/01_environment/daemon/Makefile
Normal file
5
src/01_environment/daemon/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
EXE=app
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
# Include the standard application Makefile for the CSEL1 labs
|
||||||
|
include ../appl.mk
|
||||||
24
src/01_environment/daemon/S60appl
Normal file
24
src/01_environment/daemon/S60appl
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Daemon application
|
||||||
|
#
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
/usr/local/app_a
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
killall app_a
|
||||||
|
;;
|
||||||
|
restart|reload)
|
||||||
|
killall app_a
|
||||||
|
/usr/local/app_a
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo $"Usage: $0 {start|stop|restart}"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "Daemon application launched"
|
||||||
|
|
||||||
|
exit $?
|
||||||
|
|
||||||
152
src/01_environment/daemon/daemon.c
Normal file
152
src/01_environment/daemon/daemon.c
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Module: MA-CSEL1 - Building Embedded Systems under Linux
|
||||||
|
*
|
||||||
|
* Abstract: Introduction to the Embedded Linux Development Environment
|
||||||
|
*
|
||||||
|
* Purpose: This module implements a simple daemon to be launched
|
||||||
|
* from a /etc/init.d/S??_* script
|
||||||
|
*
|
||||||
|
* Autĥor: Daniel Gachet
|
||||||
|
* Date: 28.08.2015
|
||||||
|
*/
|
||||||
|
#define _XOPEN_SOURCE 600
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <grp.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
|
|
||||||
|
static int signal_catched = 0;
|
||||||
|
|
||||||
|
static void catch_signal (int signal)
|
||||||
|
{
|
||||||
|
syslog (LOG_INFO, "signal=%d catched\n", signal);
|
||||||
|
signal_catched++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fork_process()
|
||||||
|
{
|
||||||
|
pid_t pid = fork();
|
||||||
|
switch (pid) {
|
||||||
|
case 0: break; // child process has been created
|
||||||
|
case -1: syslog (LOG_ERR, "ERROR while forking"); exit (1); break;
|
||||||
|
default: exit(0); // exit parent process with success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
UNUSED(argc); UNUSED(argv);
|
||||||
|
|
||||||
|
// 1. fork off the parent process
|
||||||
|
fork_process();
|
||||||
|
|
||||||
|
// 2. create new session
|
||||||
|
if (setsid() == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while creating new session");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. fork again to get rid of session leading process
|
||||||
|
fork_process();
|
||||||
|
|
||||||
|
// 4. capture all required signals
|
||||||
|
struct sigaction act = {.sa_handler = catch_signal,};
|
||||||
|
sigaction (SIGHUP, &act, NULL); // 1 - hangup
|
||||||
|
sigaction (SIGINT, &act, NULL); // 2 - terminal interrupt
|
||||||
|
sigaction (SIGQUIT, &act, NULL); // 3 - terminal quit
|
||||||
|
sigaction (SIGABRT, &act, NULL); // 6 - abort
|
||||||
|
sigaction (SIGTERM, &act, NULL); // 15 - termination
|
||||||
|
sigaction (SIGTSTP, &act, NULL); // 19 - terminal stop signal
|
||||||
|
|
||||||
|
// 5. update file mode creation mask
|
||||||
|
umask(0027);
|
||||||
|
|
||||||
|
// 6. change working directory to appropriate place
|
||||||
|
if (chdir ("/") == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while changing to working directory");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. close all open file descriptors
|
||||||
|
for (int fd = sysconf(_SC_OPEN_MAX); fd >= 0; fd--) {
|
||||||
|
close (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. redirect stdin, stdout and stderr to /dev/null
|
||||||
|
if (open ("/dev/null", O_RDWR) != STDIN_FILENO) {
|
||||||
|
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stdin");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (dup2 (STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO) {
|
||||||
|
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stdout");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (dup2 (STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO) {
|
||||||
|
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stderr");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. option: open syslog for message logging
|
||||||
|
openlog (NULL, LOG_NDELAY | LOG_PID, LOG_DAEMON);
|
||||||
|
syslog (LOG_INFO, "Daemon has started...");
|
||||||
|
|
||||||
|
// 10. option: get effective user and group id for appropriate's one
|
||||||
|
struct passwd* pwd = getpwnam ("daemon");
|
||||||
|
if (pwd == 0) {
|
||||||
|
syslog (LOG_ERR, "ERROR while reading daemon password file entry");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 11. option: change root directory
|
||||||
|
if (chroot (".") == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while changing to new root directory");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 12. option: change effective user and group id for appropriate's one
|
||||||
|
if (setegid (pwd->pw_gid) == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while setting new effective group id");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (seteuid (pwd->pw_uid) == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while setting new effective user id");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 13. implement daemon body...
|
||||||
|
int t = 30;
|
||||||
|
do {
|
||||||
|
t = sleep(t);
|
||||||
|
} while (t > 0);
|
||||||
|
|
||||||
|
syslog (LOG_INFO, "daemon stopped. Number of signals catched=%d\n", signal_catched);
|
||||||
|
closelog();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
5
src/01_environment/daemon/justfile
Normal file
5
src/01_environment/daemon/justfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build:
|
||||||
|
cmake -S . -B build && cmake --build build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
24
src/01_environment/dot-vscode/deploy.sh
Executable file
24
src/01_environment/dot-vscode/deploy.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
# set -o xtrace
|
||||||
|
|
||||||
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
__root="$(cd "$(dirname "${__dir}")" && pwd)"
|
||||||
|
|
||||||
|
targets="""
|
||||||
|
backtrace
|
||||||
|
core_dumps
|
||||||
|
daemon
|
||||||
|
fibonacci
|
||||||
|
memory_leaks
|
||||||
|
process
|
||||||
|
system_calls
|
||||||
|
tracing
|
||||||
|
"""
|
||||||
|
|
||||||
|
for i in $targets; do
|
||||||
|
mkdir -p $__root/$i/.vscode
|
||||||
|
cp $__dir/launch.json $__root/$i/.vscode
|
||||||
|
cp $__dir/tasks.json $__root/$i/.vscode
|
||||||
|
done
|
||||||
21
src/01_environment/dot-vscode/launch.json
Normal file
21
src/01_environment/dot-vscode/launch.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
43
src/01_environment/dot-vscode/launch.json_presque
Normal file
43
src/01_environment/dot-vscode/launch.json_presque
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "app",
|
||||||
|
"args": [
|
||||||
|
"2"
|
||||||
|
],
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// "miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
// "miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb",
|
||||||
|
"pipeTransport": {
|
||||||
|
// "pipeCwd": "/usr/bin",
|
||||||
|
"pipeProgram": "/usr/bin/ssh",
|
||||||
|
"pipeArgs": [
|
||||||
|
"root@192.168.0.14"
|
||||||
|
],
|
||||||
|
"debuggerPath": "/usr/bin/gdb"
|
||||||
|
// "debuggerPath": "stdbuf -i0 -o0 -e0 /usr/bin/gdb"
|
||||||
|
},
|
||||||
|
// "logging": {
|
||||||
|
// "engineLogging": true,
|
||||||
|
// },
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/dot-vscode/tasks.json
Normal file
14
src/01_environment/dot-vscode/tasks.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
1
src/01_environment/fibonacci/.gitignore
vendored
Normal file
1
src/01_environment/fibonacci/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
fibonacci
|
||||||
21
src/01_environment/fibonacci/.vscode/launch.json
vendored
Normal file
21
src/01_environment/fibonacci/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/fibonacci/.vscode/tasks.json
vendored
Normal file
14
src/01_environment/fibonacci/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app 2'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
src/01_environment/fibonacci/CMakeLists.txt
Normal file
5
src/01_environment/fibonacci/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(fibonacci)
|
||||||
|
|
||||||
|
include(../../nanopi.cmake)
|
||||||
|
add_executable(fibonacci fibonacci.c)
|
||||||
5
src/01_environment/fibonacci/Makefile
Normal file
5
src/01_environment/fibonacci/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
EXE=app
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
# Include the standard application Makefile for the CSEL1 labs
|
||||||
|
include ../appl.mk
|
||||||
88
src/01_environment/fibonacci/fibonacci.c
Normal file
88
src/01_environment/fibonacci/fibonacci.c
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Module: MA-CSEL1 - Building Embedded Systems under Linux
|
||||||
|
*
|
||||||
|
* Abstract: Introduction to the Embedded Linux Development Environment
|
||||||
|
*
|
||||||
|
* Purpose: Fibonacci numbers: a simple demo program to exercice debugging
|
||||||
|
* facilities on embedded Linux system.
|
||||||
|
*
|
||||||
|
* -->> tracing with printf
|
||||||
|
*
|
||||||
|
* Autĥor: Daniel Gachet
|
||||||
|
* Date: 28.08.2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Fibonacci numbers form a sequence of integers, mathematically defined by
|
||||||
|
* F(0)=0; F(1)=1; F(n) = F(n - 1) + F(n - 2) for n > 1.
|
||||||
|
*
|
||||||
|
* This results in the following sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,
|
||||||
|
* 21, 34, 55, 89, 144, 233, 377, 610, 987, ...
|
||||||
|
* so that each new number is the sum of the previous two, after seeding the
|
||||||
|
* sequence with the starting pair 0, 1.
|
||||||
|
*
|
||||||
|
* @param n value for which the Fibonacci number should be computed
|
||||||
|
* @return Fibonacci number
|
||||||
|
*/
|
||||||
|
long fibonacci_r(long n)
|
||||||
|
{
|
||||||
|
if (n <= 1)
|
||||||
|
return n;
|
||||||
|
return fibonacci_r(n - 1) + fibonacci_r(n - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
long fibonacci_i(long n)
|
||||||
|
{
|
||||||
|
long f0 = 0;
|
||||||
|
long f1 = 1;
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
f1 = f1 + f0;
|
||||||
|
f0 = f1 - f0; // WAT !!!
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
return f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main program computing the Fibonacci numbers for a given sequence starting
|
||||||
|
* from 0 to a number specified at the command line.
|
||||||
|
*/
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
long n = 0;
|
||||||
|
long i = 0;
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
n = atol(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s, %d, %s, %s\n", __FILE__, __LINE__, __DATE__, __TIME__);
|
||||||
|
printf("The first %ld Fibonacci numbers are:\n", n);
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
|
{
|
||||||
|
printf("%ld%s", fibonacci_i(i), i < n-1 ? ", " : "");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
5
src/01_environment/fibonacci/justfile
Normal file
5
src/01_environment/fibonacci/justfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build:
|
||||||
|
cmake -S . -B build && cmake --build build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
9
src/01_environment/justfile
Normal file
9
src/01_environment/justfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
build-all:
|
||||||
|
#!/bin/bash
|
||||||
|
for i in $(dirname */CMAkeLists.txt); do
|
||||||
|
cd $i && just build && cd ..
|
||||||
|
done
|
||||||
|
|
||||||
|
clean-all:
|
||||||
|
rm -Rf */build
|
||||||
|
|
||||||
21
src/01_environment/memory_leaks/.vscode/launch.json
vendored
Normal file
21
src/01_environment/memory_leaks/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/memory_leaks/.vscode/tasks.json
vendored
Normal file
14
src/01_environment/memory_leaks/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
src/01_environment/memory_leaks/CMakeLists.txt
Normal file
5
src/01_environment/memory_leaks/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(memory-leaks)
|
||||||
|
|
||||||
|
include(../../nanopi.cmake)
|
||||||
|
add_executable(memory-leaks mem_leaks.c)
|
||||||
5
src/01_environment/memory_leaks/Makefile
Normal file
5
src/01_environment/memory_leaks/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
EXE=app
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
# Include the standard application Makefile for the CSEL1 labs
|
||||||
|
include ../appl.mk
|
||||||
5
src/01_environment/memory_leaks/justfile
Normal file
5
src/01_environment/memory_leaks/justfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build:
|
||||||
|
cmake -S . -B build && cmake --build build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
113
src/01_environment/memory_leaks/mem_leaks.c
Normal file
113
src/01_environment/memory_leaks/mem_leaks.c
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Module: MA-CSEL1 - Building Embedded Systems under Linux
|
||||||
|
*
|
||||||
|
* Abstract: Introduction to the Embedded Linux Development Environment
|
||||||
|
*
|
||||||
|
* Purpose: Memory leak demo program
|
||||||
|
* call this demo program with
|
||||||
|
* $ valgrind --leak-check=full ./app_a
|
||||||
|
*
|
||||||
|
* Autĥor: Daniel Gachet
|
||||||
|
* Date: 28.08.2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define TRACE(x) printf x
|
||||||
|
#else
|
||||||
|
#define TRACE(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct alpha
|
||||||
|
{
|
||||||
|
int attr;
|
||||||
|
struct alpha* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void alloc1 (struct alpha** root)
|
||||||
|
{
|
||||||
|
static int cnt=0;
|
||||||
|
|
||||||
|
struct alpha* ele = malloc (sizeof(*ele));
|
||||||
|
ele->next = 0;
|
||||||
|
ele->attr = cnt++;
|
||||||
|
if (*root == 0) {
|
||||||
|
*root = ele;
|
||||||
|
} else {
|
||||||
|
struct alpha* n = *root;
|
||||||
|
while (n->next != 0) n = n->next;
|
||||||
|
n->next = ele;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void alloc2(struct alpha** root)
|
||||||
|
{
|
||||||
|
static int cnt=0;
|
||||||
|
|
||||||
|
struct alpha* ele = malloc (sizeof(*ele));
|
||||||
|
ele->next = 0;
|
||||||
|
ele->attr = cnt++;
|
||||||
|
if (*root == 0) {
|
||||||
|
*root = ele;
|
||||||
|
} else {
|
||||||
|
struct alpha* n = *root;
|
||||||
|
while (n->next != 0) n = n->next;
|
||||||
|
n->next = ele;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void alloc(struct alpha** root)
|
||||||
|
{
|
||||||
|
static int x=0;
|
||||||
|
|
||||||
|
if (x == 0) alloc1(root);
|
||||||
|
else alloc2 (root);
|
||||||
|
|
||||||
|
x = (x + 1) % 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dealloc(struct alpha** root)
|
||||||
|
{
|
||||||
|
struct alpha* ele = *root;
|
||||||
|
if (*root != 0) *root = ele->next;
|
||||||
|
free (ele);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
struct alpha* root = 0;
|
||||||
|
|
||||||
|
for (int i=0; i<4000; i++) alloc (&root);
|
||||||
|
|
||||||
|
struct alpha* p = root;
|
||||||
|
int i = 0;
|
||||||
|
while (p != 0) {
|
||||||
|
TRACE (("ele %2d, attr=%2d, ptr=%p\n", i, p->attr, p));
|
||||||
|
p = p->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<15; i++) dealloc (&root);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
21
src/01_environment/process/.vscode/launch.json
vendored
Normal file
21
src/01_environment/process/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/process/.vscode/tasks.json
vendored
Normal file
14
src/01_environment/process/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
src/01_environment/process/CMakeLists.txt
Normal file
5
src/01_environment/process/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(process)
|
||||||
|
|
||||||
|
include(../../nanopi.cmake)
|
||||||
|
add_executable(process process.c)
|
||||||
5
src/01_environment/process/Makefile
Normal file
5
src/01_environment/process/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
EXE=app
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
# Include the standard application Makefile for the CSEL1 labs
|
||||||
|
include ../appl.mk
|
||||||
5
src/01_environment/process/justfile
Normal file
5
src/01_environment/process/justfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build:
|
||||||
|
cmake -S . -B build && cmake --build build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
133
src/01_environment/process/process.c
Normal file
133
src/01_environment/process/process.c
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Module: MA-CSEL1 - Building Embedded Systems under Linux
|
||||||
|
*
|
||||||
|
* Abstract: Introduction to the Embedded Linux Development Environment
|
||||||
|
*
|
||||||
|
* Purpose: This module implements a simple application to be launched from
|
||||||
|
* /etc/inttab.
|
||||||
|
* -->> tracing with syslog
|
||||||
|
*
|
||||||
|
* Autĥor: Daniel Gachet
|
||||||
|
* Date: 28.08.2015
|
||||||
|
*/
|
||||||
|
#define _XOPEN_SOURCE 600
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <grp.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
|
|
||||||
|
static int signal_catched = 0;
|
||||||
|
|
||||||
|
static void catch_signal (int signal)
|
||||||
|
{
|
||||||
|
syslog (LOG_INFO, "signal=%d catched\n", signal);
|
||||||
|
signal_catched++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
UNUSED(argc); UNUSED(argv);
|
||||||
|
|
||||||
|
// daemon's steps 1 to 3 skipt
|
||||||
|
|
||||||
|
// 4. capture all required signals
|
||||||
|
struct sigaction act = {.sa_handler = catch_signal,};
|
||||||
|
sigaction (SIGHUP, &act, NULL); // 1 - hangup
|
||||||
|
sigaction (SIGINT, &act, NULL); // 2 - terminal interrupt
|
||||||
|
sigaction (SIGQUIT, &act, NULL); // 3 - terminal quit
|
||||||
|
sigaction (SIGABRT, &act, NULL); // 6 - abort
|
||||||
|
sigaction (SIGTERM, &act, NULL); // 15 - termination
|
||||||
|
sigaction (SIGTSTP, &act, NULL); // 19 - terminal stop signal
|
||||||
|
|
||||||
|
// 5. update file mode creation mask
|
||||||
|
umask(0027);
|
||||||
|
|
||||||
|
// 6. change working directory to appropriate place
|
||||||
|
if (chdir ("/") == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while changing to working directory");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. close all open file descriptors
|
||||||
|
for (int fd = sysconf(_SC_OPEN_MAX); fd >= 0; fd--) {
|
||||||
|
close (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. redirect stdin, stdout and stderr to /dev/null
|
||||||
|
if (open ("/dev/null", O_RDWR) != STDIN_FILENO) {
|
||||||
|
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stdin");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (dup2 (STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO) {
|
||||||
|
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stdout");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (dup2 (STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO) {
|
||||||
|
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stderr");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. option: open syslog for message logging
|
||||||
|
openlog (NULL, LOG_NDELAY | LOG_PID, LOG_DAEMON);
|
||||||
|
syslog (LOG_INFO, "Daemon has started...");
|
||||||
|
|
||||||
|
// 10. option: get effective user and group id for appropriate's one
|
||||||
|
struct passwd* pwd = getpwnam ("daemon");
|
||||||
|
if (pwd == 0) {
|
||||||
|
syslog (LOG_ERR, "ERROR while reading daemon password file entry");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 11. option: change root directory
|
||||||
|
if (chroot (".") == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while changing to new root directory");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 12. option: change effective user and group id for appropriate's one
|
||||||
|
if (setegid (pwd->pw_gid) == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while setting new effective group id");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
if (seteuid (pwd->pw_uid) == -1) {
|
||||||
|
syslog (LOG_ERR, "ERROR while setting new effective user id");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 13. implement daemon body...
|
||||||
|
int t = 30;
|
||||||
|
do {
|
||||||
|
t = sleep(t);
|
||||||
|
} while (t > 0);
|
||||||
|
|
||||||
|
syslog (LOG_INFO, "daemon stopped. Number of signals catched=%d\n", signal_catched);
|
||||||
|
closelog();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
21
src/01_environment/system_calls/.vscode/launch.json
vendored
Normal file
21
src/01_environment/system_calls/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/system_calls/.vscode/tasks.json
vendored
Normal file
14
src/01_environment/system_calls/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
src/01_environment/system_calls/CMakeLists.txt
Normal file
5
src/01_environment/system_calls/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project("system-calls")
|
||||||
|
|
||||||
|
include(../../nanopi.cmake)
|
||||||
|
add_executable("system-calls" syscall.c)
|
||||||
5
src/01_environment/system_calls/Makefile
Normal file
5
src/01_environment/system_calls/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
EXE=app
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
# Include the standard application Makefile for the CSEL1 labs
|
||||||
|
include ../appl.mk
|
||||||
5
src/01_environment/system_calls/justfile
Normal file
5
src/01_environment/system_calls/justfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build:
|
||||||
|
cmake -S . -B build && cmake --build build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
58
src/01_environment/system_calls/syscall.c
Normal file
58
src/01_environment/system_calls/syscall.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Module: MA-CSEL1 - Building Embedded Systems under Linux
|
||||||
|
*
|
||||||
|
* Abstract: Introduction to the Embedded Linux Development Environment
|
||||||
|
*
|
||||||
|
* Purpose: System call demo program
|
||||||
|
* call this demo program with
|
||||||
|
* # strace ./app_a
|
||||||
|
*
|
||||||
|
* Autĥor: Daniel Gachet
|
||||||
|
* Date: 28.08.2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int temp = 99000;
|
||||||
|
int f = open("/sys/class/thermal/thermal_zone0/temp", O_RDONLY);
|
||||||
|
if (f >= 0) {
|
||||||
|
char val[50] = "";
|
||||||
|
ssize_t r = read (f, val, sizeof(val));
|
||||||
|
close (f);
|
||||||
|
if (r > 0) {
|
||||||
|
temp = atoi(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf ("current temperature: %d.%02d degree Celcius\n",
|
||||||
|
temp/1000, (temp/10)%100);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
21
src/01_environment/tracing/.vscode/launch.json
vendored
Normal file
21
src/01_environment/tracing/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "(gdb) Launch",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/app",
|
||||||
|
"stopAtEntry": true,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerServerAddress": "192.168.0.14:1234",
|
||||||
|
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
14
src/01_environment/tracing/.vscode/tasks.json
vendored
Normal file
14
src/01_environment/tracing/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "gdbserver",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"ssh -t root@192.168.0.14 '/usr/bin/gdbserver :1234",
|
||||||
|
"${workspaceFolder}/app'"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
9
src/01_environment/tracing/CMakeLists.txt
Normal file
9
src/01_environment/tracing/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(tracing)
|
||||||
|
|
||||||
|
include(../../nanopi.cmake)
|
||||||
|
|
||||||
|
add_executable(fibonacci fibonacci.c)
|
||||||
|
add_executable(fibonacci-debug fibonacci.c)
|
||||||
|
|
||||||
|
target_compile_definitions(fibonacci-debug PRIVATE DEBUG)
|
||||||
9
src/01_environment/tracing/Makefile
Normal file
9
src/01_environment/tracing/Makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
EXE=app
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
ifneq ($(DEBUG),)
|
||||||
|
EXTRA_CFLAGS+=-DDEBUG
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Include the standard application Makefile for the CSEL1 labs
|
||||||
|
include ../appl.mk
|
||||||
79
src/01_environment/tracing/fibonacci.c
Normal file
79
src/01_environment/tracing/fibonacci.c
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Module: MA-CSEL1 - Building Embedded Systems under Linux
|
||||||
|
*
|
||||||
|
* Abstract: Introduction to the Embedded Linux Development Environment
|
||||||
|
*
|
||||||
|
* Purpose: Fibonacci numbers: a simple demo program to exercice debugging
|
||||||
|
* facilities on embedded Linux system.
|
||||||
|
*
|
||||||
|
* -->> tracing with conditional printf
|
||||||
|
*
|
||||||
|
* Autĥor: Daniel Gachet
|
||||||
|
* Date: 28.08.2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define TRACE(x) printf x
|
||||||
|
#else
|
||||||
|
#define TRACE(X)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Fibonacci numbers form a sequence of integers, mathematically defined by
|
||||||
|
* F(0)=0; F(1)=1; F(n) = F(n - 1) + F(n - 2) for n > 1.
|
||||||
|
*
|
||||||
|
* This results in the following sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,
|
||||||
|
* 21, 34, 55, 89, 144, 233, 377, 610, 987, ...
|
||||||
|
* so that each new number is the sum of the previous two, after seeding the
|
||||||
|
* sequence with the starting pair 0, 1.
|
||||||
|
*
|
||||||
|
* @param n value for which the Fibonacci number should be computed
|
||||||
|
* @return Fibonacci number
|
||||||
|
*/
|
||||||
|
long fibonacci(long n)
|
||||||
|
{
|
||||||
|
if (n <= 1) return n;
|
||||||
|
return fibonacci(n-1)+fibonacci(n-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main program computing the Fibonacci numbers for a given sequence starting
|
||||||
|
* from 0 to a number specified at the command line.
|
||||||
|
*/
|
||||||
|
int main (int argc, char** argv)
|
||||||
|
{
|
||||||
|
long n = 0;
|
||||||
|
long i = 0;
|
||||||
|
|
||||||
|
if (argc == 2) {
|
||||||
|
n = atol(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TRACE(("%s, %d, %s, %s\n", __FILE__, __LINE__, __DATE__, __TIME__));
|
||||||
|
printf("The first %ld Fibonacci numbers are:\n", n);
|
||||||
|
|
||||||
|
for (i=0; i<=n; i++) {
|
||||||
|
printf("%ld, ", fibonacci(i));
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
5
src/01_environment/tracing/justfile
Normal file
5
src/01_environment/tracing/justfile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
build:
|
||||||
|
cmake -S . -B build && cmake --build build
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
5
src/02_modules/Makefile
Normal file
5
src/02_modules/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
DIRS=$(filter-out Makefile, $(wildcard *))
|
||||||
|
|
||||||
|
all clean install:
|
||||||
|
for dir in $(DIRS); do $(MAKE) $@ -C $$dir; done
|
||||||
|
|
||||||
19
src/02_modules/exercice01/.vscode/c_cpp_properties.json
vendored
Normal file
19
src/02_modules/exercice01/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"/buildroot/output/build/linux-5.15.148/include",
|
||||||
|
"/buildroot/output/build/linux-5.15.148/arch/arm64/include",
|
||||||
|
"/buildroot/output/build/linux-5.15.148/arch/arm64/include/generated"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/usr/bin/clang",
|
||||||
|
"cStandard": "c99",
|
||||||
|
"cppStandard": "c++14",
|
||||||
|
"intelliSenseMode": "linux-clang-arm64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
30
src/02_modules/exercice01/Makefile
Normal file
30
src/02_modules/exercice01/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/02_modules/exercice01/skeleton.c
Normal file
31
src/02_modules/exercice01/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");
|
||||||
|
|
||||||
22
src/02_modules/exercice04/Makefile
Normal file
22
src/02_modules/exercice04/Makefile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Part executed when called from standard make in module source directory:
|
||||||
|
else
|
||||||
|
include ../../buildroot_path
|
||||||
|
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
|
||||||
|
|
||||||
|
install:
|
||||||
|
$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install
|
||||||
|
|
||||||
|
endif
|
||||||
16
src/02_modules/exercice04/host.mk
Normal file
16
src/02_modules/exercice04/host.mk
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
ifneq ($(KERNELRELEASE),)
|
||||||
|
obj-m += mymodule.o ## name of the generated module
|
||||||
|
|
||||||
|
mymodule-objs := skeleton.o ## list of objects needed for that module
|
||||||
|
|
||||||
|
else
|
||||||
|
KDIR := /lib/modules/$(shell uname -r)/build
|
||||||
|
PWD := $(shell pwd)
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(MAKE) -C $(KDIR) M=$(PWD) modules
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -C $(KDIR) M=$(PWD) clean
|
||||||
|
|
||||||
|
endif
|
||||||
64
src/02_modules/exercice04/skeleton.c
Normal file
64
src/02_modules/exercice04/skeleton.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/* 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 */
|
||||||
|
|
||||||
|
#include <linux/slab.h> /* needed for dynamic memory allocation */
|
||||||
|
#include <linux/list.h> /* needed for linked list processing */
|
||||||
|
#include <linux/string.h> /* needed for string handling */
|
||||||
|
|
||||||
|
static char* text = "dummy text";
|
||||||
|
module_param(text, charp, 0);
|
||||||
|
static int elements = 0;
|
||||||
|
module_param(elements, int, 0);
|
||||||
|
|
||||||
|
struct element {
|
||||||
|
char text[100];
|
||||||
|
int ele_nr;
|
||||||
|
struct list_head node;
|
||||||
|
};
|
||||||
|
|
||||||
|
static LIST_HEAD (my_list);
|
||||||
|
|
||||||
|
static int __init skeleton_init(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
pr_info ("Linux module 04 skeleton loaded\n");
|
||||||
|
pr_info (" text: %s\n elements: %d\n", text, elements);
|
||||||
|
for (i = 0; i < elements; i++) {
|
||||||
|
struct element* ele = kzalloc (sizeof(*ele), GFP_KERNEL);
|
||||||
|
if (ele != 0) {
|
||||||
|
strncpy (ele->text, text, 99);
|
||||||
|
ele->ele_nr = i;
|
||||||
|
list_add_tail (&ele->node, &my_list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __exit skeleton_exit(void)
|
||||||
|
{
|
||||||
|
struct element* ele;
|
||||||
|
int nb_eles = 0;
|
||||||
|
list_for_each_entry (ele, &my_list, node) {
|
||||||
|
pr_info ("ele [%d/%d/%d] = %s\n", nb_eles, ele->ele_nr, elements, ele->text);
|
||||||
|
nb_eles++;
|
||||||
|
}
|
||||||
|
while (!list_empty (&my_list)) {
|
||||||
|
ele = list_entry (my_list.next, struct element, node);
|
||||||
|
list_del (&ele->node);
|
||||||
|
kfree (ele);
|
||||||
|
}
|
||||||
|
pr_info ("All elements (%d/%d) of the list have been removed and deleted!\n", nb_eles, elements);
|
||||||
|
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");
|
||||||
|
|
||||||
23
src/02_modules/exercice05/Makefile
Normal file
23
src/02_modules/exercice05/Makefile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Part executed when called from standard make in module source directory:
|
||||||
|
else
|
||||||
|
include ../../buildroot_path
|
||||||
|
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
|
||||||
|
|
||||||
|
install:
|
||||||
|
$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
83
src/02_modules/exercice05/skeleton.c
Normal file
83
src/02_modules/exercice05/skeleton.c
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/* 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 */
|
||||||
|
|
||||||
|
#include <linux/slab.h> /* needed for dynamic memory allocation */
|
||||||
|
#include <linux/list.h> /* needed for linked list processing */
|
||||||
|
#include <linux/string.h> /* needed for string handling */
|
||||||
|
|
||||||
|
#include <linux/ioport.h> /* needed for memory region handling */
|
||||||
|
#include <linux/io.h> /* needed for mmio handling */
|
||||||
|
|
||||||
|
|
||||||
|
static struct resource* res[3]={[0]=0,};
|
||||||
|
|
||||||
|
static int __init skeleton_init(void)
|
||||||
|
{
|
||||||
|
unsigned char* regs[3]={[0]=0,};
|
||||||
|
unsigned int chipid[4]={[0]=0,};
|
||||||
|
long temp = 0;
|
||||||
|
unsigned int addr[2] = {[0]=0,};
|
||||||
|
|
||||||
|
pr_info ("Linux module 05 skeleton loaded\n");
|
||||||
|
|
||||||
|
res[0] = request_mem_region (0x01c14000, 0x1000, "allwiner h5 sid");
|
||||||
|
//res[1] = request_mem_region (0x01C25000, 0x1000, "allwiner h5 ths");
|
||||||
|
//res[2] = request_mem_region (0x01C30000, 0x1000, "allwiner h5 emac");
|
||||||
|
if ((res[0] == 0))// || (res[1] == 0) ||(res[2] == 0))
|
||||||
|
pr_info ("Error while reserving memory region... [0]=%d, [1]=%d, [2]=%d\n", res[0]==0, res[1]==0, res[2]==0);
|
||||||
|
|
||||||
|
regs[0] = ioremap (0x01c14000, 0x1000);
|
||||||
|
regs[1] = ioremap (0x01C25000, 0x1000);
|
||||||
|
regs[2] = ioremap (0x01C30000, 0x1000);
|
||||||
|
|
||||||
|
if ((regs[0] == 0) || (regs[1] == 0) ||(regs[2] == 0)) {
|
||||||
|
pr_info ("Error while trying to map processor register...\n");
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
chipid[0] = ioread32 (regs[0]+0x200);
|
||||||
|
chipid[1] = ioread32 (regs[0]+0x204);
|
||||||
|
chipid[2] = ioread32 (regs[0]+0x208);
|
||||||
|
chipid[3] = ioread32 (regs[0]+0x20c);
|
||||||
|
pr_info("chipid=%08x'%08x'%08x'%08x\n",
|
||||||
|
chipid[0], chipid[1], chipid[2], chipid[3]);
|
||||||
|
|
||||||
|
temp = -1191 * (int)ioread32(regs[1]+0x80) / 10 + 223000;
|
||||||
|
pr_info ("temperature=%ld (%d)\n", temp, ioread32(regs[1]+0x80));
|
||||||
|
|
||||||
|
addr[0]=ioread32(regs[2]+0x50);
|
||||||
|
addr[1]=ioread32(regs[2]+0x54);
|
||||||
|
pr_info("mac-addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||||
|
(addr[1]>> 0) & 0xff,
|
||||||
|
(addr[1]>> 8) & 0xff,
|
||||||
|
(addr[1]>>16) & 0xff,
|
||||||
|
(addr[1]>>24) & 0xff,
|
||||||
|
(addr[0]>> 0) & 0xff,
|
||||||
|
(addr[0]>> 8) & 0xff
|
||||||
|
);
|
||||||
|
|
||||||
|
iounmap (regs[0]);
|
||||||
|
iounmap (regs[1]);
|
||||||
|
iounmap (regs[2]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __exit skeleton_exit(void)
|
||||||
|
{
|
||||||
|
pr_info ("Linux module skeleton unloaded\n");
|
||||||
|
if (res[0] != 0) release_mem_region (0x01c14000, 0x1000);
|
||||||
|
//release_mem_region (0x01C25000, 0x1000);
|
||||||
|
//release_mem_region (0x01C30000, 0x1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
module_init (skeleton_init);
|
||||||
|
module_exit (skeleton_exit);
|
||||||
|
|
||||||
|
MODULE_AUTHOR ("Daniel Gachet <daniel.gachet@hefr.ch>");
|
||||||
|
MODULE_DESCRIPTION ("Module skeleton");
|
||||||
|
MODULE_LICENSE ("GPL");
|
||||||
|
|
||||||
24
src/02_modules/exercice06/Makefile
Normal file
24
src/02_modules/exercice06/Makefile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Part executed when called from standard make in module source directory:
|
||||||
|
else
|
||||||
|
include ../../buildroot_path
|
||||||
|
include ../../kernel_settings
|
||||||
|
include ../../set_host_path
|
||||||
|
PWD := $(shell pwd)
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(MAKE) -C $(KDIR) M=$(PWD) ARCH=$(CPU) CROSS_COMPILE=$(TOOLS) modules
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -C $(KDIR) M=$(PWD) clean
|
||||||
|
|
||||||
|
install:
|
||||||
|
$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
55
src/02_modules/exercice06/skeleton.c
Normal file
55
src/02_modules/exercice06/skeleton.c
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* 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 */
|
||||||
|
|
||||||
|
#include <linux/slab.h> /* needed for dynamic memory allocation */
|
||||||
|
#include <linux/list.h> /* needed for linked list processing */
|
||||||
|
#include <linux/string.h> /* needed for string handling */
|
||||||
|
|
||||||
|
#include <linux/ioport.h> /* needed for memory region handling */
|
||||||
|
#include <linux/io.h> /* needed for mmio handling */
|
||||||
|
|
||||||
|
#include <linux/kthread.h> /* needed for kernel thread management */
|
||||||
|
#include <linux/delay.h> /* needed for delay fonctions */
|
||||||
|
|
||||||
|
|
||||||
|
static struct task_struct* my_thread;
|
||||||
|
|
||||||
|
|
||||||
|
static int skeleton_thread (void* data)
|
||||||
|
{
|
||||||
|
pr_info ("skeleton thread is now active...\n");
|
||||||
|
while(!kthread_should_stop()) {
|
||||||
|
ssleep (5);
|
||||||
|
pr_info ("skeleton thread is kick every 5 seconds...\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int __init skeleton_init(void)
|
||||||
|
{
|
||||||
|
pr_info ("Linux module 06 skeleton loaded\n");
|
||||||
|
|
||||||
|
my_thread = kthread_run (skeleton_thread, 0, "s/thread");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __exit skeleton_exit(void)
|
||||||
|
{
|
||||||
|
kthread_stop (my_thread);
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
23
src/02_modules/exercice07/Makefile
Normal file
23
src/02_modules/exercice07/Makefile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Part executed when called from standard make in module source directory:
|
||||||
|
else
|
||||||
|
include ../../buildroot_path
|
||||||
|
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
|
||||||
|
|
||||||
|
install:
|
||||||
|
$(MAKE) -C $(KDIR) M=$(PWD) INSTALL_MOD_PATH=$(MODPATH) modules_install
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user