Embedded Linux Systems Programming (2023-02-13 - 2023-02-17)¶
If possible, we should use WSL for core Linux topics. Local editing in Visual Studio Code, local compilation on a virtualized Ubuntu, local running.
For the more involved hardware related topics, I’ll bring a Raspberry Pi and some network equipment and build up a local network where we can log in from our PCs.
Please check that connecting the course participants’ PCs to some foreign untrusted LAN is permitted IT-wise.
Hammering on a GPIO pin: a typical example of how hardware access works on Linux (from Introductory Live Hacking, Hardware-Wise (sysfs GPIO)).
Using the Shell’s commandline, an overview is given about Unix system concepts like processes, files, and permissions. Many if not all of these concepts will be viewed programmatically in the remainder of the course. It will be no surprise, for example, that communication with hardware has to do with file I/O.
Exercises (from Exercises: The ls Command)
Exercises (from Exercises: Create/Copy/Move/Remove)
Setup Github project for local build: https://github.com/jfasch/2023-02-13
⟶ See instructions on that page
First try: four programs, two on either side (
⟶ weird output when used bidirectionally
Enable “raw mode” 🤔 ⟶ man -s 1 stty
⟶ no special character handling in terminal driver. Want no terminal, want naked UART IO!!
⟶ weird output still weird, but less so
Dedicated input and output programs
cfmakeraw()programmatically (the “non-cooked mode” from man -s 1 stty)
⟶ this is what we want to see!
setserial /dev/ttyUSB0 low_latency(man -s 8 setserial), only programmatically
tty-bidir-threads.cpp: not separate programs on different fds; two threads hammering on one fd
Livehacking: transform that into event-driven (tty-bidir-events.cpp)
Advantec Marketingese. Security is the “S” in IoT … that library requires you to run your code as root. Considered cool nonetheless, and marketed heavily by Advantec.
Modify that program such that it mimicks
Is given on single filename argument
Opens that file
Reads its content, and outputs it on standard output
$ ./mycat /etc/passwd ... contents of /etc/passwd here ...
Establish a custom built toolchain for Raspberry Pi cross development (from Case Study: Raspberry Toolchain)
Have a look into how toolchains are made:
Show sine wave: show-pwm-temperature-sine.cpp
Realtime sine waves on 2 LEDs (see
⟶ is-a Display
CIFS/Samba: mounting a Windows share on Linux: https://automationadmin.com/2016/12/mounting-a-samba-share-in-fedora/#gsc.tab=0
Race Conditions, and prevention thereof (mutexes)
Communication mechanisms (condition variable)