Embedded Linux Systems Programming (2023-02-13 - 2023-02-17)¶
WSL For Core Linux Topics¶
If possible, we should use WSL for core Linux topics. Local editing in Visual Studio Code, local compilation on a virtualized Ubuntu, local running.
Cross Development For Hardware Topics¶
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.
Day 1: Overview¶
Introductory Live Hacking¶
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.
From The Shell (Bash - “Bourne Again Shell”)
Exercises (from Exercises: The ls Command)
Exercises (from Exercises: Create/Copy/Move/Remove)
Processes Quick Walk-Through¶
Development: CMake Quick Intro, And Git Quick Intro¶
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
setserialsource code on Github
Linux kernel source code: drivers/tty/tty_io.c
ioctl(fd, TIOCGSERIAL, &serial_struct)
serial_struct.flags |= ASYNC_LOW_LATENCY
ioctl(fd, TIOCSSERIAL, &serial_struct)
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)
Unpacking the toolchain archive: Archiving and Compression
Have a look into how toolchains are made:
Secure Shell (SSH)¶
Send sensor values (W1, and userspace LM73) over CAN
Receive values, and show via a PWM’d LED
Some OO: PWM display (display-pwm.h, display-pwm.cpp), and associated program (show-pwm-temperature.cpp
Show sine wave: show-pwm-temperature-sine.cpp
Realtime sine waves on 2 LEDs (see
More OO? Writing temperature to CAN could be viewed as another kind of display. A little C++ interfacery ( display.h, leading to display-can.h, display-can.cpp)
⟶ 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
More From The Commandline¶
Multithreading (And C++)¶
From Linux Systems Programming: Multithreading:
Race Conditions, and prevention thereof (mutexes)
Communication mechanisms (condition variable)