diff --git a/.bazelrc b/.bazelrc index 2fb203969..a917905a2 100644 --- a/.bazelrc +++ b/.bazelrc @@ -16,7 +16,7 @@ common --@score_baselibs//score/mw/log/detail/flags:KUse_Stub_Implementation_Onl common --@score_baselibs//score/mw/log/flags:KRemote_Logging=False common --@score_baselibs//score/json:base_library=nlohmann common --//score/mw/com/flags:tracing_library=stub -common --extra_toolchains=@gcc_toolchain//:host_gcc_12 +common --extra_toolchains=@gcc_toolchain//:aarch64_gcc_13 build --incompatible_strict_action_env test --test_output=errors build --experimental_retain_test_configuration_across_testonly #https://github.com/bazelbuild/bazel/issues/6842 @@ -28,6 +28,8 @@ test --sandbox_tmpfs_path=/tmp # Tests require to be run in a sandbox. Otherwise some will be flaky. test --nosandbox_default_allow_network +build:aarch64 --platforms=@score_toolchains_gcc//platforms:aarch64-linux + common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/refs/heads/main/ common --registry=https://bcr.bazel.build diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..0fd62d510 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Run fastdev image", + "type": "shell", + "command": "${workspaceFolder}/run_qemu.sh bazel-bin/score/mw/com/example/ipc_bridge_hi_wrapper/deb-qemuarm64-modified/", + "problemMatcher": [] + }, + { + "label": "Upload application binaries to fastedev image", + "type": "shell", + "command": "cd ${workspaceFolder} && bazel build --config=aarch64 --spawn_strategy=local //score/mw/com/example/ipc_bridge_hi_wrapper:upload", + "problemMatcher": [] + }, + { + "label": "Run example application in fastedev image", + "type": "shell", + "command": "cd ${workspaceFolder} && bazel build --config=aarch64 --spawn_strategy=local //score/mw/com/example/ipc_bridge_hi_wrapper:run_example && code ./bazel-bin/score/mw/com/example/ipc_bridge_hi_wrapper/qemu_run.log && code ./bazel-bin/score/mw/com/example/ipc_bridge_hi_wrapper/ssh_run.log", + "problemMatcher": [] + } + ] +} diff --git a/MODULE.bazel b/MODULE.bazel index 20e5a8d81..7dd1caef8 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -13,8 +13,12 @@ module(name = "communication") bazel_dep(name = "platforms", version = "0.0.11") - -bazel_dep(name = "score_toolchains_gcc", version = "0.4", dev_dependency = True) +bazel_dep(name = "score_toolchains_gcc", version = "0.4", dev_dependency=True) +git_override( + module_name = "score_toolchains_gcc", + remote = "https://github.com/Elektrobit/eclipse-score_toolchains_gcc.git", + commit = "fb009e490b9b8f28805d587f50d0bf6d885f3414", +) gcc = use_extension( "@score_toolchains_gcc//extentions:gcc.bzl", @@ -22,9 +26,9 @@ gcc = use_extension( dev_dependency = True, ) gcc.toolchain( - sha256 = "457f5f20f57528033cb840d708b507050d711ae93e009388847e113b11bf3600", - strip_prefix = "x86_64-unknown-linux-gnu", - url = "https://github.com/eclipse-score/toolchains_gcc_packages/releases/download/0.0.1/x86_64-unknown-linux-gnu_gcc12.tar.gz", + url = "https://linux.elektrobit.com/tmp/score/fastdev-sdk-ubuntu-ebcl-deb-qemu-arm64.tar.xz", + sha256 = "cf8d277a2b95bbdad3e177c488fa77d01723510690a911218ef33747574d78fe", + strip_prefix = "fastdev-sdk-ubuntu-ebcl-deb-qemuarm64", ) # TODO to be moved to toolchain. https://github.com/eclipse-score/toolchains_gcc/issues/11 @@ -119,12 +123,12 @@ bazel_dep(name = "rules_doxygen", version = "2.5.0") bazel_dep(name = "score_baselibs", version = "0.2.0") git_override( module_name = "score_baselibs", - commit = "de5bb275ee9957433b3587582ac07d3eeb98dd6a", + commit = "e9dc2036cbdee3dce0ce51543eb34ea405326f7c", patch_strip = 1, patches = [ "//:wait_free_stack_fix.patch", ], - remote = "https://github.com/eclipse-score/baselibs.git", + remote = "https://github.com/Elektrobit/eclipse-score_baselibs.git", ) # Doxygen extension for documentation generation diff --git a/README.md b/README.md index b1a045432..6ca0ed353 100644 --- a/README.md +++ b/README.md @@ -141,4 +141,4 @@ We welcome contributions! See our [Contributing Guide](CONTRIBUTING.md) for deta --- -**Note**: This is an open-source project under the Eclipse Foundation. It implements automotive-grade communication middleware suitable for safety-critical applications. \ No newline at end of file +**Note**: This is an open-source project under the Eclipse Foundation. It implements automotive-grade communication middleware suitable for safety-critical applications. diff --git a/run_qemu.sh b/run_qemu.sh new file mode 100755 index 000000000..627c81ba4 --- /dev/null +++ b/run_qemu.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -xu + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi +BASEFOLDER=$1 +IMAGE="${BASEFOLDER}/fastdev-ubuntu-ebcl-deb-qemuarm64.wic" +KERNEL="${BASEFOLDER}/fastdev-ubuntu-ebcl-deb-qemuarm64-vmlinux" +if [ ! -d "${BASEFOLDER}" ] || [ ! -f "${IMAGE}" ] || [ ! -f "${KERNEL}" ] ; then + echo "Run \"bazel build --config=aarch64 --spawn_strategy=local //score/mw/com/example/ipc_bridge_hi_wrapper:fastdev-image\" first to fetch the image" +fi + +MACHINE="virt,virtualization=true,gic-version=3" +CPU="cortex-a53" +SMP="8" +MEM="4G" +KERNEL_ARGS=("-append" "root=/dev/vda1 sdk_enable lisa_syscall_whitelist=2026 rw sharedmem.enable_sharedmem=0 init=/usr/bin/ebclfsa-cflinit") +DISK_ARGS="-device virtio-blk-device,drive=vd0 -drive if=none,format=raw,file=${IMAGE},id=vd0" +NETWORK_ARGS="-netdev user,id=net0,net=192.168.7.0/24,dhcpstart=192.168.7.2,dns=192.168.7.3,host=192.168.7.5,hostfwd=tcp::2222-:22,hostfwd=tcp::3333-:3333 -device virtio-net-device,netdev=net0 " + +if ! command -v qemu-system-aarch64 > /dev/null; then + echo "Please install qemu-system-aarch64" + exit 1 +fi + +chmod +w ${IMAGE} + +exec qemu-system-aarch64 -m "${MEM}" -machine "${MACHINE}" -cpu "${CPU}" \ + -smp "${SMP}" -kernel "${KERNEL}" "${KERNEL_ARGS[@]}" ${DISK_ARGS} \ + ${NETWORK_ARGS} -nographic ${@:2} diff --git a/score/mw/com/example/ipc_bridge/BUILD b/score/mw/com/example/ipc_bridge/BUILD index 31f82ab45..f13cbdba0 100644 --- a/score/mw/com/example/ipc_bridge/BUILD +++ b/score/mw/com/example/ipc_bridge/BUILD @@ -30,6 +30,9 @@ cc_binary( "@score_baselibs//score/language/futurecpp", "@score_baselibs//score/mw/log", ], + visibility = [ + "//visibility:public", # platform_only + ], ) cc_library( diff --git a/score/mw/com/example/ipc_bridge_hi_wrapper/BUILD b/score/mw/com/example/ipc_bridge_hi_wrapper/BUILD new file mode 100644 index 000000000..280cbb9fc --- /dev/null +++ b/score/mw/com/example/ipc_bridge_hi_wrapper/BUILD @@ -0,0 +1,118 @@ +# ******************************************************************************* +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* +load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES") + +genrule( + name = "ipc_bridge_cpp_sil", + srcs = ["//score/mw/com/example/ipc_bridge:ipc_bridge_cpp"], + outs = ["ipc_bridge_cpp_sil"], + cmd = "cp $(SRCS) $@ && \ + chmod ugo+w $@ && \ + $(execpath @gcc_toolchain_gcc//:elf-enabler) $@ && \ + chmod ugo-w $@", + tools = ["@gcc_toolchain_gcc//:elf-enabler"], +) + +genrule( + name = "hi_app", + srcs = [ + ":ipc_bridge_hi_wrapper", + ":ipc_bridge_cpp_sil" + ], + outs = ["hi_app"], + cmd = "cp $(location :ipc_bridge_hi_wrapper) $@ && \ + chmod ugo+w $@ && \ + $(execpath @gcc_toolchain_gcc//:elf-enabler) $@ && \ + chmod ugo-w $@", + tools = ["@gcc_toolchain_gcc//:elf-enabler"], +) + +cc_binary( + name = "ipc_bridge_hi_wrapper", + srcs = [ + "main.cc", + ], + features = COMPILER_WARNING_FEATURES, + deps = [ + "//score/mw/com/example/ipc_bridge:ipc_bridge_cpp", + ], +) + +genrule( + name = "fetch-fastdev-archive", + srcs = [], + outs = ["fastdev-archive.tgz"], + cmd = "wget -O $@ https://linux.elektrobit.com/tmp/score/fastdev-ubuntu-ebcl-deb-qemu-arm64.tgz" +) + +genrule( + name = "fastdev-image", + srcs = [":fetch-fastdev-archive"], + outs = [ + "deb-qemuarm64/fastdev-ubuntu-ebcl-deb-qemuarm64.wic", + "deb-qemuarm64/fastdev-ubuntu-ebcl-deb-qemuarm64-vmlinux" + ], + cmd = "tar xzf $(location :fetch-fastdev-archive) -C $(RULEDIR)", +) + +genrule( + name = "upload", + srcs = [ + ":ipc_bridge_cpp_sil", + "//score/mw/com/example/ipc_bridge:ipc_bridge_cpp", + ":hi_app", + ":fastdev-image", + "mw_com_config.json", + "run_qemu.sh", + "logging.json" + ], + cmd = " \ + mkdir -p $(RULEDIR)/deb-qemuarm64-modified &&\ + cp $(RULEDIR)/deb-qemuarm64/* $(RULEDIR)/deb-qemuarm64-modified/ &&\ + $(location run_qemu.sh) $(RULEDIR)/deb-qemuarm64-modified -pidfile $(RULEDIR)/qemu.pid > $(RULEDIR)/qemu_upload.log &\ + sleep 30 ; \ + sshpass -p linux scp -o StrictHostKeyChecking=no -P 2222 $(location :ipc_bridge_cpp_sil) root@localhost:/usr/bin &&\ + sshpass -p linux scp -o StrictHostKeyChecking=no -P 2222 $(location //score/mw/com/example/ipc_bridge:ipc_bridge_cpp) root@localhost:/usr/bin &&\ + sshpass -p linux scp -o StrictHostKeyChecking=no -P 2222 $(location :hi_app) root@localhost:/usr/bin &&\ + sshpass -p linux scp -o StrictHostKeyChecking=no -P 2222 $(location mw_com_config.json) root@localhost:/etc/ &&\ + sshpass -p linux scp -o StrictHostKeyChecking=no -P 2222 $(location logging.json) root@localhost:/etc/ &&\ + sshpass -p linux ssh -o StrictHostKeyChecking=no -p 2222 root@localhost sync &&\ + sshpass -p linux ssh -o StrictHostKeyChecking=no -p 2222 root@localhost crinit-ctl poweroff || true \ + sleep 5 \ + ", + outs = [ + "qemu_upload.log", + "deb-qemuarm64-modified/fastdev-ubuntu-ebcl-deb-qemuarm64.wic", + "deb-qemuarm64-modified/fastdev-ubuntu-ebcl-deb-qemuarm64-vmlinux" + ], +) + +genrule( + name = "run_example", + srcs = [ + "deb-qemuarm64-modified/fastdev-ubuntu-ebcl-deb-qemuarm64.wic", + "deb-qemuarm64-modified/fastdev-ubuntu-ebcl-deb-qemuarm64-vmlinux", + "run_qemu.sh" + ], + cmd = " \ + $(location run_qemu.sh) $(RULEDIR)/deb-qemuarm64-modified -pidfile $(RULEDIR)/qemu.pid > $(RULEDIR)/qemu_run.log &\ + sleep 10 ; \ + sshpass -p linux ssh -o StrictHostKeyChecking=no -p 2222 root@localhost ipc_bridge_cpp -n 10 -m send -t 200 -s /etc/mw_com_config.json > $(RULEDIR)/ssh_run.log && \ + sshpass -p linux ssh -o StrictHostKeyChecking=no -p 2222 root@localhost crinit-ctl poweroff || true \ + sleep 5 \ + ", + outs = [ + "qemu_run.log", + "ssh_run.log", + ], +) diff --git a/score/mw/com/example/ipc_bridge_hi_wrapper/logging.json b/score/mw/com/example/ipc_bridge_hi_wrapper/logging.json new file mode 100644 index 000000000..54646e105 --- /dev/null +++ b/score/mw/com/example/ipc_bridge_hi_wrapper/logging.json @@ -0,0 +1,8 @@ +{ + "appId": "IPBR", + "appDesc": "ipc_bridge", + "logLevel": "kInfo", + "logLevelThresholdConsole": "kInfo", + "logMode": "kRemote|kConsole", + "dynamicDatarouterIdentifiers" : true +} diff --git a/score/mw/com/example/ipc_bridge_hi_wrapper/main.cc b/score/mw/com/example/ipc_bridge_hi_wrapper/main.cc new file mode 100644 index 000000000..d0909dd65 --- /dev/null +++ b/score/mw/com/example/ipc_bridge_hi_wrapper/main.cc @@ -0,0 +1,38 @@ +/******************************************************************************** + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +#include +#include +#include + +int main() { + std::cout << "HI_App: Starting ipc_bridge_cpp_sil" << std::endl; + + const char *c_args[] = { + "/usr/bin/ipc_bridge_cpp_sil", + "-n", "10", + "-m", "recv", + "-t", "200", + "-s", "/etc/mw_com_config.json", + nullptr + }; + + execve("/usr/bin/ipc_bridge_cpp_sil", const_cast(c_args), nullptr); + + std::cerr << "execve failed, sleeping... Reason: " << strerror(errno) + << std::endl; + while (true) { + sleep(10); + } + return 0; +} + diff --git a/score/mw/com/example/ipc_bridge_hi_wrapper/mw_com_config.json b/score/mw/com/example/ipc_bridge_hi_wrapper/mw_com_config.json new file mode 120000 index 000000000..b1f8e8637 --- /dev/null +++ b/score/mw/com/example/ipc_bridge_hi_wrapper/mw_com_config.json @@ -0,0 +1 @@ +../ipc_bridge/etc/mw_com_config.json \ No newline at end of file diff --git a/score/mw/com/example/ipc_bridge_hi_wrapper/run_qemu.sh b/score/mw/com/example/ipc_bridge_hi_wrapper/run_qemu.sh new file mode 120000 index 000000000..6ec286b61 --- /dev/null +++ b/score/mw/com/example/ipc_bridge_hi_wrapper/run_qemu.sh @@ -0,0 +1 @@ +../../../../../run_qemu.sh \ No newline at end of file