|
| 1 | +# Neural Analytics BitBake Recipe - Integration Guide |
| 2 | + |
| 3 | +## Repository as a BitBake Recipe |
| 4 | + |
| 5 | +The Neural Analytics repository serves as a complete, self-contained BitBake recipe for Yocto/OpenEmbedded and Poky Linux systems. The included `neural-analytics_git.bb` recipe at the project root transforms this repository into a buildable package that integrates seamlessly with embedded Linux distributions. |
| 6 | + |
| 7 | +### Recipe Architecture Philosophy |
| 8 | + |
| 9 | +This repository functions as both source code and BitBake recipe, providing a unified development and deployment experience: |
| 10 | + |
| 11 | +1. **Self-Contained Recipe**: Complete BitBake recipe included in the source repository |
| 12 | +2. **Poky Linux Integration**: Designed for seamless integration with Poky-based distributions |
| 13 | +3. **Embedded Optimization**: Configurable graphics backends for various embedded platforms |
| 14 | +4. **Precompiled Libraries**: Support for vendor-specific libraries in `/app/lib` |
| 15 | +5. **Systemd Integration**: Native service management with automatic startup |
| 16 | + |
| 17 | +## Development Configurations |
| 18 | + |
| 19 | +### Local Development Mode |
| 20 | + |
| 21 | +For testing the recipe with local code changes without committing to git, temporarily modify the `SRC_URI`: |
| 22 | + |
| 23 | +```bitbake |
| 24 | +# Comment out git configuration |
| 25 | +# SRC_URI = "git://github.com/neirth/neural-analytics.git;protocol=https;branch=main" |
| 26 | +# SRCREV = "${AUTOREV}" |
| 27 | +
|
| 28 | +# Use local configuration |
| 29 | +SRC_URI = "file://${THISDIR}" |
| 30 | +S = "${WORKDIR}/neural-analytics" |
| 31 | +
|
| 32 | +# Copy local files |
| 33 | +do_unpack:append() { |
| 34 | + cp -r ${THISDIR}/* ${S}/ |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +### Production Configuration |
| 39 | + |
| 40 | +The current configuration is optimized for production builds: |
| 41 | + |
| 42 | +```bitbake |
| 43 | +SRC_URI = "git://github.com/neirth/neural-analytics.git;protocol=https;branch=main" |
| 44 | +SRCREV = "${AUTOREV}" |
| 45 | +``` |
| 46 | + |
| 47 | +## Integration with Poky Linux Projects |
| 48 | + |
| 49 | +Since this repository **is** the recipe itself, integration follows Yocto's standard patterns for self-contained recipe repositories: |
| 50 | + |
| 51 | +### Method 1: Git Submodule Integration (Recommended) |
| 52 | + |
| 53 | +Add this repository as a git submodule to your Poky-based project: |
| 54 | + |
| 55 | +```bash |
| 56 | +# In your Poky build directory |
| 57 | +cd sources/ |
| 58 | +git submodule add https://github.com/neirth/neural-analytics.git meta-neural-analytics |
| 59 | + |
| 60 | +# The repository structure becomes: |
| 61 | +# sources/ |
| 62 | +# poky/ |
| 63 | +# meta-openembedded/ |
| 64 | +# meta-neural-analytics/ <- Our repository |
| 65 | +# neural-analytics_git.bb <- The recipe |
| 66 | +# packages/ <- Source code |
| 67 | +# dataset/ <- Data files |
| 68 | +``` |
| 69 | + |
| 70 | +### Method 2: Direct Clone in Sources Directory |
| 71 | + |
| 72 | +Clone the repository directly into your sources directory: |
| 73 | + |
| 74 | +```bash |
| 75 | +# In your Poky build environment |
| 76 | +cd sources/ |
| 77 | +git clone https://github.com/neirth/neural-analytics.git meta-neural-analytics |
| 78 | + |
| 79 | +# Add to conf/bblayers.conf |
| 80 | +echo 'BBLAYERS += "${TOPDIR}/../sources/meta-neural-analytics"' >> conf/bblayers.conf |
| 81 | +``` |
| 82 | + |
| 83 | +### Method 3: Layer Configuration for Recipe Discovery |
| 84 | + |
| 85 | +Create a minimal layer.conf to make BitBake discover the recipe: |
| 86 | + |
| 87 | +```bash |
| 88 | +# Create conf/layer.conf in the repository root |
| 89 | +mkdir -p conf/ |
| 90 | +cat > conf/layer.conf << 'EOF' |
| 91 | +BBPATH .= ":${LAYERDIR}" |
| 92 | +BBFILES += "${LAYERDIR}/*.bb ${LAYERDIR}/*.bbappend" |
| 93 | +BBFILE_COLLECTIONS += "neural-analytics" |
| 94 | +BBFILE_PATTERN_neural-analytics = "^${LAYERDIR}/" |
| 95 | +BBFILE_PRIORITY_neural-analytics = "6" |
| 96 | +LAYERDEPENDS_neural-analytics = "core" |
| 97 | +LAYERSERIES_COMPAT_neural-analytics = "mickledore nanbield scarthgap" |
| 98 | +EOF |
| 99 | +``` |
| 100 | + |
| 101 | +## Poky Linux Build Workflow |
| 102 | + |
| 103 | +### 1. Environment Setup |
| 104 | + |
| 105 | +```bash |
| 106 | +# Initialize Poky build environment |
| 107 | +source poky/oe-init-build-env build-neural-analytics |
| 108 | + |
| 109 | +# Add the neural-analytics repository to your layer configuration |
| 110 | +echo 'BBLAYERS += "${TOPDIR}/../sources/meta-neural-analytics"' >> conf/bblayers.conf |
| 111 | + |
| 112 | +# Configure target machine and include neural-analytics package |
| 113 | +echo 'MACHINE = "qemux86-64"' >> conf/local.conf |
| 114 | +echo 'IMAGE_INSTALL:append = " neural-analytics"' >> conf/local.conf |
| 115 | +``` |
| 116 | + |
| 117 | +### 2. Graphics Backend Configuration (Optional) |
| 118 | + |
| 119 | +```bash |
| 120 | +# Configure graphics backend in local.conf |
| 121 | +echo 'NEURAL_ANALYTICS_GRAPHICS_BACKEND = "drm"' >> conf/local.conf |
| 122 | + |
| 123 | +# Available backends: "wayland", "drm", "minimal" |
| 124 | +``` |
| 125 | + |
| 126 | +### 3. Build Execution |
| 127 | + |
| 128 | +```bash |
| 129 | +# Build only the neural analytics package |
| 130 | +bitbake neural-analytics |
| 131 | + |
| 132 | +# Build complete image with neural analytics included |
| 133 | +bitbake core-image-minimal |
| 134 | + |
| 135 | +# Or build with additional features |
| 136 | +bitbake core-image-sato |
| 137 | +``` |
| 138 | + |
| 139 | +### 4. Testing and Deployment |
| 140 | + |
| 141 | +```bash |
| 142 | +# Test in QEMU |
| 143 | +runqemu qemux86-64 |
| 144 | + |
| 145 | +# Deploy to target hardware |
| 146 | +dd if=tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic of=/dev/sdX bs=4M |
| 147 | +``` |
| 148 | + |
| 149 | +## Repository Structure for BitBake Consumption |
| 150 | + |
| 151 | +When consumed as a Yocto layer, the repository structure becomes: |
| 152 | + |
| 153 | +``` |
| 154 | +meta-neural-analytics/ <- Repository root (acts as layer) |
| 155 | +├── conf/ |
| 156 | +│ └── layer.conf <- Layer configuration (create if needed) |
| 157 | +├── neural-analytics_git.bb <- Main recipe file |
| 158 | +├── packages/ <- Source code (used by recipe) |
| 159 | +├── dataset/ <- Data files (copied to /app/data) |
| 160 | +├── vendor/ <- Precompiled libraries (copied to /app/lib) |
| 161 | +└── docs/ <- Documentation |
| 162 | +``` |
| 163 | + |
| 164 | +## Development and Local Testing |
| 165 | + |
| 166 | +### Local Development with File Protocol |
| 167 | + |
| 168 | +For local development and testing without git commits, the recipe supports file:// protocol: |
| 169 | + |
| 170 | +```bitbake |
| 171 | +# Modify SRC_URI in neural-analytics_git.bb for local development |
| 172 | +SRC_URI = "file://${THISDIR}" |
| 173 | +S = "${WORKDIR}/neural-analytics" |
| 174 | +``` |
| 175 | + |
| 176 | +This allows you to test recipe changes locally before committing to the repository. |
| 177 | + |
| 178 | +### Production Git Configuration |
| 179 | + |
| 180 | +For production builds, the recipe uses the standard git protocol: |
| 181 | + |
| 182 | +```bitbake |
| 183 | +SRC_URI = "git://github.com/neirth/neural-analytics.git;protocol=https;branch=main" |
| 184 | +SRCREV = "${AUTOREV}" |
| 185 | +``` |
| 186 | + |
| 187 | +## Recipe Automation and Helper Scripts |
| 188 | + |
| 189 | +The following scripts can be added to your repository to facilitate development workflows: |
| 190 | + |
| 191 | +### Development Mode Script (`dev-mode.sh`) |
| 192 | +```bash |
| 193 | +#!/bin/bash |
| 194 | +# Switch to local development mode |
| 195 | +cp neural-analytics_git.bb neural-analytics_git.bb.backup |
| 196 | +sed -i 's/SRC_URI = "git:/# SRC_URI = "git:/' neural-analytics_git.bb |
| 197 | +sed -i 's/SRCREV/# SRCREV/' neural-analytics_git.bb |
| 198 | +echo 'SRC_URI = "file://${THISDIR}"' >> neural-analytics_git.bb |
| 199 | +echo "Development mode activated - using local sources" |
| 200 | +``` |
| 201 | + |
| 202 | +### Production Mode Script (`prod-mode.sh`) |
| 203 | +```bash |
| 204 | +#!/bin/bash |
| 205 | +# Restore production configuration |
| 206 | +if [ -f neural-analytics_git.bb.backup ]; then |
| 207 | + mv neural-analytics_git.bb.backup neural-analytics_git.bb |
| 208 | + echo "Production mode restored - using git sources" |
| 209 | +else |
| 210 | + echo "Backup not found - cannot restore production mode" |
| 211 | +fi |
| 212 | +``` |
| 213 | + |
| 214 | +### Build Integration Script (`setup-layer.sh`) |
| 215 | + |
| 216 | +```bash |
| 217 | +#!/bin/bash |
| 218 | +# Setup neural-analytics as a Yocto layer |
| 219 | +POKY_BUILD_DIR="${1:-build}" |
| 220 | + |
| 221 | +# Ensure we have layer.conf |
| 222 | +if [ ! -f conf/layer.conf ]; then |
| 223 | + mkdir -p conf/ |
| 224 | + cat > conf/layer.conf << 'EOF' |
| 225 | +BBPATH .= ":${LAYERDIR}" |
| 226 | +BBFILES += "${LAYERDIR}/*.bb ${LAYERDIR}/*.bbappend" |
| 227 | +BBFILE_COLLECTIONS += "neural-analytics" |
| 228 | +BBFILE_PATTERN_neural-analytics = "^${LAYERDIR}/" |
| 229 | +BBFILE_PRIORITY_neural-analytics = "6" |
| 230 | +LAYERDEPENDS_neural-analytics = "core" |
| 231 | +LAYERSERIES_COMPAT_neural-analytics = "mickledore nanbield scarthgap" |
| 232 | +EOF |
| 233 | +fi |
| 234 | + |
| 235 | +# Add to existing Poky build if path provided |
| 236 | +if [ -d "${POKY_BUILD_DIR}/conf" ]; then |
| 237 | + LAYER_PATH=$(realpath .) |
| 238 | + echo "BBLAYERS += \"${LAYER_PATH}\"" >> ${POKY_BUILD_DIR}/conf/bblayers.conf |
| 239 | + echo "IMAGE_INSTALL:append = \" neural-analytics\"" >> ${POKY_BUILD_DIR}/conf/local.conf |
| 240 | + echo "Neural Analytics layer integrated into ${POKY_BUILD_DIR}" |
| 241 | +else |
| 242 | + echo "Layer configuration created. Add this directory to your BBLAYERS in bblayers.conf" |
| 243 | +fi |
| 244 | +``` |
| 245 | + |
| 246 | +## Vendor Library Support |
| 247 | + |
| 248 | +The recipe automatically handles precompiled libraries: |
| 249 | + |
| 250 | +```bash |
| 251 | +# Add vendor libraries to repository |
| 252 | +mkdir vendor/ |
| 253 | +cp -r /path/to/precompiled/libs/* vendor/ |
| 254 | + |
| 255 | +# Commit vendor directory |
| 256 | +git add vendor/ |
| 257 | +git commit -m "Add vendor libraries for embedded deployment" |
| 258 | +git push origin main |
| 259 | +``` |
| 260 | + |
| 261 | +The recipe will automatically: |
| 262 | + |
| 263 | +- Copy `vendor/*` to `/app/lib/` |
| 264 | +- Configure `LD_LIBRARY_PATH` for runtime |
| 265 | +- Set proper permissions for shared libraries |
| 266 | + |
| 267 | +## Poky Linux Distribution Considerations |
| 268 | + |
| 269 | +### Target Platform Configuration |
| 270 | + |
| 271 | +```bitbake |
| 272 | +# For Raspberry Pi |
| 273 | +MACHINE = "raspberrypi4" |
| 274 | +NEURAL_ANALYTICS_GRAPHICS_BACKEND = "drm" |
| 275 | +
|
| 276 | +# For x86_64 embedded systems |
| 277 | +MACHINE = "genericx86-64" |
| 278 | +NEURAL_ANALYTICS_GRAPHICS_BACKEND = "wayland" |
| 279 | +
|
| 280 | +# For minimal embedded systems |
| 281 | +MACHINE = "qemuarm" |
| 282 | +NEURAL_ANALYTICS_GRAPHICS_BACKEND = "minimal" |
| 283 | +``` |
| 284 | + |
| 285 | +### Image Integration |
| 286 | + |
| 287 | +```bitbake |
| 288 | +# Create custom image including neural analytics |
| 289 | +inherit core-image |
| 290 | +IMAGE_INSTALL += "neural-analytics bluez5 mesa" |
| 291 | +IMAGE_FEATURES += "package-management" |
| 292 | +``` |
| 293 | + |
| 294 | +## Best Practices for Yocto Integration |
| 295 | + |
| 296 | +1. **Repository as Layer**: Treat this repository as a self-contained Yocto layer |
| 297 | +2. **Version Management**: Use git tags for stable releases in production builds |
| 298 | +3. **Layer Dependencies**: Ensure all LAYERDEPENDS are satisfied in your build environment |
| 299 | +4. **Cross-Compilation**: The recipe handles Rust cross-compilation automatically |
| 300 | +5. **Testing**: Always test with `bitbake neural-analytics` before including in images |
| 301 | +6. **Documentation**: Keep this integration guide updated with recipe changes |
| 302 | + |
| 303 | +This repository exemplifies Yocto's principle of self-contained, reusable components that can be easily integrated into embedded Linux distributions while maintaining both development flexibility and production reliability. |
0 commit comments