On this page

C

Building for Qt Ultralite with AUTOSAR

Building the Project

The project uses CMake for building.

The build configuration requires the following CMake variables:

  • QSR_SOURCE_DIR: Path to Qt Safe Renderer Runtime sources (typically Qt installation directory>/Src/QtSafeRenderer-runtime-2.2.0).
  • BUILD_LIBRARIES_ONLY: Optional flag to build only QSR libraries for separate AUTOSAR projects.
  • QSR_INPUT_QML: Path to the safety-critical UI design. This variable must point to the main QML file of the application.
  • SAFELAYOUT_SAFE_LAYOUT_FONTS: Directory containing the font files of the application.
  • SAFE_LAYOUT_CRC_ALGORITHM: CRC algorithm (crc32 for Renesas, mpeg2 for Traveo II).

To ensure Qt Safe Layout generation works correctly with Qt Ultralite, place the following files in the same directory:

  • The main QML file.
  • Those QML files that contain safe items.

The build configuration requires the following environment variable:

The build process includes:

  • Building QSR libraries (SafeRenderer, OutputVerifier, Monitor) into ${CMAKE_BINARY_DIR}/lib.
  • Generating monitor data from QML using the QSR Monitor Config Tool.
  • Creating a data library with CRC values for verification.
  • Linking the test executable with all required components.
  • Exporting header files to ${CMAKE_BINARY_DIR}/include for use in other projects.

To build the project, run:

mkdir build
cd build
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=<Qt installation directory>/Src/QtSafeRenderer-runtime-2.2.0/cmake/<toolchain file for your target device> -DQSR_TARGET_TOOLCHAIN_DIR="<GHS compiler installation>" -DQSR_SOURCE_DIR=<Qt installation directory>/Src/QtSafeRenderer-runtime-2.2.0
cmake --build .

Use one of the following for the toolchain file:

  • Infineon Traveo II: ghs-armv7m.cmake
  • Renesas RH850 or similar: ghs.cmake

This configuration:

  • Uses qsr_generate_monitor_data to process the QML file.
  • Creates a library containing the generated CRC data in ${CMAKE_BINARY_DIR}/lib.
  • The CRC algorithm for the target platform is set in the build configuration:
    • crc32 for Renesas RH850.
    • mpeg2 for Infineon Traveo II.

If you modify the QML layout, rebuild the project to regenerate the CRC data.

Output Verification

The QML layout defines safety items that need to be verified. Each item is identified by its QML id:

import QtQuick
import Qt.SafeRenderer

Window {
    id: test
    width: 640
    height: 480

    SafeImage {
        id: iconBattery
        objectName: "iconBattery"
        width: 64
        height: 64
        anchors.centerIn: parent
        fillColor: "black"
        source: "battery_icon.png"
    }
}

The item ID used in verification is calculated from the QML id using the qsafe_hash function:

// Calculate item ID from QML id using qsafe_hash
const char *itemName = "iconBattery";
const quint32 itemId = qsafe_hash(itemName, strlen(itemName));
const quint32 stateId = 1U; //visible
const qint32 ret = addItemToVerification(itemId, stateId);

The main.c file initializes the output verification, adds items for CRC checking, and runs the verification sequence:

// main.c
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "errorcode.h"
#include "qsafeglobal.h"
#include "qsafechecksum.h"
#include "outputverifier_capi.h"
#include "qsrmonitor.h"

int main(void)
{
    const char *itemName = "iconBattery";
    const quint32 itemId = qsafe_hash(itemName, strlen(itemName));
    const quint32 stateId = 1U; //visible
    int ret = addItemToVerification(itemId, stateId);

    printf("Testing monitor integration\n");
    initVerifierDevice(100U, 100U);
    printf("Item id: %d State id: %d\n", itemId, stateId);
    if (ret == 0) {
       OutputVerifier_verifyOutput();
       verifyOutput(defaultErrorHandler);
       return 0;
    } else {
        printf("Failed to add item for verification\n");
        return 1;
    }
}

The API addItemToVerification() adds an item and its expected state to the verification queue. Items are verified using OutputVerifier_verifyOutput() followed by verifyOutput().

The queue is FIFO-based and supports state updates automatically. The application code only needs to enqueue the new item state; internal logic ensures the latest state is verified.

The verification device is initialized with offset values to position the verification area:

void initVerifierDevice(quint32 xOffset, quint32 yOffset) {
    static SafeRenderer::OutputVerifierDevice outputVerifierDevice(xOffset, yOffset, getStaticOutputVerifier());
}

The display integrity checking stubs used by this example are:

void Cdd_Qsr_RequestCrc(quint32 x, quint32 y, quint32 width, quint32 height)
{
    // Define region to verify
    // In real implementation, this would configure the hardware CRC unit
    (void)x;
    (void)y;
    (void)width;
    (void)height;
}
void Cdd_Qsr_WaitForResult(void)
{
    // Wait for CRC calculation to complete
    // In real implementation, this would wait for hardware CRC unit
}
quint32 Cdd_Qsr_ReadCrc(void)
{
    // Read the calculated CRC value
    // In real implementation, this would read from hardware CRC unit
    return 0U;
}

These stub functions represent the device API:

For details about implementing the AUTOSAR CDD interface, see: Adapting Output Monitor to AUTOSAR

  • Cdd_Qsr_RequestCrc() - Defines the region to verify.
  • Cdd_Qsr_WaitForResult() - Waits for the result.
  • Cdd_Qsr_ReadCrc() - Reads the actual CRC.

The read CRC value is compared against the pre-generated golden CRCs. If the values do not match, the error handler is invoked to handle the verification failure.

Available under certain Qt licenses.
Find out more.