Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add renode-cli #28944

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions recipes/renode-cli/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash

set -o xtrace -o nounset -o pipefail -o errexit

update_antmicro_submodule() {
local commit=$1
local module=$2

git clone https://github.com/antmicro/${module}.git
pushd ${module}
git fetch origin ${commit}
git submodule update --init --recursive
popd
}

mkdir -p ${PREFIX}/bin
mkdir -p ${PREFIX}/libexec/${PKG_NAME}
export PATH="${DOTNET_ROOT}/dotnet:${PATH}"

install_prefix="${PREFIX}/opt/${PKG_NAME}"

dotnet_version=$(dotnet --version)
framework_version=${dotnet_version%.*}

mkdir -p ${SRC_DIR}/src/Infrastructure/
mv renode-infrastructure/* ${SRC_DIR}/src/Infrastructure/ && rm -rf renode-infrastructure

mkdir -p ${SRC_DIR}/lib
pushd ${SRC_DIR}/lib
git clone https://github.com/renode/renode-resources.git
pushd renode-resources && git submodule update --init --recursive && popd
mv renode-resources resources

update_antmicro_submodule b1d3d03d602581fc2bed6db586b5e5c3388456c7 AntShell
update_antmicro_submodule e7bfa5873f2300e6e87c185f466e227762dbf4b2 BigGustave
update_antmicro_submodule b0c2a820f28a7bdedb85575bfca6447c9e7fa955 CxxDemangler
update_antmicro_submodule de4e4f6ffab555771285cb810f17f61cfd38ef39 ELFsharp
rm -rf ELFSharp && mv ELFsharp ELFSharp
update_antmicro_submodule e379e8ae696676afffed2f33dd8083855af00f2f FdtSharp
update_antmicro_submodule 33e5ab24eaaab488e9a94f1a40d5d6ae2f7f02f1 InpliTftpServer
update_antmicro_submodule c6514e99f2c35afec083b9f4a7eec3408c0081d1 Migrant
update_antmicro_submodule 2fe74fd257f6d6f86076c100952178f347098b3d Packet.Net
update_antmicro_submodule 33d24f1307d267c34b7f1439bc159a8825c5aa3d bc-csharp
update_antmicro_submodule bde21d04fbfc540989b7a0ac13a54eae8b756994 cctask
update_antmicro_submodule e8c2051dec56c5ccd3a4927b07a5740f34eed8c8 options-parser
update_antmicro_submodule 71af57ef4fec29e416f48160b8918057a58548a9 termsharp
popd
MementoRC marked this conversation as resolved.
Show resolved Hide resolved

find lib src tests -name "*.csproj" -exec sed -i -E \
-e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" \
-e "s|^((\s+)<PropertyGroup>)|\1\n\2\2<NoWarn>CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051</NoWarn>|" \
-e 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' \
{} \;
find . -type d -name "obj" -exec rm -rf {} +
find . -type d -name "bin" -exec rm -rf {} +
sed -i -E 's/(ReleaseHeadless\|Any .+ = )Debug/\1Release/' Renode_NET.sln

export CC=${CC}
export CFLAGS="${CFLAGS} -fPIC"

if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then
_os_name=${target_platform%-*}

./build.sh --net --no-gui --force-net-framework-version ${framework_version}
else
_os_name=windows
./build.sh --net --no-gui --force-net-framework-version ${framework_version}
fi


mkdir -p $PREFIX/libexec/${PKG_NAME}
cp -r output/bin/Release/net${framework_version}/* $PREFIX/libexec/${PKG_NAME}/

mkdir -p $PREFIX/opt/${PKG_NAME}/scripts
mkdir -p $PREFIX/opt/${PKG_NAME}/platforms
mkdir -p $PREFIX/opt/${PKG_NAME}/tests
mkdir -p $PREFIX/opt/${PKG_NAME}/tools
mkdir -p $PREFIX/opt/${PKG_NAME}/licenses

cp .renode-root $PREFIX/opt/${PKG_NAME}/
cp -r scripts/* $PREFIX/opt/${PKG_NAME}/scripts/
cp -r platforms/* $PREFIX/opt/${PKG_NAME}/platforms/
cp -r tests/* $PREFIX/opt/${PKG_NAME}/tests/
cp -r tools/metrics_analyzer $PREFIX/opt/${PKG_NAME}/tools
cp -r tools/execution_tracer $PREFIX/opt/${PKG_NAME}/tools
cp -r tools/gdb_compare $PREFIX/opt/${PKG_NAME}/tools
cp -r tools/sel4_extensions $PREFIX/opt/${PKG_NAME}/tools

cp lib/resources/styles/robot.css $PREFIX/opt/${PKG_NAME}/tests

tools/packaging/common_copy_licenses.sh $PREFIX/opt/${PKG_NAME}/licenses $_os_name
cp -r $PREFIX/opt/${PKG_NAME}/licenses license-files

sed -i.bak "s#os\.path\.join(this_path, '\.\./lib/resources/styles/robot\.css')#os.path.join(this_path,'robot.css')#g" $PREFIX/opt/${PKG_NAME}/tests/robot_tests_provider.py
rm $PREFIX/opt/${PKG_NAME}/tests/robot_tests_provider.py.bak

mkdir -p $PREFIX/bin/
cat > $PREFIX/bin/renode <<"EOF"
#!/bin/sh
exec "${DOTNET_ROOT}"/dotnet exec "${CONDA_PREFIX}"/libexec/renode-cli/Renode.dll "$@"
EOF
chmod +x ${PREFIX}/bin/renode

cat > $PREFIX/bin/renode.cmd <<"EOF"
call %DOTNET_ROOT%\dotnet exec %CONDA_PREFIX%\libexec\libexec\renode-cli\Renode.dll %*
EOF
chmod +x ${PREFIX}/bin/renode

cat > $PREFIX/bin/renode-test <<"EOF"
#!/usr/bin/env bash

STTY_CONFIG=`stty -g 2>/dev/null`
python3 "${CONDA_PREFIX}"/opt/"${PKG_NAME}"/tests/run_tests.py --robot-framework-remote-server-full-directory "${CONDA_PREFIX}"/libexec/"${PKG_NAME}" "$@"
RESULT_CODE=$?
if [ -n "${STTY_CONFIG:-}" ]
then
stty "$STTY_CONFIG"
fi
exit $RESULT_CODE
EOF
chmod +x ${PREFIX}/bin/renode-test
107 changes: 107 additions & 0 deletions recipes/renode-cli/helpers/build-with-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
HOST_ARCH="i386"
CMAKE_COMMON=""
CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores"
OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")"
BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type")

# clean instead of building
if $CLEAN
then
for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;)
do
for dir in {bin,obj}/{Debug,Release}
do
output_dir="$(get_path "${project_dir}/${dir}")"
if [[ -d "${output_dir}" ]]
then
echo "Removing: ${output_dir}"
rm -rf "${output_dir}"
fi
done
done

# Manually clean the main output directory as it's location is non-standard
main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")"
if [[ -d "${main_output_dir}" ]]
then
echo "Removing: ${main_output_dir}"
rm -rf "${main_output_dir}"
fi
exit 0
fi

# Check if a full rebuild is needed
if [[ -f "$BUILD_TYPE_FILE" ]]
then
if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]]
then
echo "Attempted to build Renode in a different configuration than the previous build"
echo "Please run '$0 -c' to clean the previous build before continuing"
exit 1
fi
fi

# Paths for tlib
CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION"
CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION"

# Cmake generator, handled in their own variable since the names contain spaces
if $ON_WINDOWS
then
CMAKE_GEN="-GMinGW Makefiles"
else
CMAKE_GEN="-GUnix Makefiles"
fi

# Macos architecture flags, to make rosetta work properly
if $ON_OSX
then
CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64"
if [ $HOST_ARCH == "aarch64" ]; then
CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64"
fi
fi

# This list contains all cores that will be built.
# If you are adding a new core or endianness add it here to have the correct tlib built
CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le)

# build tlib
for core_config in "${CORES[@]}"
do
CORE="$(echo $core_config | cut -d '.' -f 1)"
ENDIAN="$(echo $core_config | cut -d '.' -f 2)"
BITS=32
# Check if core is 64-bit
if [[ $CORE =~ "64" ]]; then
BITS=64
fi
# Core specific flags to cmake
CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION"
CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN
mkdir -p $CORE_DIR
pushd "$CORE_DIR" > /dev/null
if [[ $ENDIAN == "be" ]]; then
CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1"
fi
cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH
cmake --build . -j$(nproc)
CORE_BIN_DIR=$CORES_BIN_PATH/lib
mkdir -p $CORE_BIN_DIR
if $ON_OSX; then
# macos `cp` does not have the -u flag
cp -v tlib/*.so $CORE_BIN_DIR/
else
cp -u -v tlib/*.so $CORE_BIN_DIR/
fi
# copy compile_commands.json to tlib directory
if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then
command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/
fi
popd > /dev/null
done

if $TLIB_ONLY
then
exit 0
fi
67 changes: 67 additions & 0 deletions recipes/renode-cli/patches/resolve-posix-unix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--- a/src/Plugins/VerilatorPlugin/Connection/SocketVerilatorConnection.cs
+++ b/src/Plugins/VerilatorPlugin/Connection/SocketVerilatorConnection.cs
@@ -7,4 +7,6 @@
using System;
+using System.IO;
using System.Net;
using System.Net.Sockets;
+using System.Security.AccessControl;
using System.Text;
@@ -19,2 +21,3 @@
using Antmicro.Renode.Peripherals;
+using Antmicro.Renode.Peripherals.Bus;
using Antmicro.Renode.Peripherals.CPU;
@@ -212,3 +215,7 @@
#if !PLATFORM_WINDOWS
- Mono.Unix.Native.Syscall.chmod(value, FilePermissions.S_IRWXU); //setting permissions to 0x700
+ // Use built-in .NET methods for file permissions
+ var fileInfo = new FileInfo(value);
+ var fileSecurity = fileInfo.GetAccessControl();
+ fileSecurity.AddAccessRule(new FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow));
+ fileInfo.SetAccessControl(fileSecurity);
#endif
--- a/src/Renode/Backends/Terminals/UartPtyTerminal.cs 2024-09-17 03:09:19.000000000 -0500
+++ b/src/Renode/Backends/Terminals/UartPtyTerminal.cs 2025-01-25 21:32:28.901091634 -0600
@@ -10,2 +10,3 @@
using System;
+using System.IO;
using Antmicro.Renode.Peripherals.UART;
@@ -14,4 +15,2 @@
using Antmicro.Migrant;
-using Mono.Unix;
-using System.IO;
#endif
@@ -49,3 +48,3 @@
{
- symlink.Delete();
+ File.Delete(linkName);
}
@@ -53,3 +52,3 @@
{
- throw new RecoverableException(string.Format("There was an error when removing symlink `{0}': {1}", symlink.FullName, e.Message));
+ throw new RecoverableException(string.Format("There was an error when removing symlink `{0}': {1}", symlink, e.Message));
}
@@ -105,4 +104,4 @@
{
- var slavePtyFile = new UnixFileInfo(ptyStream.SlaveName);
- symlink = slavePtyFile.CreateSymbolicLink(linkName);
+ symlink = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
+ File.CreateSymbolicLink(symlink, ptyStream.SlaveName);
}
@@ -114,4 +113,2 @@

- private UnixSymbolicLinkInfo symlink;
-
private readonly bool forceCreate;
@@ -122,2 +119,4 @@
private IOProvider io;
+ [Transient]
+ private string symlink;
}
--- a/src/Renode/Program.cs 2024-09-17 03:09:19.000000000 -0500
+++ b/src/Renode/Program.cs 2025-01-26 11:07:01.717709447 -0600
@@ -98,3 +98,3 @@
ConfigurationManager.Instance.Get("general", "terminal", "Termsharp");
- ConsoleBackend.Instance.ReportRepeatingLines = !ConfigurationManager.Instance.Get("general", "collapse-repeated-log-entries", true);
+ // Logger.LogEntriesLimit = ConfigurationManager.Instance.Get("general", "log-entries-limit", 10000);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--- a/src/Renode/Renode_NET.csproj
+++ b/src/Renode/Renode_NET.csproj
@@ -29 +29 @@
- <PackageReference Include="IronPython.StdLib" Version="2.7.11" />
+ <PackageReference Include="IronPython.StdLib" Version="2.7.12" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- a/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj
+++ b/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj
@@ -18,5 +18,4 @@
<PackageReference Include="Moq" Version="4.18.1" />
- <Reference Include="IronPython">
- <HintPath>..\..\..\..\..\..\..\lib\resources\libraries\ironpython-netcore\IronPython.dll</HintPath>
- </Reference>
+ <PackageReference Include="IronPython" Version="2.7.12" />
+ <PackageReference Include="IronPython.StdLib" Version="2.7.12" />
<PackageReference Include="NUnit" Version="3.13.1" />
--- a/src/Emulator/Main/Foreign/Player.cs
+++ b/src/Emulator/Main/Foreign/Player.cs
@@ -26,3 +26,4 @@
this.stream = stream;
+ byte[] metadataBytes = null;
- deserializer = new Serializer(new Settings(useBuffering: false, disableTypeStamping: true)).ObtainOpenStreamDeserializer(stream);
+ deserializer = new Serializer(new Settings(useBuffering: false, disableTypeStamping: true)).ObtainOpenStreamDeserializer(stream, out metadataBytes);
handlersCache = new Dictionary<NameAndHandler, Delegate>();
Loading
Loading