1
0

Initial commit

This commit is contained in:
Jacques Supcik
2022-02-24 00:00:47 +01:00
commit 2eeb71e110
59 changed files with 1769 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
{
"name": "csel",
"dockerComposeFile": "docker-compose.yml",
"service": "toolchain",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose",
"settings": {},
"extensions": [
"ms-vscode.cpptools"
]
}

View File

@@ -0,0 +1,44 @@
services:
toolchain:
image: csel/toolchain
build:
context: toolchain
dockerfile: Dockerfile
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
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"
ports:
- "139:139"
- "1445:445"
volumes:
- ..:/workspace:cached
- buildroot:/buildroot
- rootfs:/rootfs
- home:/root-home
volumes:
buildroot: {}
rootfs: {}
home: {}

View File

@@ -0,0 +1,32 @@
{
"folders": [
{
"path": ".."
},
{
"path": "../src/backtrace"
},
{
"path": "../src/core_dumps"
},
{
"path": "../src/daemon"
},
{
"path": "../src/fibonacci"
},
{
"path": "../src/memory_leaks"
},
{
"path": "../src/process"
},
{
"path": "../src/system_calls"
},
{
"path": "../src/tracing"
}
],
"settings": {}
}

View File

@@ -0,0 +1,29 @@
# [Choice] Debian / Ubuntu version (use Debian 11, Ubuntu 18.04/21.04 on local arm64/Apple Silicon): debian-11, debian-10, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
ARG VARIANT=ubuntu-21.04
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
RUN apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get -y install --no-install-recommends \
autoconf \
automake \
bc \
bison \
cpio \
device-tree-compiler \
file \
flex \
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/*

View 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 -- {} +

View 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 -- {} +

View 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/

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
git clone git://git.buildroot.net/buildroot /buildroot
rsync -a /workspace/config/board/ /buildroot/board/
rsync -a /workspace/config/configs/ /buildroot/configs/
cd /buildroot
git checkout -b csel 2021.11.1
make csel_defconfig

View 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

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
images
buildroot-images
src/*/app
.obj

12
.vscode/extensions.json vendored Normal file
View 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
View 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/)

View 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

View 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"
}
}

View File

@@ -0,0 +1,27 @@
# 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

View File

@@ -0,0 +1,7 @@
/dts-v1/;
#include "allwinner/sun50i-h5-nanopi-neo-plus2.dts"
/ {
/delete-node/ leds;
};

View File

@@ -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.0.14
netmask 255.255.255.0
gateway 192.168.0.4

View File

@@ -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

View File

@@ -0,0 +1,2 @@
# Save env to SD Card
CONFIG_ENV_FAT_DEVICE_AND_PART="0:auto"

View File

@@ -0,0 +1,109 @@
BR2_aarch64=y
BR2_ARM_FPU_VFPV4=y
BR2_SSP_NONE=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=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_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.21"
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.07"
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_PYTHON3=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"

4
src/Makefile Normal file
View 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/appl.mk Normal file
View 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/backtrace/.vscode/launch.json vendored Normal file
View 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/backtrace/.vscode/tasks.json vendored Normal file
View 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/backtrace/Makefile Normal file
View File

@@ -0,0 +1,5 @@
EXE=app
SRCS=$(wildcard *.c)
# Include the standard application Makefile for the CSEL1 labs
include ../appl.mk

63
src/backtrace/main.c Normal file
View 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;
}

21
src/core_dumps/.vscode/launch.json vendored Normal file
View 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/core_dumps/.vscode/tasks.json vendored Normal file
View 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/core_dumps/Makefile Normal file
View File

@@ -0,0 +1,5 @@
EXE=app
SRCS=$(wildcard *.c)
# Include the standard application Makefile for the CSEL1 labs
include ../appl.mk

View 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;
}

21
src/daemon/.vscode/launch.json vendored Normal file
View 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/daemon/.vscode/tasks.json vendored Normal file
View 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/daemon/Makefile Normal file
View File

@@ -0,0 +1,5 @@
EXE=app
SRCS=$(wildcard *.c)
# Include the standard application Makefile for the CSEL1 labs
include ../appl.mk

24
src/daemon/S60appl Normal file
View 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/daemon/daemon.c Normal file
View 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;
}

24
src/dot-vscode/deploy.sh Executable file
View 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

View 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"
}
]
}

View 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/dot-vscode/tasks.json Normal file
View 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'"]
}
]
}

21
src/fibonacci/.vscode/launch.json vendored Normal file
View 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/fibonacci/.vscode/tasks.json vendored Normal file
View 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/fibonacci/Makefile Normal file
View File

@@ -0,0 +1,5 @@
EXE=app
SRCS=$(wildcard *.c)
# Include the standard application Makefile for the CSEL1 labs
include ../appl.mk

88
src/fibonacci/fibonacci.c Normal file
View 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;
}

21
src/memory_leaks/.vscode/launch.json vendored Normal file
View 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/memory_leaks/.vscode/tasks.json vendored Normal file
View 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'"]
}
]
}

View File

@@ -0,0 +1,5 @@
EXE=app
SRCS=$(wildcard *.c)
# Include the standard application Makefile for the CSEL1 labs
include ../appl.mk

View 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/process/.vscode/launch.json vendored Normal file
View 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/process/.vscode/tasks.json vendored Normal file
View 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/process/Makefile Normal file
View File

@@ -0,0 +1,5 @@
EXE=app
SRCS=$(wildcard *.c)
# Include the standard application Makefile for the CSEL1 labs
include ../appl.mk

133
src/process/process.c Normal file
View 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/system_calls/.vscode/launch.json vendored Normal file
View 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/system_calls/.vscode/tasks.json vendored Normal file
View 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'"]
}
]
}

View File

@@ -0,0 +1,5 @@
EXE=app
SRCS=$(wildcard *.c)
# Include the standard application Makefile for the CSEL1 labs
include ../appl.mk

View 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/tracing/.vscode/launch.json vendored Normal file
View 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/tracing/.vscode/tasks.json vendored Normal file
View 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/tracing/Makefile Normal file
View 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/tracing/fibonacci.c Normal file
View 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;
}