Showing posts with label Buildroot. Show all posts
Showing posts with label Buildroot. Show all posts

Sunday, October 02, 2022

Measuring PREEMPT_RT Latency with an Oscilloscope

A ready-to-use bootable SD card image for BeagleBone Black/Green with a fully preemptible Linux kernel (PREEMPT_RT) — includes a gpio-test program that mirrors an input signal to a GPIO output pin for measuring scheduler latency with an oscilloscope.

Oscilloscope showing input and output waveforms with scheduler latency

Oscilloscope view — yellow is the input signal, blue is the GPIO output. The phase difference indicates scheduler latency.

Thanks to Maxime Chevallier of Bootlin for providing the gpio-test demo utility during PREEMPT_RT training.

Setup diagram

Setup diagram — signal generator, BeagleBone, and oscilloscope

Setup diagram — signal generator feeds the BeagleBone, oscilloscope measures input vs output.

Items needed

Instructions

  1. Prepare the setup as shown in the diagram (set signal generator to 100 Hz, 50% duty cycle)
  2. Download sdcard-beaglebone-preemptrt-demo.img.xz (~25 MB)
  3. Write the image to a micro SD card using Balena Etcher
  4. Insert the SD card into the BeagleBone and power on
  5. After boot, the oscilloscope shows two square waves with a phase difference — yellow (input) and blue (output from BeagleBone)
  6. The phase difference indicates the latency introduced by the scheduler while running the preemptrt-gpiotest program

On startup, /etc/init.d/S99PreemptrtGpioTester invokes:

chrt -r 99 /usr/sbin/preemptrt-gpiotest gpiochip0 28 gpiochip0 17 h p

This starts the gpio-test utility at real-time priority 99.

Measuring latency under load

The gpio-test program mirrors a GPIO input to an output — the phase difference between the two signals shows how fast the scheduler delivers context to your application. Jitter on the output signal (measured in oscilloscope persist mode) indicates the best and worst case scheduler latency under different load conditions (network traffic, interrupts, etc.).

Oscilloscope persist mode showing best and worst case latency

Persist mode — showing best and worst case scheduler latency under load.

For further details on PREEMPT_RT, see Bootlin's PREEMPT_RT training material.

Building from source

Detailed build instructions are available in the git repository. Cross-compile instructions for modifying and running a customized gpio-test utility are also available.

SOURCE CODE

github.com/hackboxguy/preemptrt-gpiotest — GPIO latency test program

github.com/hackboxguy/br-wrapper — Buildroot config and build instructions

sdcard-beaglebone-preemptrt-demo.img.xz — pre-built SD card image (~25 MB)

Saturday, September 24, 2022

AWS IoT on Raspberry Pi with 25 MB Buildroot Linux

Six simple steps to get an AWS IoT Device SDK demo running on a Raspberry Pi 4 — using a lightweight custom Linux image built with Buildroot (just under 25 MB).

Quick start

  1. Download sdcard-pi4-aws-iot-demo.img.xz (~25 MB)
  2. Write the image to an SD card using Balena Etcher
  3. Unplug and re-plug the SD card so the boot partition appears on your PC
  4. Open aws-iot-pubsub-agent.conf and set your AWS IoT endpoint
  5. Copy your AWS-generated device certificate (xyz-certificate.pem) and private key (xyz-private.pem.key) to the boot partition
  6. Insert the SD card into the Raspberry Pi 4, power on — the aws-iot-pubsub-agent will start publishing messages to your AWS IoT Core

The following image shows steps 4, 5, and 6 in detail:

SD card configuration — endpoint, certificates, and boot

Steps 4–6: configure endpoint, copy certificates, and boot the Pi.

AWS cloud preparation

Before booting the Pi, set up the following on console.aws.amazon.com:

  1. Create an AWS IoT account (payment details required even for the free tier)
  2. Navigate to IoT Core
  3. Go to Manage → All Devices → Things → Create Thing
  4. Download the device certificate and private key (copy these to the SD card boot partition as described in step 5 above)
  5. Go to Settings and note your Endpoint (needed for step 4 above)
  6. Go to Security → Policies and create a policy with 4 entries as shown below:
AWS IoT security policy configuration

AWS IoT security policy — required permissions for the device.

Building the image from source

Two commands to build the SD card image (detailed instructions in the git repository):

make -C buildroot BR2_EXTERNAL=../ BR2_DL_DIR=../../br-dl O=../../br-output raspberrypi4_aws_iot_defconfig
make -C buildroot BR2_EXTERNAL=../ BR2_DL_DIR=../../br-dl O=../../br-output

Buildroot customizations

Key changes in the Raspberry Pi 4 Buildroot config for this AWS demo image:

  1. Enabled Dropbear SSH for remote debugging without monitor/keyboard
  2. Added Buildroot package for aws-iot-device-sdk-cpp-v2
  3. Added Buildroot package for aws-iot-pubsub-agent
  4. Enabled chrony for time sync (required for TLS handshake)
  5. Enabled SDK dependencies (host-cmake, libcurl, openssl, util-linux)
  6. Included AmazonRootCA1.pem in /etc/
  7. Added aws-iot-pubsub-agent.conf to rootfs for the agent startup script
  8. Added /etc/init.d/S03MountBoot to mount the boot partition at /mnt/certs (contains certificates, key, and config)
  9. Included startup script for aws-iot-pubsub-agent

After booting

  1. Connect the Raspberry Pi 4 to a DHCP network with internet access
  2. Find the Pi on your network using hostname buildroot or its assigned IP
  3. Log in via SSH: ssh root@192.168.x.y (password: brb0x)
  4. Check the publish log: cat /tmp/aws-iot-pubsub-agent.log
  5. To modify the aws-iot-pubsub-agent code, see how to cross-compile and run on target

If everything is configured correctly (SD card and AWS security policies), Hello World! messages will appear on your AWS IoT Core console:

AWS IoT Core showing Hello World messages from Raspberry Pi

AWS IoT Core — Hello World messages arriving from the Raspberry Pi 4.

SOURCE CODE

github.com/hackboxguy/br-wrapper — build instructions and Buildroot config

sdcard-pi4-aws-iot-demo.img.xz — pre-built SD card image (~25 MB)

Thursday, February 27, 2020

YARMP: Lightweight Raspberry Pi Media Player

A lightweight Buildroot-based media player image (<65 MB) for Raspberry Pi that autoplays video, audio, or images in a loop — booting in under 20 seconds.

  • Supports all Pi 1 variants (Pi Zero, Pi Zero W, Pi A/B, Pi A+/B+)
  • Works on older Pis with just 256 MB RAM and a 1 GB SD card
  • Autoplays media from the internal SD card or an external FAT-formatted USB drive
Pi Zero running YARMP as digital photo album on 7-inch LCD

Battery-powered Pi Zero running YARMP as a digital photo album on a 7-inch LCD — under $50 total.

Quick start — 3 steps

  1. Download raspi-yarmp.img.xz to your PC
  2. Write the image to an SD card using Balena Etcher
  3. Insert the SD card into your Pi and power on — the default video starts playing in a loop
Balena Etcher step 1 — select image

Step 1: Select the YARMP image in Balena Etcher.

Balena Etcher step 2 — select target

Step 2: Select the SD card as target.

Balena Etcher step 3 — flash

Step 3: Flash the image to the SD card.

Flashing in progress

Flashing in progress.

Flash complete

Flash complete — SD card is ready.

Playing your own media

  1. Remove the SD card from the Pi and plug it into your PC
  2. Browse to USRDAT:\media-files\ and find sample-video.mkv
  3. Delete or back up the sample file, then add your own media (video, audio, or images) to the media-files directory
  4. Insert the SD card back into the Pi and power on — your media plays in a loop

If you can't find the USRDAT drive on Windows, try a USB SD card reader or mount it on Linux. Alternatively, copy your media to a FAT-formatted USB drive and plug it into the Pi — on boot, external USB media takes priority over the internal SD card.

Playback priority

When multiple media types are present, YARMP follows this priority order:

  1. Video files (highest priority)
  2. Audio files (e.g. MP3)
  3. Image files (e.g. JPG, PNG)
  4. If no media is found on USB or SD card, the default BBC motion gallery video plays

Seamless looping

By default, a single video file plays in seamless loop mode — no black screen between loops. For multiple videos to play seamlessly, merge them into one file using the melt tool.

For photo slideshows, adjust the display delay by editing /mnt/userdata/rc.local on the Pi (look for the fbv command line section).

Use cases

  • Digital signage
  • Portable HDMI audio/video test source (Pi Zero + battery bank)
  • Art installations — display your work on a loop
  • Museum exhibits — low-cost media playback
  • Science projects — small HDMI display with custom content
  • Digital photo album on an HDMI display

Hardware photos

Pi Zero YARMP setup — front view

Pi Zero with 7-inch LCD — front view.

Pi Zero YARMP setup — rear view

Pi Zero with 7-inch LCD — rear view showing battery bank.

DOWNLOADS

raspi-yarmp.img.xz — pre-built SD card image (<65 MB)

Friday, September 16, 2016

Battery-Powered IoT Device with Pi Zero and 3G

A compact, battery-powered IoT device built from a Raspberry Pi Zero, a Huawei E173 USB 3G modem, and a prepaid SIM card. RBox — a lightweight Buildroot-based Linux distribution (~25 MB) — boots from the SD card, connects to the internet over 3G, and runs an XMPP chat-bot so you can monitor and control the device from your phone's chat app.

Compact Pi Zero IoT setup — top view

Compact stacked setup — Pi Zero, USB 3G modem, and 5200 mAh battery pack.

Pi Zero IoT setup — side view
Pi Zero IoT setup — rear view
Pi Zero IoT setup — detail view

What happens at boot

  1. usb_modeswitch switches the 3G modem from mass-storage mode to modem mode
  2. umts-keeper + sakis3g establish and maintain the 3G internet connection
  3. The XMPP chat-bot daemon (built on gloox, a C++ XMPP library) logs in to a Jabber server
  4. You can now communicate with the Pi Zero from your Android Xabber app (or any XMPP client)

Features

  • Total cost under ~50 EUR (Pi Zero + SD card + 3G stick + SIM + battery)
  • Read-only root filesystem — power cuts do not corrupt the SD card
  • Over-the-air Linux image upgrade via XMPP chat message (~25 MB per upgrade)
  • No cloud service, port forwarding, or dynamic DNS required — just two Jabber accounts
  • Send/receive SMS and dial USSD codes via chat messages
  • Control GPIO pins with get/set commands
  • Execute shell commands remotely via chat
  • Multiple XMPP accounts can control the same device simultaneously

Use cases

  • SMS gateway — deploy at home with a local prepaid SIM, access SMS from anywhere via Jabber
  • Weather station — deploy in a 3G coverage area with solar panel and sensors
  • Fleet management — place in vehicles with a GPS sensor, track from a central PC
  • Wildlife monitoring — deploy with a camera in a GSM-covered area
  • Digital signage — control display content remotely via chat
  • Anti-theft tracker — for cars, boats, caravans — sends GPS coordinates when movement is detected
  • Home automation — monitor temperature/humidity, control relays via GPIO

FAQ

How much 3G data does this use?
With no chat traffic, only XMPP heartbeat packets are sent — typically a few hundred kilobytes per day.

How long does the battery last?
A fully charged 5200 mAh battery keeps the setup running for 8–10 hours. Use a higher-capacity battery for longer runtime.

Can I deploy this off-grid?
Yes, with a larger battery and solar panel. Ensure the location has 3G coverage.

What happens if power fails during an OTA update?
RBox writes the new image to the non-active partition, then flips the boot flag and reboots. A power failure during the write leaves the active partition untouched.

Why the stacked form factor?
A compact rectangular brick is easier to enclose in a 3D-printed case than dangling cables.

Comparison — old setup with dangling cables vs compact stacked setup

Old setup (left) vs compact stacked setup (right).

How much does this cost to run?
Total hardware cost is under 50 EUR. A 100 MB / 30-day prepaid data plan (e.g. ~2 EUR/month with Congstar in Germany) is sufficient for basic I/O control and command traffic.

Items needed

  • Raspberry Pi Zero v1.3
  • Huawei E173 USB 3G modem
  • 8 GB SD card
  • Battery pack (5200 mAh or larger)
  • Four pogo pins
  • General-purpose PCB
  • PCB-mountable USB male and female connectors

SD card setup

  1. Create two XMPP accounts on a public Jabber server (tested with jabber.de, xabber.de, ubuntu-jabber.de) and authorize them to chat with each other
  2. Download the RBox SD card image
  3. Decompress with 7-Zip or your preferred tool
  4. Write the image to the SD card using Win32DiskImager or similar
  5. Remove and re-insert the SD card — a boot drive appears
  6. Create xmpp-login.txt on the boot drive using this template — replace the sample credentials with your device's XMPP username and password (update APN details for your carrier)
  7. Insert the SD card into the Pi Zero and power on — wait 2–3 minutes for the 3G modem LED to glow solid blue
  8. On your phone, open Xabber and log in with the master XMPP account
  9. The Pi Zero should appear online — send Help to see the list of available commands
  10. Send Sysupdate;reboot to update to the latest RBox image — see the full command reference
  11. For graceful shutdown, send poweroff and wait for the 3G modem LED to turn off

SOURCE CODE

github.com/hackboxguy/brbox — RBox sources and build instructions

Pi Zero build instructions — generate the binary image from source

Sunday, January 03, 2016

RBox: Lightweight Linux Distro for IoT Devices

RBox (RemoteBox) is a lightweight Linux distribution built with Buildroot, designed for IoT devices that need reliable connectivity over the public internet. It runs on low-cost hardware and uses XMPP chat messaging for remote control — no cloud services, port forwarding, or dynamic DNS required.

The Raspberry Pi image provided here works only on Raspberry Pi B+.

Key features

  • Runs on Raspberry Pi B+, BeagleBone Black, and BeagleBone Green
  • Small update image — under 20 MB for Raspberry Pi, under 10 MB for BeagleBone
  • Over-the-air updates with dual-boot failsafe against power outage or network failure
  • Always-on XMPP chat-bot keeps the device accessible via any Jabber server
  • Remote GPIO read/write via chat messages
  • Health monitoring commands
  • GSM SIM management with Huawei E173 USB modem — read/send/delete SMS, dial USSD codes, voice dialling
  • Open source — hosted on GitHub

Applications

Deploying RBox on Raspberry Pi B+

  1. Create two XMPP accounts on a public Jabber server (tested with jabber.de, xabber.de, ubuntu-jabber.de) and authorize them to chat with each other
  2. Download the RBox SD card image
  3. Decompress with 7-Zip or your preferred tool
  4. Write the image to the SD card using Win32DiskImager
  5. Remove and re-insert the SD card — a boot drive appears
  6. Create xmpp-login.txt on the boot drive using this template — replace the sample credentials with your device's XMPP username and password
  7. Insert the SD card into the Raspberry Pi, connect an Ethernet cable, and power on
  8. On your phone, open Xabber and log in with the master XMPP account
  9. The Raspberry Pi should appear online — send Help to see the list of available commands
  10. Send Sysupdate;reboot to update to the latest RBox image — see the full command reference

RBox is in active development. Contributions and feedback are welcome — leave a comment or open an issue on GitHub.

SOURCE CODE

github.com/hackboxguy/brbox — RBox sources and build instructions