Embedded Linux Systems Programming (2023-02-13 - 2023-02-17)

Programming Environment

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)).

The Shell

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.

Day 2

Processes Quick Walk-Through

Permissions

From File System Permissions

Development: CMake Quick Intro, And Git Quick Intro

File IO

Day 3

UART

  • First try: four programs, two on either side (cat, and echo)

    • ⟶ 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

  • Add cfmakeraw() programmatically (the “non-cooked mode” from man -s 1 stty)

    • this is what we want to see!

  • “Realtime”: setserial /dev/ttyUSB0 low_latency (man -s 8 setserial), only programmatically

    • setserial source 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)

SUSI

  • 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.

    🖕

Exercise

Modify that program such that it mimicks cat:

  • 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 ...

Cross Development

Day 4

Secure Shell (SSH)

Miscellaneous Hardware

Group Exercise

Day 5

Untold

More From The Commandline

Multithreading (And C++)

From Linux Systems Programming: Multithreading:

  • Race Conditions, and prevention thereof (mutexes)

  • Communication mechanisms (condition variable)

  • Atomics

  • Realtime

From Multithreading