Skip to content

Commit

Permalink
docs(yocto/examples): add examples how to cross-compile generic C/C++…
Browse files Browse the repository at this point in the history
… and ROS2 C/C++ projects
  • Loading branch information
nikAizuddin committed Jul 19, 2023
1 parent a7f3854 commit 7c97965
Show file tree
Hide file tree
Showing 8 changed files with 523 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
/project/yocto/build/*.log
/project/yocto/build/*.lock
/project/yocto/build/sdk-*
/project/yocto/layers/meta-user/recipes-apps/datastruct-cpp/files/build
/project/yocto/layers/meta-user/recipes-apps/*/files/build
/project/yocto/layers/meta-user/recipes-apps/*/files/install
/project/yocto/layers/meta-user/recipes-apps/*/files/log
81 changes: 81 additions & 0 deletions docs/yocto/specifics/qemuarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ Build:
bitbake mc:qemuarm:ros2-image
```

To build SDK and extract into `[PROJECT_ROOT]/project/yocto/build/sdk-qemuarm` directory:
```
bitbake mc:qemuarm:ros2-image -c populate_sdk
./tmp-glibc/deploy/sdk/oecore-x86_64-cortexa15t2hf-neon-toolchain-nodistro.0.sh -d sdk-qemuarm
```

Replace `FIXMESTAGINGDIRHOST` with `project/yocto/build/sdk-qemuarm/sysroots` in all `cmake` files in the `sdk-qemuarm`:
```
find sdk-qemuarm -type f -name *.cmake -print0 | xargs -0 sed -i 's,FIXMESTAGINGDIRHOST,'"$(readlink -f sdk-qemuarm/sysroots/x86_64-oesdk-linux)"',g'
```


## Testing

Expand Down Expand Up @@ -53,3 +64,73 @@ runqemu \
**NOTE: If the port forwarding doesn't work, try shutdown QEMU, respawn the `yocto-toolkit` Podman container, and re-execute the same `runqemu` command again.**

Login as `yocto` user with password `yocto`. Then follow testing instructions in [Testing](../common/testing.md).


## Cross-Compiling C++ Applications

Open a new terminal and execute the following command (without using Podman):
```
source project/yocto/build/sdk-qemuarm/environment-setup-cortexa15t2hf-neon-oe-linux-gnueabi
cd project/yocto/layers/meta-user/recipes-apps/datastruct-cpp/files
mkdir -pv build
cd build
cmake \
-G "Eclipse CDT4 - Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
../datastruct-cpp
make -j $(($(nproc) -1))
```

Execute the following command to upload to QEMU and execute the binary:
```
scp -P 22222 ./ds-helloworld-cpp yocto@127.0.0.1:
ssh -p 22222 yocto@127.0.0.1
./ds-helloworld-cpp
```

To cleanup the `datastruct-cpp` project:
```
cd ..
rm -rf ./build/
```


## Cross-Compiling ROS2 C++ Applications

Open a new terminal and execute the following command (without using Podman):
```
source project/yocto/build/sdk-qemuarm/environment-setup-cortexa15t2hf-neon-oe-linux-gnueabi
source project/yocto/build/sdk-qemuarm/sysroots/x86_64-oesdk-linux/etc/profile.d/ros/setup.bash
cd project/yocto/layers/meta-user/recipes-apps/ros2-helloworld-cpp/files/ros2-helloworld-cpp/
colcon \
--log-base ../log \
build \
--build-base ../build \
--install-base ../install \
--cmake-args \
-G "Eclipse CDT4 - Unix Makefiles" \
-DPython3_FIND_STRATEGY=LOCATION \
-DBUILD_TESTING=OFF
```

Within the `yocto-toolkit` Podman container, start QEMU using the following command:
```
runqemu \
qemuarm \
slirp \
nographic \
qemuparams="-m 512 -net nic -net user,hostfwd=tcp:127.0.0.1:1534-:1534,hostfwd=tcp:127.0.0.1:22222-:22,hostfwd=tcp:127.0.0.1:2345-:2345" \
bootparams="selinux=1 enforcing=0"
```

From host, execute the following command to upload to QEMU and execute the binary:
```
scp -P 22222 ../install/ros2-helloworld-cpp/lib/ros2-helloworld-cpp/main yocto@127.0.0.1:
ssh -p 22222 yocto@127.0.0.1
./main
```

To cleanup the `ros2-helloworld-cpp` project:
```
rm -rf ../build/ ../install/ ../log/
```
81 changes: 81 additions & 0 deletions docs/yocto/specifics/qemuarm64.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ Build:
bitbake mc:qemuarm64:ros2-image
```

To build SDK and extract into `[PROJECT_ROOT]/project/yocto/build/sdk-qemuarm64` directory:
```
bitbake mc:qemuarm64:ros2-image -c populate_sdk
./tmp-glibc/deploy/sdk/oecore-x86_64-cortexa57-toolchain-nodistro.0.sh -d sdk-qemuarm64
```

Replace `FIXMESTAGINGDIRHOST` with `project/yocto/build/sdk-qemuarm64/sysroots` in all `cmake` files in the `sdk-qemuarm64`:
```
find sdk-qemuarm64 -type f -name *.cmake -print0 | xargs -0 sed -i 's,FIXMESTAGINGDIRHOST,'"$(readlink -f sdk-qemuarm64/sysroots)"',g'
```


## Testing

Expand Down Expand Up @@ -53,3 +64,73 @@ runqemu \
**NOTE: If the port forwarding doesn't work, try shutdown QEMU, respawn the `yocto-toolkit` Podman container, and re-execute the same `runqemu` command again.**

Login as `yocto` user with password `yocto`. Then follow testing instructions in [Testing](../common/testing.md).


## Cross-Compiling C++ Applications

Open a new terminal and execute the following command (without using Podman):
```
source project/yocto/build/sdk-qemuarm64/environment-setup-cortexa57-oe-linux
cd project/yocto/layers/meta-user/recipes-apps/datastruct-cpp/files
mkdir -pv build
cd build
cmake \
-G "Eclipse CDT4 - Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
../datastruct-cpp
make -j $(($(nproc) -1))
```

Execute the following command to upload to QEMU and execute the binary:
```
scp -P 22222 ./ds-helloworld-cpp yocto@127.0.0.1:
ssh -p 22222 yocto@127.0.0.1
./ds-helloworld-cpp
```

To cleanup the `datastruct-cpp` project:
```
cd ..
rm -rf ./build/
```


## Cross-Compiling ROS2 C++ Applications

Open a new terminal and execute the following command (without using Podman):
```
source project/yocto/build/sdk-qemuarm64/environment-setup-cortexa57-oe-linux
source project/yocto/build/sdk-qemuarm64/sysroots/x86_64-oesdk-linux/etc/profile.d/ros/setup.bash
cd project/yocto/layers/meta-user/recipes-apps/ros2-helloworld-cpp/files/ros2-helloworld-cpp/
colcon \
--log-base ../log \
build \
--build-base ../build \
--install-base ../install \
--cmake-args \
-G "Eclipse CDT4 - Unix Makefiles" \
-DPython3_FIND_STRATEGY=LOCATION \
-DBUILD_TESTING=OFF
```

Within the `yocto-toolkit` Podman container, start QEMU using the following command:
```
runqemu \
qemuarm64 \
slirp \
nographic \
qemuparams="-m 512 -net nic -net user,hostfwd=tcp:127.0.0.1:1534-:1534,hostfwd=tcp:127.0.0.1:22222-:22,hostfwd=tcp:127.0.0.1:2345-:2345" \
bootparams="selinux=1 enforcing=0"
```

From host, execute the following command to upload to QEMU and execute the binary:
```
scp -P 22222 ../install/ros2-helloworld-cpp/lib/ros2-helloworld-cpp/main yocto@127.0.0.1:
ssh -p 22222 yocto@127.0.0.1
./main
```

To cleanup the `ros2-helloworld-cpp` project:
```
rm -rf ../build/ ../install/ ../log/
```
73 changes: 73 additions & 0 deletions docs/yocto/specifics/rock64.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ To build:
bitbake mc:rock64:ros2-image
```

To build SDK and extract into `[PROJECT_ROOT]/project/yocto/build/sdk-rock64` directory:
```
bitbake mc:rock64:ros2-image -c populate_sdk
./tmp-glibc/deploy/sdk/oecore-x86_64-cortexa53-crypto-toolchain-nodistro.0.sh -d sdk-rock64
```

Replace `FIXMESTAGINGDIRHOST` with `project/yocto/build/sdk-rock64/sysroots` in all `cmake` files in the `sdk-rock64`:
```
find sdk-rock64 -type f -name *.cmake -print0 | xargs -0 sed -i 's,FIXMESTAGINGDIRHOST,'"$(readlink -f sdk-rock64/sysroots/x86_64-oesdk-linux)"',g'
```


## Flashing to SD Card

Expand All @@ -38,3 +49,65 @@ sudo dd bs=4M iflag=fullblock oflag=direct status=progress if=project/yocto/buil
## Testing

Insert SD card and power on Rock64. Access serial console and login as `yocto` user with password `yocto`. Then, follow [Testing](../common/testing.md) instructions.


## Cross-Compiling C++ Applications

Open a new terminal and execute the following command (without using Podman):
```
source project/yocto/build/sdk-rock64/environment-setup-cortexa53-crypto-oe-linux
cd project/yocto/layers/meta-user/recipes-apps/datastruct-cpp/files
mkdir -pv build
cd build
cmake \
-G "Eclipse CDT4 - Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
../datastruct-cpp
make -j $(($(nproc) -1))
```

Execute the following command to upload to QEMU and execute the binary:
```
scp -P 22 ./ds-helloworld-cpp yocto@rock64.lan:
ssh -p 22 yocto@rock64.lan
./ds-helloworld-cpp
```

**NOTE: If `rock64.lan` is not resolvable by your network, you need to replace `rock64.lan` according to your target device IP address.**

To cleanup the `datastruct-cpp` project:
```
cd ..
rm -rf ./build/
```


## Cross-Compiling ROS2 C++ Applications

Open a new terminal and execute the following command (without using Podman):
```
source project/yocto/build/sdk-rock64/environment-setup-cortexa53-crypto-oe-linux
source project/yocto/build/sdk-rock64/sysroots/x86_64-oesdk-linux/etc/profile.d/ros/setup.bash
cd project/yocto/layers/meta-user/recipes-apps/ros2-helloworld-cpp/files/ros2-helloworld-cpp/
colcon \
--log-base ../log \
build \
--build-base ../build \
--install-base ../install \
--cmake-args \
-G "Eclipse CDT4 - Unix Makefiles" \
-DPython3_FIND_STRATEGY=LOCATION \
-DBUILD_TESTING=OFF
```

Execute the following command to upload to QEMU and execute the binary:
```
scp -P 22 ../install/ros2-helloworld-cpp/lib/ros2-helloworld-cpp/main yocto@rock64.lan:
ssh -p 22 yocto@rock64.lan
./main
```

To cleanup the `ros2-helloworld-cpp` project:
```
rm -rf ../build/ ../install/ ../log/
```
74 changes: 74 additions & 0 deletions docs/yocto/specifics/rpi3bp.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ Build:
bitbake mc:raspberrypi3-64:ros2-image
```

To build SDK and extract into `[PROJECT_ROOT]/project/yocto/build/sdk-rpi3bp` directory:
```
bitbake mc:raspberrypi3-64:ros2-image -c populate_sdk
./tmp-glibc/deploy/sdk/oecore-x86_64-cortexa53-toolchain-nodistro.0.sh -d sdk-rpi3bp
```

Replace `FIXMESTAGINGDIRHOST` with `project/yocto/build/sdk-rpi3bp/sysroots` in all `cmake` files in the `sdk-rpi3bp`:
```
find sdk-rpi3bp -type f -name *.cmake -print0 | xargs -0 sed -i 's,FIXMESTAGINGDIRHOST,'"$(readlink -f sdk-rpi3bp/sysroots/x86_64-oesdk-linux)"',g'
```


## Flashing to SD Card

Execute the following command:
Expand All @@ -37,3 +49,65 @@ bzcat project/yocto/build/tmp-glibc/deploy/images/raspberrypi3-64/ros2-image-hum
## Testing

Insert SD card and power on Raspberry Pi 3B+. Access serial console and login as `yocto` user with password `yocto`. Then, follow [Testing](../common/testing.md) instructions.


## Cross-Compiling C++ Applications

Open a new terminal and execute the following command (without using Podman):
```
source project/yocto/build/sdk-rpi3bp/environment-setup-cortexa53-oe-linux
cd project/yocto/layers/meta-user/recipes-apps/datastruct-cpp/files
mkdir -pv build
cd build
cmake \
-G "Eclipse CDT4 - Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
../datastruct-cpp
make -j $(($(nproc) -1))
```

Execute the following command to upload to QEMU and execute the binary:
```
scp -P 22 ./ds-helloworld-cpp yocto@raspberrypi3-64.lan:
ssh -p 22 yocto@raspberrypi3-64.lan
./ds-helloworld-cpp
```

**NOTE: If `raspberrypi3-64.lan` is not resolvable by your network, you need to replace `raspberrypi3-64.lan` according to your target device IP address.**

To cleanup the `datastruct-cpp` project:
```
cd ..
rm -rf ./build/
```


## Cross-Compiling ROS2 C++ Applications

Open a new terminal and execute the following command (without using Podman):
```
source project/yocto/build/sdk-rpi3bp/environment-setup-cortexa53-oe-linux
source project/yocto/build/sdk-rpi3bp/sysroots/x86_64-oesdk-linux/etc/profile.d/ros/setup.bash
cd project/yocto/layers/meta-user/recipes-apps/ros2-helloworld-cpp/files/ros2-helloworld-cpp/
colcon \
--log-base ../log \
build \
--build-base ../build \
--install-base ../install \
--cmake-args \
-G "Eclipse CDT4 - Unix Makefiles" \
-DPython3_FIND_STRATEGY=LOCATION \
-DBUILD_TESTING=OFF
```

Execute the following command to upload to QEMU and execute the binary:
```
scp -P 22 ../install/ros2-helloworld-cpp/lib/ros2-helloworld-cpp/main yocto@raspberrypi3-64.lan:
ssh -p 22 yocto@raspberrypi3-64.lan
./main
```

To cleanup the `ros2-helloworld-cpp` project:
```
rm -rf ../build/ ../install/ ../log/
```
Loading

0 comments on commit 7c97965

Please sign in to comment.