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

rimage: stop ignoring errors in parse_uuid() #8366

Merged
merged 3 commits into from
Oct 26, 2023
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
6 changes: 5 additions & 1 deletion tools/rimage/src/include/rimage/toml_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ void parse_printable_key(const toml_table_t *table, struct parse_ctx *ctx, const
void parse_str_key(const toml_table_t *table, struct parse_ctx *ctx, const char *key,
char *dst, int capacity, int *error);

void parse_uuid(char *buf, uint8_t *uuid);
/**
* Parse UUID hex string into a byte array. The endianness of the output
* is architecture-dependent: do not use in any portable code.
*/
void parse_uuid(const char *buf, uint8_t *uuid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Rimage is part of sof repository can we add ifdef condition for Intel adsp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to submit a follow-up PR after this one. This is one is just a minor clean-up.


/** version is stored as toml array with integer number, something like:
* "version = [1, 8]"
Expand Down
36 changes: 21 additions & 15 deletions tools/rimage/src/toml_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <rimage/toml_utils.h>
#include <rimage/cavs/cavs_ext_manifest.h>

#include <assert.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -289,23 +290,28 @@ void parse_str_key(const toml_table_t *table, struct parse_ctx *ctx, const char
dst[capacity - 1] = 0;
}

void parse_uuid(char *buf, uint8_t *uuid)
void parse_uuid(const char *buf, uint8_t *uuid)
{
struct uuid_t id;
uint32_t d[10];

sscanf(buf, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", &id.d0, &d[0],
&d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7], &d[8], &d[9]);
id.d1 = (uint16_t)d[0];
id.d2 = (uint16_t)d[1];
id.d3 = (uint8_t)d[2];
id.d4 = (uint8_t)d[3];
id.d5 = (uint8_t)d[4];
id.d6 = (uint8_t)d[5];
id.d7 = (uint8_t)d[6];
id.d8 = (uint8_t)d[7];
id.d9 = (uint8_t)d[8];
id.d10 = (uint8_t)d[9];
uint32_t d[11];

const int parsed_uuid_fields =
sscanf(buf, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", &d[0],
&d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7], &d[8], &d[9], &d[10]);

assert(parsed_uuid_fields == 11);

id.d0 = d[0];
id.d1 = (uint16_t)d[1];
id.d2 = (uint16_t)d[2];
id.d3 = (uint8_t)d[3];
id.d4 = (uint8_t)d[4];
id.d5 = (uint8_t)d[5];
id.d6 = (uint8_t)d[6];
id.d7 = (uint8_t)d[7];
id.d8 = (uint8_t)d[8];
id.d9 = (uint8_t)d[9];
id.d10 = (uint8_t)d[10];

memcpy(uuid, &id, sizeof(id));
}
Expand Down