From 28272b550f2feda2b66a479c551b624d80b0b14a Mon Sep 17 00:00:00 2001 From: Ivan Griffin Date: Wed, 13 Nov 2024 09:42:13 +0000 Subject: [PATCH] fix(hss-payload-generator): Order of YAML issue The following chunk of HSS payload generator YAML was causing the hss-payload-generator tool to seg fault: priv-mode : prv_s owner-hart : u54_1 ... whereas having owner-hart appear first worked fine. Fixing this to ensure that the order does not matter. Signed-off-by: Ivan Griffin --- tools/hss-payload-generator/main.c | 2 +- tools/hss-payload-generator/yaml_parser.c | 58 +++++++++++------------ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/tools/hss-payload-generator/main.c b/tools/hss-payload-generator/main.c index 599b7dba..3778bb23 100644 --- a/tools/hss-payload-generator/main.c +++ b/tools/hss-payload-generator/main.c @@ -41,7 +41,7 @@ #include "dump_payload.h" #include "debug_printf.h" -#define GEN_VERSION_STRING "0.99.42" +#define GEN_VERSION_STRING "0.99.43" struct HSS_BootImage bootImage; struct HSS_BootChunkDesc *pChunkDescs; diff --git a/tools/hss-payload-generator/yaml_parser.c b/tools/hss-payload-generator/yaml_parser.c index 6f05b5f8..4b0bf561 100644 --- a/tools/hss-payload-generator/yaml_parser.c +++ b/tools/hss-payload-generator/yaml_parser.c @@ -725,6 +725,25 @@ static void Handle_STATE_NEW_PAYLOAD(yaml_event_t *pEvent) } } + debug_printf(1, "\tpriv_mode is %u\n", base_priv_mode); + debug_printf(2, "\tSetting priv mode for %d to %d\n", base_owner, base_priv_mode); + + bootImage.hart[base_owner-1].privMode = base_priv_mode; + + for (size_t i = 0u; i < ARRAY_SIZE(base_secondary); i++) { + if (base_secondary[i] != 0u) { + if (bootImage.hart[base_secondary[i]-1].privMode == PRV_ILLEGAL) { + debug_printf(2, "\tSetting priv mode for %d to %d\n", base_secondary[i], base_priv_mode); + bootImage.hart[base_secondary[i]-1].privMode = base_priv_mode; + } else { + fprintf(stderr, "Attempted to set U54_%" PRIu64 " to priv_mode %u, but it is already set to %u\n" + "Please check configuration file\n", + base_secondary[i], base_priv_mode, bootImage.hart[base_secondary[i]-1].privMode); + exit(EXIT_FAILURE); + } + } + } + assert(base_owner); if (strlen(bootImage.hart[base_owner-1].name)) { concatenate(bootImage.hart[base_owner-1].name, "+", @@ -757,7 +776,7 @@ static void Handle_STATE_NEW_PAYLOAD(yaml_event_t *pEvent) break; case YAML_SCALAR_EVENT: - // debug_printf(0, "Parsing scalar >>%s<<\n", pEvent->data.scalar.value); + debug_printf(7, "Parsing scalar >>%s<<\n", pEvent->data.scalar.value); token_idx = string_to_scalar(pEvent->data.scalar.value); switch (token_idx) { @@ -891,7 +910,7 @@ static void Handle_STATE_NEW_PAYLOAD_SECONDARY_HART(yaml_event_t *pEvent) enum token token_idx; -//printf("%s(): event %d / token %s\n", __func__, pEvent->type, pEvent->data.scalar.value); + debug_printf(7, "%s(): event %d / token %s\n", __func__, pEvent->type, pEvent->data.scalar.value); switch (pEvent->type) { case YAML_MAPPING_START_EVENT: break; @@ -1016,25 +1035,6 @@ static void Handle_STATE_NEW_PAYLOAD_PRIV_MODE(yaml_event_t *pEvent) __attribute__((fallthrough)); // deliberate fallthrough case TOKEN_PRIV_MODE_U: base_priv_mode = map_token_to_priv_mode(token_idx); - - debug_printf(1, "\tpriv_mode is %u\n", base_priv_mode); - debug_printf(2, "\tSetting priv mode for %d to %d\n", base_owner, base_priv_mode); - - bootImage.hart[base_owner-1].privMode = base_priv_mode; - - for (size_t i = 0u; i < ARRAY_SIZE(base_secondary); i++) { - if (base_secondary[i] != 0u) { - if (bootImage.hart[base_secondary[i]-1].privMode == PRV_ILLEGAL) { - debug_printf(2, "\tSetting priv mode for %d to %d\n", base_secondary[i], base_priv_mode); - bootImage.hart[base_secondary[i]-1].privMode = base_priv_mode; - } else { - fprintf(stderr, "Attempted to set U54_%" PRIu64 " to priv_mode %u, but it is already set to %u\n" - "Please check configuration file\n", - base_secondary[i], base_priv_mode, bootImage.hart[base_secondary[i]-1].privMode); - exit(EXIT_FAILURE); - } - } - } Do_State_Transition(STATE_NEW_PAYLOAD); break; @@ -1163,7 +1163,7 @@ static void Handle_STATE_NEW_PAYLOAD_ANCILLIARY_DATA(yaml_event_t *pEvent) { assert(pEvent); - //printf("%s(): event %d / token %s\n", __func__, pEvent->type, pEvent->data.scalar.value); + debug_printf(7, "%s(): event %d / token %s\n", __func__, pEvent->type, pEvent->data.scalar.value); switch (pEvent->type) { case YAML_MAPPING_START_EVENT: break; @@ -1210,22 +1210,18 @@ void yaml_parser(char const * const input_filename) } strncpy(bootImage.set_name, "PolarFireSOC-HSS::", BOOT_IMAGE_MAX_NAME_LEN-2); - bootImage.hart[0].privMode = PRV_ILLEGAL; - bootImage.hart[1].privMode = PRV_ILLEGAL; - bootImage.hart[2].privMode = PRV_ILLEGAL; - bootImage.hart[3].privMode = PRV_ILLEGAL; - bootImage.hart[0].flags = 0u; - bootImage.hart[1].flags = 0u; - bootImage.hart[2].flags = 0u; - bootImage.hart[3].flags = 0u; + for (int i = 0; i < 4; i++) { + bootImage.hart[i].privMode = PRV_ILLEGAL; + bootImage.hart[i].flags = 0u; + } yaml_parser_set_input_file(&parser, configFileIn); yaml_event_t event; do { if (!yaml_parser_parse(&parser, &event)) { - perror("yaml_parser_parse()"); + fprintf(stderr, "yaml_parser_parse(): %d\n", parser.error); exit(EXIT_FAILURE); }