Tuesday, January 31, 2023

How does Linux load rootfs

  • To load rootfs, you need a basic set of tools. How does the kernel bring them in? Initramfs
  • Initramfs is a RAM based FS that brings support for the basic things.  Command line to setup the kernel at start: vmlinuz initrd=initramfs.img root=/dev/sdaX
  • Moving from initramfs to rootfs: Initramfs does a pivot and switch to rootfs. (1) Move initramfs mountpoints to new rootfs mountpoints, (2) This initramfs contains the essential tools required to create and launch the rootfs. Final switch is done by: switch_root /newroot /bin/bash. Finally once the switch_root is done, run the init from the new rootfs.
Labels: switch_root, Linux, Kernel, rootfs, initramfs, build, systems, TLDR, summary

Code Snippet:
# First, find and mount the new filesystem.      mkdir /newroot    mount /dev/whatever /newroot      # Unmount everything else you've attached to rootfs.  (Moving the filesystems    # into newroot is something useful to do with them.)      mount --move /sys /newroot/sys    mount --move /proc /newroot/proc    mount --move /dev /newroot/dev      # Now switch to the new filesystem, and run /sbin/init out of it.  Don't    # forget the "exec" here, because you want the new init program to inherit    # PID 1.      exec switch_root /newroot /sbin/init

Thursday, January 26, 2023

TLDR: WPA3-SAE - How does it work

  • WPA3 - SAE - stands for simultaneous authentication of equals. This is a more secure mechanism than the previous WPA2-PSK [1].
  • This relies on 3 fundamental components:
    • DH - Diffie-hellman key exchange - Helps to generate a common shared key between the two WiFi entities e.g. station and client.
    • ECC (elliptic curve cryptography) - Elliptic-curve cryptography (ECC) is an approach to public-key cryptography based on the algebraic structure of elliptic curves over finite fields. ECC allows smaller keys compared to non-EC cryptography (based on plain Galois fields) to provide equivalent security [2]. ECC is used once a common pairwise key is generated using the DH key exchange.
    • Dragonfly key exchange is a mechanism for key exchange using discrete logarithm cryptography [3]. This is used with the two components above to setup SAE. See the reference for details on how it is setup [3]. Also covered in RFC7664.
labels: WiFi, TLDR, summary article, WPA3, SAE, security, 

Reference:

Sunday, January 22, 2023

Difference between POE-PD and POE-PSE, POE vs POE+

  • POE stands for power over ethernet
  • A POE system consists of two components - a POE-PSE (Power sourcing equipment) the device which provides the power, and a POE-PD (Power delivered) equipment which receives the power over ethernet.
  • PSE equipment examples - POE switches, POE injectors, POE media convertors [1]
  • PD equipment examples - APs, IP cameras, other devices.
  • PSE has 4 types based on PSE, PD power ratings with a 90W PSE max allowing a 71W PD draw on a port [2].
  • PD ratings are only based on the power draw limit - max of 71W - class 8 PD [2]
  • Power delivery limits are based on negotiations determined by the 802.3 standard. 802.3at (POE) delivers 15.4W, 802.3af (POE+)  delivers 25.5W. This is the difference between POE and POE+.
labels: POE, ethernet, difference, solution, networking, IP networks, TLDR

Reference

Saturday, January 14, 2023

(Programming) Combining the constant and volatile keywords in C

Sometimes asked as an interview question in embedded programming, this summary article covers an interesting use case of combining two seemingly opposite keywords in C [1].

Here is a TLDR of what this means:
1. int volatile x; Tells the compiler that x can change independent of the code e.g a register change that happens in Hardware.
2. uint16_t const x; Is used to tell the compiler that the variable x is immutable.
3. So when can we end up using these together? The article [1] talks about 3 cases, but they are essentially the same thing. We can use these keywords together for a pointer where the address of the pointer does not change (constant) but the value contained at that address is volatile (e.g. a register, shared memory etc). 
e.g. Constant address of volatile hardware register / memory. uint8_t volatile * const p_ptr; i.e the p_ptr has a constant address for a volatile (register).
 
Reference:
[1] Embedded.com. Michael Barr Combining C's volatile and constant 

GITHUB POCO C++ libraries

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.