自定义Yocto层执行格式错误及CANBOAT层创建技术问询
First off, that Exec format error is almost certainly an architecture mismatch—you're trying to run an ARM-compiled binary (for your phyBOARD Mira, which uses an NXP i.MX ARM chip) directly on your x86_64 Ubuntu VM. Let's fix that first, then walk through building a fully functional CANBOAT layer tailored to your board's needs.
1. Root Cause of the Exec Format Error
Your Ubuntu VM is x86_64, but the phyBOARD Mira is an armv7a device. Any binaries built for the board will not run natively on your VM. To test them on your host, you'll need QEMU user-mode emulation. But first, let's make sure your Yocto build is targeting the correct architecture.
Fix Architecture Settings in local.conf
Open your $YOCTO_DIR/build/conf/local.conf and confirm these lines are set correctly (adjust the MACHINE name to match your specific phyBOARD Mira model):
MACHINE ??= "phyboard-mira-imx6" # Use phyboard-mira-imx7 if that's your model TARGET_ARCH = "arm" DEFAULTTUNE = "armv7athf-neon"
Never try to run ARM binaries directly on your x86 host without QEMU—we'll cover that later.
2. Build a Proper meta-canboat Layer Structure
Assuming you've already created a skeleton meta-canboat layer, let's flesh it out with the right files and recipes.
Layer Directory Structure
Your layer should look like this:
meta-canboat/ ├── conf/ │ └── layer.conf └── recipes-canboat/ └── canboat/ └── canboat_git.bb
Configure layer.conf
This tells Yocto how to find your layer's recipes:
BBPATH .= ":${LAYERDIR}" BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ ${LAYERDIR}/recipes-*/*/*.bbappend" BBFILE_COLLECTIONS += "meta-canboat" BBFILE_PATTERN_meta-canboat = "^${LAYERDIR}/" BBFILE_PRIORITY_meta-canboat = "6" # Set a priority higher than base layers LAYERSERIES_COMPAT_meta-canboat = "thud warrior" # Match your Yocto branch (adjust if needed)
Write the CANBOAT Recipe (canboat_git.bb)
CANBOAT is an open-source NMEA2000 toolset—we'll pull it directly from GitHub and build it for ARM:
SUMMARY = "CANBOAT - NMEA2000 Protocol Parser & Tools" HOMEPAGE = "https://github.com/canboat/canboat" LICENSE = "Apache-2.0" LIC_FILES_CHKSUM = "file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327" SRC_URI = "git://github.com/canboat/canboat.git;branch=master" SRCREV = "HEAD" # Replace with a specific commit hash for stability if needed S = "${WORKDIR}/git" # Dependencies CANBOAT needs to build DEPENDS = "bzip2 zlib" # Use autotools to build (some CANBOAT versions need brokensep for legacy autotools) inherit autotools-brokensep # Explicitly set host for ARM cross-compilation EXTRA_OECONF_arm = "--host=arm-linux-gnueabihf" # Enable all CANBOAT tools (canlogger, analyzer, etc.) EXTRA_OECONF += "--enable-all-tools" # Install PGN database files to the target do_install_append() { install -d ${D}${datadir}/canboat install -m 0644 ${S}/pgns/*.json ${D}${datadir}/canboat/ } # Ensure the PGN files are included in the package FILES_${PN} += "${datadir}/canboat"
3. Fixing Build & Runtime Issues
Clean Up Stale Build Artifacts
If you had a misconfigured build before, clean the CANBOAT build state and rebuild:
bitbake -c cleansstate canboat bitbake canboat
Test ARM Binaries on Your VM (Optional)
To test the built binary without flashing the board, install QEMU user-mode emulation:
sudo apt-get install qemu-user-static
Then run the binary with QEMU:
qemu-arm-static $YOCTO_DIR/build/tmp/deploy/images/phyboard-mira-imx6/canboat/usr/bin/canlogger
4. Integrate Database Storage for PGN Data
You want to store NMEA2000 PGN data to a database—here's how to add that to your setup:
- Add Database Dependency: If using SQLite (lightweight, good for embedded), add
sqlite3to your CANBOAT recipe'sDEPENDS, or include it in your image recipe. - Create a Logging Script: Write a simple shell or Python script to pipe CANBOAT output into SQLite. For example:
#!/bin/sh # Save as /usr/bin/canboat-log-to-db.sh canlogger -s can0 | sqlite3 /var/lib/nmea2000.db - Package the Script: Add a recipe or append to your CANBOAT recipe to install this script to the target filesystem.
5. Test on the phyBOARD Mira
Once you've built your image:
- Flash it to an SD card and boot the board.
- Load CAN kernel modules:
modprobe can modprobe can-dev modprobe can-raw ip link set can0 up type can bitrate 250000 # NMEA2000 standard baud rate - Run CANBOAT to verify data capture:
canlogger can0 - Start your database logging script to confirm PGN data is being stored correctly.
Troubleshooting Tips
- CAN Interface Not Working: Double-check hardware wiring, ensure the CAN transceiver is powered, and confirm the bitrate is set to 250000.
- Build Dependency Errors: Verify the
DEPENDSline in your CANBOAT recipe includes all required libraries (bzip2, zlib, sqlite3 if using the database). - Database Write Failures: Check file permissions for the database path, and ensure your script correctly parses CANBOAT's output format.
内容的提问来源于stack exchange,提问作者user4851126

