From 2eeb71e1105e888f1bc935e54e9c4286478c5e48 Mon Sep 17 00:00:00 2001 From: Jacques Supcik Date: Thu, 24 Feb 2022 00:00:47 +0100 Subject: [PATCH] Initial commit --- .devcontainer/devcontainer.json | 12 ++ .devcontainer/docker-compose.yml | 44 +++++ .devcontainer/main.code-workspace | 32 ++++ .devcontainer/toolchain/Dockerfile | 29 ++++ .../toolchain/scripts/delete-buildroot.sh | 8 + .../toolchain/scripts/delete-rootfs.sh | 8 + .../toolchain/scripts/extract-rootfs.sh | 8 + .../toolchain/scripts/get-buildroot.sh | 16 ++ .../toolchain/scripts/sync-images.sh | 8 + .gitignore | 4 + .vscode/extensions.json | 12 ++ README.md | 39 +++++ .../friendlyarm/nanopi-neo-plus2/boot.cmd | 6 + .../friendlyarm/nanopi-neo-plus2/genimage.cfg | 41 +++++ .../nanopi-neo-plus2/linux-extras.config | 27 ++++ .../nanopi-neo-plus2/nanopi-neo-plus2.dts | 7 + .../rootfs_overlay/etc/network/interfaces | 10 ++ .../rootfs_overlay/etc/ssh/sshd_config | 117 ++++++++++++++ .../nanopi-neo-plus2/uboot-extras.config | 2 + config/configs/csel_defconfig | 109 +++++++++++++ src/Makefile | 4 + src/appl.mk | 45 ++++++ src/backtrace/.vscode/launch.json | 21 +++ src/backtrace/.vscode/tasks.json | 14 ++ src/backtrace/Makefile | 5 + src/backtrace/main.c | 63 ++++++++ src/core_dumps/.vscode/launch.json | 21 +++ src/core_dumps/.vscode/tasks.json | 14 ++ src/core_dumps/Makefile | 5 + src/core_dumps/core_dumps.c | 45 ++++++ src/daemon/.vscode/launch.json | 21 +++ src/daemon/.vscode/tasks.json | 14 ++ src/daemon/Makefile | 5 + src/daemon/S60appl | 24 +++ src/daemon/daemon.c | 152 ++++++++++++++++++ src/dot-vscode/deploy.sh | 24 +++ src/dot-vscode/launch.json | 21 +++ src/dot-vscode/launch.json_presque | 43 +++++ src/dot-vscode/tasks.json | 14 ++ src/fibonacci/.vscode/launch.json | 21 +++ src/fibonacci/.vscode/tasks.json | 14 ++ src/fibonacci/Makefile | 5 + src/fibonacci/fibonacci.c | 88 ++++++++++ src/memory_leaks/.vscode/launch.json | 21 +++ src/memory_leaks/.vscode/tasks.json | 14 ++ src/memory_leaks/Makefile | 5 + src/memory_leaks/mem_leaks.c | 113 +++++++++++++ src/process/.vscode/launch.json | 21 +++ src/process/.vscode/tasks.json | 14 ++ src/process/Makefile | 5 + src/process/process.c | 133 +++++++++++++++ src/system_calls/.vscode/launch.json | 21 +++ src/system_calls/.vscode/tasks.json | 14 ++ src/system_calls/Makefile | 5 + src/system_calls/syscall.c | 58 +++++++ src/tracing/.vscode/launch.json | 21 +++ src/tracing/.vscode/tasks.json | 14 ++ src/tracing/Makefile | 9 ++ src/tracing/fibonacci.c | 79 +++++++++ 59 files changed, 1769 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/main.code-workspace create mode 100644 .devcontainer/toolchain/Dockerfile create mode 100755 .devcontainer/toolchain/scripts/delete-buildroot.sh create mode 100755 .devcontainer/toolchain/scripts/delete-rootfs.sh create mode 100755 .devcontainer/toolchain/scripts/extract-rootfs.sh create mode 100755 .devcontainer/toolchain/scripts/get-buildroot.sh create mode 100755 .devcontainer/toolchain/scripts/sync-images.sh create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 README.md create mode 100644 config/board/friendlyarm/nanopi-neo-plus2/boot.cmd create mode 100644 config/board/friendlyarm/nanopi-neo-plus2/genimage.cfg create mode 100644 config/board/friendlyarm/nanopi-neo-plus2/linux-extras.config create mode 100644 config/board/friendlyarm/nanopi-neo-plus2/nanopi-neo-plus2.dts create mode 100644 config/board/friendlyarm/nanopi-neo-plus2/rootfs_overlay/etc/network/interfaces create mode 100644 config/board/friendlyarm/nanopi-neo-plus2/rootfs_overlay/etc/ssh/sshd_config create mode 100644 config/board/friendlyarm/nanopi-neo-plus2/uboot-extras.config create mode 100644 config/configs/csel_defconfig create mode 100644 src/Makefile create mode 100644 src/appl.mk create mode 100644 src/backtrace/.vscode/launch.json create mode 100644 src/backtrace/.vscode/tasks.json create mode 100644 src/backtrace/Makefile create mode 100644 src/backtrace/main.c create mode 100644 src/core_dumps/.vscode/launch.json create mode 100644 src/core_dumps/.vscode/tasks.json create mode 100644 src/core_dumps/Makefile create mode 100644 src/core_dumps/core_dumps.c create mode 100644 src/daemon/.vscode/launch.json create mode 100644 src/daemon/.vscode/tasks.json create mode 100644 src/daemon/Makefile create mode 100644 src/daemon/S60appl create mode 100644 src/daemon/daemon.c create mode 100755 src/dot-vscode/deploy.sh create mode 100644 src/dot-vscode/launch.json create mode 100644 src/dot-vscode/launch.json_presque create mode 100644 src/dot-vscode/tasks.json create mode 100644 src/fibonacci/.vscode/launch.json create mode 100644 src/fibonacci/.vscode/tasks.json create mode 100644 src/fibonacci/Makefile create mode 100644 src/fibonacci/fibonacci.c create mode 100644 src/memory_leaks/.vscode/launch.json create mode 100644 src/memory_leaks/.vscode/tasks.json create mode 100644 src/memory_leaks/Makefile create mode 100644 src/memory_leaks/mem_leaks.c create mode 100644 src/process/.vscode/launch.json create mode 100644 src/process/.vscode/tasks.json create mode 100644 src/process/Makefile create mode 100644 src/process/process.c create mode 100644 src/system_calls/.vscode/launch.json create mode 100644 src/system_calls/.vscode/tasks.json create mode 100644 src/system_calls/Makefile create mode 100644 src/system_calls/syscall.c create mode 100644 src/tracing/.vscode/launch.json create mode 100644 src/tracing/.vscode/tasks.json create mode 100644 src/tracing/Makefile create mode 100644 src/tracing/fibonacci.c diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3415d3e --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,12 @@ +{ + "name": "csel", + "dockerComposeFile": "docker-compose.yml", + "service": "toolchain", + "workspaceFolder": "/workspace", + "shutdownAction": "stopCompose", + + "settings": {}, + "extensions": [ + "ms-vscode.cpptools" + ] +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..adc0487 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -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: {} diff --git a/.devcontainer/main.code-workspace b/.devcontainer/main.code-workspace new file mode 100644 index 0000000..eb8a18f --- /dev/null +++ b/.devcontainer/main.code-workspace @@ -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": {} +} \ No newline at end of file diff --git a/.devcontainer/toolchain/Dockerfile b/.devcontainer/toolchain/Dockerfile new file mode 100644 index 0000000..62486f0 --- /dev/null +++ b/.devcontainer/toolchain/Dockerfile @@ -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/* \ No newline at end of file diff --git a/.devcontainer/toolchain/scripts/delete-buildroot.sh b/.devcontainer/toolchain/scripts/delete-buildroot.sh new file mode 100755 index 0000000..c6f157e --- /dev/null +++ b/.devcontainer/toolchain/scripts/delete-buildroot.sh @@ -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 -- {} + diff --git a/.devcontainer/toolchain/scripts/delete-rootfs.sh b/.devcontainer/toolchain/scripts/delete-rootfs.sh new file mode 100755 index 0000000..f8e80fc --- /dev/null +++ b/.devcontainer/toolchain/scripts/delete-rootfs.sh @@ -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 -- {} + diff --git a/.devcontainer/toolchain/scripts/extract-rootfs.sh b/.devcontainer/toolchain/scripts/extract-rootfs.sh new file mode 100755 index 0000000..c5b1aa9 --- /dev/null +++ b/.devcontainer/toolchain/scripts/extract-rootfs.sh @@ -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/ \ No newline at end of file diff --git a/.devcontainer/toolchain/scripts/get-buildroot.sh b/.devcontainer/toolchain/scripts/get-buildroot.sh new file mode 100755 index 0000000..0e61783 --- /dev/null +++ b/.devcontainer/toolchain/scripts/get-buildroot.sh @@ -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 diff --git a/.devcontainer/toolchain/scripts/sync-images.sh b/.devcontainer/toolchain/scripts/sync-images.sh new file mode 100755 index 0000000..f280c10 --- /dev/null +++ b/.devcontainer/toolchain/scripts/sync-images.sh @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a98db23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +images +buildroot-images +src/*/app +.obj \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..37a49dd --- /dev/null +++ b/.vscode/extensions.json @@ -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" + ] + } \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..49f7756 --- /dev/null +++ b/README.md @@ -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/) diff --git a/config/board/friendlyarm/nanopi-neo-plus2/boot.cmd b/config/board/friendlyarm/nanopi-neo-plus2/boot.cmd new file mode 100644 index 0000000..e2e3de0 --- /dev/null +++ b/config/board/friendlyarm/nanopi-neo-plus2/boot.cmd @@ -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 diff --git a/config/board/friendlyarm/nanopi-neo-plus2/genimage.cfg b/config/board/friendlyarm/nanopi-neo-plus2/genimage.cfg new file mode 100644 index 0000000..b64ef0a --- /dev/null +++ b/config/board/friendlyarm/nanopi-neo-plus2/genimage.cfg @@ -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" + } +} diff --git a/config/board/friendlyarm/nanopi-neo-plus2/linux-extras.config b/config/board/friendlyarm/nanopi-neo-plus2/linux-extras.config new file mode 100644 index 0000000..ae6af85 --- /dev/null +++ b/config/board/friendlyarm/nanopi-neo-plus2/linux-extras.config @@ -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 diff --git a/config/board/friendlyarm/nanopi-neo-plus2/nanopi-neo-plus2.dts b/config/board/friendlyarm/nanopi-neo-plus2/nanopi-neo-plus2.dts new file mode 100644 index 0000000..f80383b --- /dev/null +++ b/config/board/friendlyarm/nanopi-neo-plus2/nanopi-neo-plus2.dts @@ -0,0 +1,7 @@ +/dts-v1/; + +#include "allwinner/sun50i-h5-nanopi-neo-plus2.dts" + +/ { + /delete-node/ leds; +}; diff --git a/config/board/friendlyarm/nanopi-neo-plus2/rootfs_overlay/etc/network/interfaces b/config/board/friendlyarm/nanopi-neo-plus2/rootfs_overlay/etc/network/interfaces new file mode 100644 index 0000000..eed4859 --- /dev/null +++ b/config/board/friendlyarm/nanopi-neo-plus2/rootfs_overlay/etc/network/interfaces @@ -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 diff --git a/config/board/friendlyarm/nanopi-neo-plus2/rootfs_overlay/etc/ssh/sshd_config b/config/board/friendlyarm/nanopi-neo-plus2/rootfs_overlay/etc/ssh/sshd_config new file mode 100644 index 0000000..cf889ce --- /dev/null +++ b/config/board/friendlyarm/nanopi-neo-plus2/rootfs_overlay/etc/ssh/sshd_config @@ -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 diff --git a/config/board/friendlyarm/nanopi-neo-plus2/uboot-extras.config b/config/board/friendlyarm/nanopi-neo-plus2/uboot-extras.config new file mode 100644 index 0000000..8c47f75 --- /dev/null +++ b/config/board/friendlyarm/nanopi-neo-plus2/uboot-extras.config @@ -0,0 +1,2 @@ +# Save env to SD Card +CONFIG_ENV_FAT_DEVICE_AND_PART="0:auto" diff --git a/config/configs/csel_defconfig b/config/configs/csel_defconfig new file mode 100644 index 0000000..a4f8fb3 --- /dev/null +++ b/config/configs/csel_defconfig @@ -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" diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..4f90695 --- /dev/null +++ b/src/Makefile @@ -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 + diff --git a/src/appl.mk b/src/appl.mk new file mode 100644 index 0000000..667cb94 --- /dev/null +++ b/src/appl.mk @@ -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 + + + diff --git a/src/backtrace/.vscode/launch.json b/src/backtrace/.vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/backtrace/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/backtrace/.vscode/tasks.json b/src/backtrace/.vscode/tasks.json new file mode 100644 index 0000000..75f4b5a --- /dev/null +++ b/src/backtrace/.vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/backtrace/Makefile b/src/backtrace/Makefile new file mode 100644 index 0000000..87b69cc --- /dev/null +++ b/src/backtrace/Makefile @@ -0,0 +1,5 @@ +EXE=app +SRCS=$(wildcard *.c) + +# Include the standard application Makefile for the CSEL1 labs +include ../appl.mk diff --git a/src/backtrace/main.c b/src/backtrace/main.c new file mode 100644 index 0000000..8720547 --- /dev/null +++ b/src/backtrace/main.c @@ -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 +#include +#include +#include +#include + +#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; +} diff --git a/src/core_dumps/.vscode/launch.json b/src/core_dumps/.vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/core_dumps/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/core_dumps/.vscode/tasks.json b/src/core_dumps/.vscode/tasks.json new file mode 100644 index 0000000..75f4b5a --- /dev/null +++ b/src/core_dumps/.vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/core_dumps/Makefile b/src/core_dumps/Makefile new file mode 100644 index 0000000..87b69cc --- /dev/null +++ b/src/core_dumps/Makefile @@ -0,0 +1,5 @@ +EXE=app +SRCS=$(wildcard *.c) + +# Include the standard application Makefile for the CSEL1 labs +include ../appl.mk diff --git a/src/core_dumps/core_dumps.c b/src/core_dumps/core_dumps.c new file mode 100644 index 0000000..100582c --- /dev/null +++ b/src/core_dumps/core_dumps.c @@ -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; +} diff --git a/src/daemon/.vscode/launch.json b/src/daemon/.vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/daemon/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/daemon/.vscode/tasks.json b/src/daemon/.vscode/tasks.json new file mode 100644 index 0000000..75f4b5a --- /dev/null +++ b/src/daemon/.vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/daemon/Makefile b/src/daemon/Makefile new file mode 100644 index 0000000..87b69cc --- /dev/null +++ b/src/daemon/Makefile @@ -0,0 +1,5 @@ +EXE=app +SRCS=$(wildcard *.c) + +# Include the standard application Makefile for the CSEL1 labs +include ../appl.mk diff --git a/src/daemon/S60appl b/src/daemon/S60appl new file mode 100644 index 0000000..1286746 --- /dev/null +++ b/src/daemon/S60appl @@ -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 $? + diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c new file mode 100644 index 0000000..2e4364c --- /dev/null +++ b/src/daemon/daemon.c @@ -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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#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; +} diff --git a/src/dot-vscode/deploy.sh b/src/dot-vscode/deploy.sh new file mode 100755 index 0000000..2f12ec5 --- /dev/null +++ b/src/dot-vscode/deploy.sh @@ -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 \ No newline at end of file diff --git a/src/dot-vscode/launch.json b/src/dot-vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/dot-vscode/launch.json @@ -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" + } + ] +} diff --git a/src/dot-vscode/launch.json_presque b/src/dot-vscode/launch.json_presque new file mode 100644 index 0000000..422d731 --- /dev/null +++ b/src/dot-vscode/launch.json_presque @@ -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, + // }, + } + ] +} \ No newline at end of file diff --git a/src/dot-vscode/tasks.json b/src/dot-vscode/tasks.json new file mode 100644 index 0000000..75f4b5a --- /dev/null +++ b/src/dot-vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/fibonacci/.vscode/launch.json b/src/fibonacci/.vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/fibonacci/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/fibonacci/.vscode/tasks.json b/src/fibonacci/.vscode/tasks.json new file mode 100644 index 0000000..91dd9de --- /dev/null +++ b/src/fibonacci/.vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/fibonacci/Makefile b/src/fibonacci/Makefile new file mode 100644 index 0000000..87b69cc --- /dev/null +++ b/src/fibonacci/Makefile @@ -0,0 +1,5 @@ +EXE=app +SRCS=$(wildcard *.c) + +# Include the standard application Makefile for the CSEL1 labs +include ../appl.mk diff --git a/src/fibonacci/fibonacci.c b/src/fibonacci/fibonacci.c new file mode 100644 index 0000000..7d5b8fc --- /dev/null +++ b/src/fibonacci/fibonacci.c @@ -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 +#include + +/** + * 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; +} diff --git a/src/memory_leaks/.vscode/launch.json b/src/memory_leaks/.vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/memory_leaks/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/memory_leaks/.vscode/tasks.json b/src/memory_leaks/.vscode/tasks.json new file mode 100644 index 0000000..75f4b5a --- /dev/null +++ b/src/memory_leaks/.vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/memory_leaks/Makefile b/src/memory_leaks/Makefile new file mode 100644 index 0000000..87b69cc --- /dev/null +++ b/src/memory_leaks/Makefile @@ -0,0 +1,5 @@ +EXE=app +SRCS=$(wildcard *.c) + +# Include the standard application Makefile for the CSEL1 labs +include ../appl.mk diff --git a/src/memory_leaks/mem_leaks.c b/src/memory_leaks/mem_leaks.c new file mode 100644 index 0000000..1804ad5 --- /dev/null +++ b/src/memory_leaks/mem_leaks.c @@ -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 +#include +#include + +#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; +} + + diff --git a/src/process/.vscode/launch.json b/src/process/.vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/process/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/process/.vscode/tasks.json b/src/process/.vscode/tasks.json new file mode 100644 index 0000000..75f4b5a --- /dev/null +++ b/src/process/.vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/process/Makefile b/src/process/Makefile new file mode 100644 index 0000000..87b69cc --- /dev/null +++ b/src/process/Makefile @@ -0,0 +1,5 @@ +EXE=app +SRCS=$(wildcard *.c) + +# Include the standard application Makefile for the CSEL1 labs +include ../appl.mk diff --git a/src/process/process.c b/src/process/process.c new file mode 100644 index 0000000..160ef1d --- /dev/null +++ b/src/process/process.c @@ -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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#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; +} diff --git a/src/system_calls/.vscode/launch.json b/src/system_calls/.vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/system_calls/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/system_calls/.vscode/tasks.json b/src/system_calls/.vscode/tasks.json new file mode 100644 index 0000000..75f4b5a --- /dev/null +++ b/src/system_calls/.vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/system_calls/Makefile b/src/system_calls/Makefile new file mode 100644 index 0000000..87b69cc --- /dev/null +++ b/src/system_calls/Makefile @@ -0,0 +1,5 @@ +EXE=app +SRCS=$(wildcard *.c) + +# Include the standard application Makefile for the CSEL1 labs +include ../appl.mk diff --git a/src/system_calls/syscall.c b/src/system_calls/syscall.c new file mode 100644 index 0000000..a6d02dd --- /dev/null +++ b/src/system_calls/syscall.c @@ -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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +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; +} + + diff --git a/src/tracing/.vscode/launch.json b/src/tracing/.vscode/launch.json new file mode 100644 index 0000000..56a80dd --- /dev/null +++ b/src/tracing/.vscode/launch.json @@ -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" + } + ] +} diff --git a/src/tracing/.vscode/tasks.json b/src/tracing/.vscode/tasks.json new file mode 100644 index 0000000..75f4b5a --- /dev/null +++ b/src/tracing/.vscode/tasks.json @@ -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'"] + } + ] +} \ No newline at end of file diff --git a/src/tracing/Makefile b/src/tracing/Makefile new file mode 100644 index 0000000..f779f6c --- /dev/null +++ b/src/tracing/Makefile @@ -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 diff --git a/src/tracing/fibonacci.c b/src/tracing/fibonacci.c new file mode 100644 index 0000000..30736de --- /dev/null +++ b/src/tracing/fibonacci.c @@ -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 +#include + +#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; +}