|
| 1 | +# Embedded Linux Remote Template |
| 2 | + |
| 3 | +**A professional, automated framework for cross-compiling and remote debugging on Embedded Linux devices using VS Code, CMake, and GDB.** |
| 4 | + |
| 5 | +## 📖 Overview |
| 6 | + |
| 7 | +This repository provides a robust **"One-Click Debugging"** workflow for Embedded Linux development. It solves the inefficiency of manual file transfers and `printf` debugging by automating the entire pipeline: |
| 8 | + |
| 9 | +1. **Cross-Compilation** (Host side). |
| 10 | +2. **Deployment** (SCP to Target). |
| 11 | +3. **Process Management** (Safe port handling on Target). |
| 12 | +4. **GDB Attachment** (Live debugging via VS Code). |
| 13 | + |
| 14 | +This template is **board-agnostic** and can be adapted for any platform (Raspberry Pi, BeagleBone, i.MX, STM32MP1, Nuvoton, etc.) running `gdbserver`. |
| 15 | + |
| 16 | +## 📂 Project Structure |
| 17 | + |
| 18 | +```text |
| 19 | +. |
| 20 | +├── CMakeLists.txt # Main build configuration (Platform independent) |
| 21 | +├── build/ # Out-of-source build artifacts |
| 22 | +├── src/ |
| 23 | +│ └── main.cpp # Application source code |
| 24 | +├── toolchain/ |
| 25 | +│ └── generic.cmake # Toolchain definition (Compiler paths & flags) |
| 26 | +└── .vscode/ # VS Code Automation & Configuration |
| 27 | + ├── settings.json # Project-wide variables (IPs, Paths, Users) |
| 28 | + ├── tasks.json # Automation pipeline (Build -> Deploy -> Run) |
| 29 | + └── launch.json # GDB Client configuration |
| 30 | +``` |
| 31 | + |
| 32 | +## 🛠 Prerequisites |
| 33 | + |
| 34 | +Host Machine (Developer PC) |
| 35 | + |
| 36 | +- OS: Linux (Ubuntu/Debian) or Windows (WSL2). |
| 37 | +- Software: |
| 38 | + - VS Code + C/C++ Extension + CMake Tools. |
| 39 | + - gdb-multiarch (Universal GDB Client). |
| 40 | + - ssh, scp. |
| 41 | +- Target Device (Embedded Board) |
| 42 | + - Linux Kernel. |
| 43 | + - gdbserver installed. (or download from https://github.com/stayliv3/gdb-static-cross/tree/master/prebuilt) |
| 44 | + - SSH Access enabled. |
| 45 | + |
| 46 | +## 🚀 Setup & Usage Guide |
| 47 | + |
| 48 | +### Step 1: Clone and Configure |
| 49 | + |
| 50 | +Clone this repository and update the environment variables in .vscode/settings.json to match your hardware: |
| 51 | + |
| 52 | +```json |
| 53 | +// .vscode/settings.json |
| 54 | +{ |
| 55 | + // --- Target Board Configuration --- |
| 56 | + "embed.targetIP": "192.168.1.100", |
| 57 | + "embed.targetUser": "root", |
| 58 | + "embed.targetPath": "/usr/local/my_app", |
| 59 | + "embed.debugPort": "2345", |
| 60 | + |
| 61 | + // --- Host Configuration --- |
| 62 | + "embed.hostBuildPath": "${workspaceFolder}/build/my_app" |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +### Step 2: SSH Key (Passwordless Access) |
| 67 | + |
| 68 | +To allow automation, the Host must access the Target without a password prompt. |
| 69 | + |
| 70 | +```bash |
| 71 | +# On Host Terminal |
| 72 | +ssh-copy-id root@192.168.1.100 |
| 73 | +``` |
| 74 | + |
| 75 | +### Step 3: Toolchain Setup (toolchain/generic.cmake) |
| 76 | + |
| 77 | +Create this file to define your cross-compiler. Do not hardcode paths in CMakeLists.txt. |
| 78 | + |
| 79 | +### Step 4: Run one-time for setup |
| 80 | + |
| 81 | +```bash |
| 82 | +# Change your toolchain path |
| 83 | +cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=./toolchain/generic.cmake -DCMAKE_BUILD_TYPE=Debug |
| 84 | +``` |
| 85 | + |
| 86 | +### Step 5: Start Debugging |
| 87 | + |
| 88 | +1. Open src/main.cpp |
| 89 | +2. Set a Breakpoint (F9). |
| 90 | +3. Press F5. |
0 commit comments