Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)

project(ra-utils
VERSION 0.11.0
VERSION 0.12.0
DESCRIPTION "Command line tools related to the Renesas MCU (aka safety controller)"
LANGUAGES C
)
Expand Down
11 changes: 10 additions & 1 deletion firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ install(

install(
FILES
ra-update.service
ra-update@.service
DESTINATION /lib/systemd/system
)

install(
DIRECTORY
ra-update@ttyLP1.service.d
ra-update@ttyLP2.service.d
DESTINATION /lib/systemd/system
FILES_MATCHING
PATTERN "*.conf"
)

install(
PROGRAMS
ra-update.sh
Expand Down
1 change: 1 addition & 0 deletions firmware/ra-update.service → firmware/ra-update@.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RequiresMountsFor=/var/log

[Service]
Type=oneshot
Environment="SAFETY_MCU_UART=/dev/%i"
ExecStart=/usr/libexec/ra-update.sh

[Install]
Expand Down
2 changes: 2 additions & 0 deletions firmware/ra-update@ttyLP1.service.d/ConditionFirmware.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Unit]
ConditionFirmware=|device-tree-compatible(chargebyte,imx93-charge-control-v)
4 changes: 4 additions & 0 deletions firmware/ra-update@ttyLP1.service.d/Environment.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Service]
Environment="SAFETY_MCU_GPIOCHIP=/dev/gpiochip1"
Environment="SAFETY_MCU_RESET_GPIO=nSAFETY2_RESET_INT"
Environment="SAFETY_MCU_MD_GPIO=SAFETY2_BOOTMODE_SET"
3 changes: 3 additions & 0 deletions firmware/ra-update@ttyLP2.service.d/ConditionFirmware.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Unit]
ConditionFirmware=|device-tree-compatible(chargebyte,imx93-charge-som)
ConditionFirmware=|device-tree-compatible(chargebyte,imx93-charge-control-y)
23 changes: 23 additions & 0 deletions src/gpio-defaults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright © 2026 chargebyte GmbH
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

/* the default gpiochip device to use */
#define DEFAULT_RA_GPIOCHIP "/dev/gpiochip2"

/* the default gpio name of the MCU reset pin */
#define DEFAULT_RA_GPIO_RESET_PIN "nSAFETY_RESET_INT"

/* the default gpio name of the gpio to toggle the MCU boot mode */
#define DEFAULT_RA_GPIO_MD_PIN "SAFETY_BOOTMODE_SET"

/* name of environment variable to override compiled-in DEFAULT_RA_GPIOCHIP */
#define GETENV_GPIOCHIP_KEY "SAFETY_MCU_GPIOCHIP"

/* name of environment variable to override compiled-in DEFAULT_RA_GPIO_RESET_PIN */
#define GETENV_RESET_PIN_KEY "SAFETY_MCU_RESET_GPIO"

/* name of environment variable to override compiled-in DEFAULT_RA_GPIO_MD_PIN */
#define GETENV_MD_PIN_KEY "SAFETY_MCU_MD_GPIO"
18 changes: 17 additions & 1 deletion src/ra-raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <version.h>
#include "ra_gpio.h"
#include "stringify.h"
#include "gpio-defaults.h"
#include "uart-defaults.h"

/* fallback if not set by build system */
Expand Down Expand Up @@ -248,6 +249,9 @@ int main(int argc, char *argv[])
struct pollfd poll_fds[2]; /* stdin at [0], UART fd at [1] */
int fds = 2;
char *env_uart_device = NULL;
char *env_gpiochip = NULL;
char *env_reset_gpioname = NULL;
char *env_md_gpioname = NULL;
struct uart_ctx uart = { .fd = -1 };
struct safety_controller ctx = {};
enum cb_uart_com com;
Expand All @@ -259,14 +263,26 @@ int main(int argc, char *argv[])
int rc = EXIT_FAILURE;
int rv;

/* check whether environment variable SAFETY_MCU_UART is set and use it
/* check whether any of the environment variables SAFETY_MCU_... is set and use it
* as default; so the resulting order is:
* compiled-in default -> can be overridden by environment -> can be overridden by cmdline
*/
env_uart_device = getenv(GETENV_UART_KEY);
if (env_uart_device)
uart_device = env_uart_device;

env_gpiochip = getenv(GETENV_GPIOCHIP_KEY);
if (env_gpiochip)
gpiochip = env_gpiochip;

env_reset_gpioname = getenv(GETENV_RESET_PIN_KEY);
if (env_reset_gpioname)
reset_gpioname = env_reset_gpioname;

env_md_gpioname = getenv(GETENV_MD_PIN_KEY);
if (env_md_gpioname)
md_gpioname = env_md_gpioname;

/* handle command line options */
parse_cli(argc, argv);

Expand Down
18 changes: 17 additions & 1 deletion src/ra-update.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "fw_file.h"
#include "ra_gpio.h"
#include "stringify.h"
#include "gpio-defaults.h"
#include "uart-defaults.h"

/* fallback if not set by build system */
Expand Down Expand Up @@ -424,6 +425,9 @@ int main(int argc, char *argv[])
{
struct version_app_infoblock version_info;
char *env_uart_device = NULL;
char *env_gpiochip = NULL;
char *env_reset_gpioname = NULL;
char *env_md_gpioname = NULL;
struct uart_ctx uart = { .fd = -1 };
struct gpio_ctx *gpio = NULL;
uint8_t *fw_content = NULL;
Expand All @@ -433,14 +437,26 @@ int main(int argc, char *argv[])
int rc = EXIT_FAILURE;
int rv;

/* check whether environment variable SAFETY_MCU_UART is set and use it
/* check whether any of the environment variables SAFETY_MCU_... is set and use it
* as default; so the resulting order is:
* compiled-in default -> can be overridden by environment -> can be overridden by cmdline
*/
env_uart_device = getenv(GETENV_UART_KEY);
if (env_uart_device)
uart_device = env_uart_device;

env_gpiochip = getenv(GETENV_GPIOCHIP_KEY);
if (env_gpiochip)
gpiochip = env_gpiochip;

env_reset_gpioname = getenv(GETENV_RESET_PIN_KEY);
if (env_reset_gpioname)
reset_gpioname = env_reset_gpioname;

env_md_gpioname = getenv(GETENV_MD_PIN_KEY);
if (env_md_gpioname)
md_gpioname = env_md_gpioname;

/* handle command line options */
parse_cli(argc, argv);

Expand Down
9 changes: 0 additions & 9 deletions src/ra_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@

#include <gpiod.h>

/* the default gpiochip device to use */
#define DEFAULT_RA_GPIOCHIP "/dev/gpiochip2"

/* the default gpio name of the MCU reset pin */
#define DEFAULT_RA_GPIO_RESET_PIN "nSAFETY_RESET_INT"

/* the default gpio name of the gpio to toogle the MCU boot mode */
#define DEFAULT_RA_GPIO_MD_PIN "SAFETY_BOOTMODE_SET"

/* forward declaration */
struct gpio_ctx;

Expand Down