Skip to contentSkip to conversation

ASoC: SOF: extended manifest support for 5.8

PATCH In review Kai Vehmanen 2 participants 7 messages May 20, 2020 – May 25, 2020

Subsystems (3)
lore
Share & tools
lore

Kai Vehmanen

author reviewer
#0 lore raw

cover ASoC: SOF: extended manifest support for 5.8

Hello,

extended firmware manifest is a method to retrieve capabilities directly from the firmware file instead of routing the information via the DSP and reading it back via IPC (latter mechanism still supported but will be deprecated).

This feature was briefly merged to 5.8 with the series sent on 2020-Apr-15, but due to a regression hit with exporting uapi headers, the patches got dropped.

Here's an update with the uapi header issue fixed, rebased to latest 'for-5.8' and a few minor fixes. This has been sitting in sof-dev for some weeks and no further issues have been found. We also added a check for the uapi-export case to SOF CI, so such errors would not slip through again in the future.

Tooling support to create firmware files with an extended header is available in SOF firmware repository (see the rimage tool) and this part is already merged.

Karol Trzcinski (5):
ASoC: SOF: loader: Adjust validation condition for fw_offset
ASoC: SOF: Introduce extended manifest
ASoC: SOF: ext_manifest: parse firmware version
ASoC: SOF: ext_manifest: parse windows
ASoC: SOF: ext_manifest: parse compiler version

 include/sound/sof/ext_manifest.h |  95 +++++++++++++++++
 sound/soc/sof/intel/hda-loader.c |   2 +-
 sound/soc/sof/loader.c           | 176 ++++++++++++++++++++++++++++++-
 3 files changed, 269 insertions(+), 4 deletions(-)
 create mode 100644 include/sound/sof/ext_manifest.h
Signature · 1 line
2.26.2
author reviewer
#2 lore raw

PATCH 2/5 ASoC: SOF: Introduce extended manifest

From: Karol Trzcinski <[email protected]>

Extended manifest is a place to store build time known firmware metadata, for example firmware version or used compiler description. Given information is read on host side before firmware startup. This part of output binary is located as a first structure in binary file.
Extended manifest should be skipped in firmware loading routine.

---
 include/sound/sof/ext_manifest.h |  65 ++++++++++++++++++
 sound/soc/sof/loader.c           | 112 +++++++++++++++++++++++++++++++
 2 files changed, 177 insertions(+)
 create mode 100644 include/sound/sof/ext_manifest.h
include/sound/sof/ext_manifest.h new file +65 -0
new file mode 100644
index 000000000000..5c1f03603919
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
+/*
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * Copyright(c) 2020 Intel Corporation. All rights reserved.
+ */
+
+/*
+ * Extended manifest is a place to store metadata about firmware, known during
+ * compilation time - for example firmware version or used compiler.
+ * Given information are read on host side before firmware startup.
+ * This part of output binary is not signed.
+ */
+
+#ifndef __SOF_FIRMWARE_EXT_MANIFEST_H__
+#define __SOF_FIRMWARE_EXT_MANIFEST_H__
+
+#include <linux/bits.h>
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+/* In ASCII `XMan` */
+#define SOF_EXT_MAN_MAGIC_NUMBER	0x6e614d58
+
+/* Build u32 number in format MMmmmppp */
+#define SOF_EXT_MAN_BUILD_VERSION(MAJOR, MINOR, PATH) ((uint32_t)( \
+	((MAJOR) << 24) | \
+	((MINOR) << 12) | \
+	(PATH)))
+
+/* check extended manifest version consistency */
+#define SOF_EXT_MAN_VERSION_INCOMPATIBLE(host_ver, cli_ver) ( \
+	((host_ver) & GENMASK(31, 24)) != \
+	((cli_ver) & GENMASK(31, 24)))
+
+/* used extended manifest header version */
+#define SOF_EXT_MAN_VERSION		SOF_EXT_MAN_BUILD_VERSION(1, 0, 0)
+
+/* extended manifest header, deleting any field breaks backward compatibility */
+struct sof_ext_man_header {
+	uint32_t magic;		/*< identification number, */
+				/*< EXT_MAN_MAGIC_NUMBER */
+	uint32_t full_size;	/*< [bytes] full size of ext_man, */
+				/*< (header + content + padding) */
+	uint32_t header_size;	/*< [bytes] makes header extensionable, */
+				/*< after append new field to ext_man header */
+				/*< then backward compatible won't be lost */
+	uint32_t header_version; /*< value of EXT_MAN_VERSION */
+				/*< not related with following content */
+
+	/* just after this header should be list of ext_man_elem_* elements */
+} __packed;
+
+/* Now define extended manifest elements */
+
+/* extended manifest element header */
+struct sof_ext_man_elem_header {
+	uint32_t type;		/*< SOF_EXT_MAN_ELEM_ */
+	uint32_t size;		/*< in bytes, including header size */
+
+	/* just after this header should be type dependent content */
+} __packed;
+
+#endif /* __SOF_FIRMWARE_EXT_MANIFEST_H__ */
sound/soc/sof/loader.c +112 -0

141 lines not on this page · raw message

Signature · 1 line
2.26.2
author reviewer
#3 lore raw

PATCH 3/5 ASoC: SOF: ext_manifest: parse firmware version

In reply to Kai Vehmanen

From: Karol Trzcinski <[email protected]>

The firmware version can be extracted from the extended manifest content. This information known at build time does not need to be provided in a mailbox.

---
 include/sound/sof/ext_manifest.h | 14 ++++++++++++++
 sound/soc/sof/loader.c           | 16 ++++++++++++++++
 2 files changed, 30 insertions(+)
include/sound/sof/ext_manifest.h +14 -0
index 5c1f03603919..6ed787eb788c 100644
@@ -19,6 +19,7 @@
 #include <linux/bits.h>
 #include <linux/compiler.h>
 #include <linux/types.h>
+#include <sound/sof/info.h>
 
 /* In ASCII `XMan` */
 #define SOF_EXT_MAN_MAGIC_NUMBER	0x6e614d58
@@ -54,6 +55,11 @@ struct sof_ext_man_header {
 
 /* Now define extended manifest elements */
 
+/* Extended manifest elements types */
+enum sof_ext_man_elem_type {
+	SOF_EXT_MAN_ELEM_FW_VERSION		= 0,
+};
+
 /* extended manifest element header */
 struct sof_ext_man_elem_header {
 	uint32_t type;		/*< SOF_EXT_MAN_ELEM_ */
@@ -62,4 +68,12 @@ struct sof_ext_man_elem_header {
 	/* just after this header should be type dependent content */
 } __packed;
 
+/* FW version */
+struct sof_ext_man_fw_version {
+	struct sof_ext_man_elem_header hdr;
+	/* use sof_ipc struct because of code re-use */
+	struct sof_ipc_fw_version version;
+	uint32_t flags;
+} __packed;
+
 #endif /* __SOF_FIRMWARE_EXT_MANIFEST_H__ */
sound/soc/sof/loader.c +16 -0
index a2c2dc17e9ab..8b42613304a7 100644
@@ -127,6 +127,19 @@ int snd_sof_fw_parse_ext_data(struct snd_sof_dev *sdev, u32 bar, u32 offset)
 }
 EXPORT_SYMBOL(snd_sof_fw_parse_ext_data);
 
+static int ext_man_get_fw_version(struct snd_sof_dev *sdev,
+				  const struct sof_ext_man_elem_header *hdr)
+{
+	const struct sof_ext_man_fw_version *v =
+		container_of(hdr, struct sof_ext_man_fw_version, hdr);
+
+	memcpy(&sdev->fw_ready.version, &v->version, sizeof(v->version));
+	sdev->fw_ready.flags = v->flags;
+
+	/* log ABI versions and check FW compatibility */
+	return snd_sof_ipc_valid(sdev);
+}
+
 static ssize_t snd_sof_ext_man_size(const struct firmware *fw)
 {
 	const struct sof_ext_man_header *head;
@@ -197,6 +210,9 @@ static int snd_sof_fw_ext_man_parse(struct snd_sof_dev *sdev,
 
 		/* process structure data */
 		switch (elem_hdr->type) {
+		case SOF_EXT_MAN_ELEM_FW_VERSION:
+			ret = ext_man_get_fw_version(sdev, elem_hdr);
+			break;
 		default:
 			dev_warn(sdev->dev, "warning: unknown sof_ext_man header type %d size 0x%X\n",
 				 elem_hdr->type, elem_hdr->size);
Signature · 1 line
2.26.2
author reviewer
#5 lore raw

PATCH 5/5 ASoC: SOF: ext_manifest: parse compiler version

In reply to Kai Vehmanen

From: Karol Trzcinski <[email protected]>

The compiler version and description can be extracted from the extended manifest content. This information known at build time does not need to be provided in a mailbox.

---
 include/sound/sof/ext_manifest.h |  8 ++++++++
 sound/soc/sof/loader.c           | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+)
include/sound/sof/ext_manifest.h +8 -0
index 0001fc5779ef..04359cda92dc 100644
@@ -59,6 +59,7 @@ struct sof_ext_man_header {
 enum sof_ext_man_elem_type {
 	SOF_EXT_MAN_ELEM_FW_VERSION		= 0,
 	SOF_EXT_MAN_ELEM_WINDOW			= SOF_IPC_EXT_WINDOW,
+	SOF_EXT_MAN_ELEM_CC_VERSION		= SOF_IPC_EXT_CC_INFO,
 };
 
 /* extended manifest element header */
@@ -84,4 +85,11 @@ struct sof_ext_man_window {
 	struct sof_ipc_window ipc_window;
 } __packed;
 
+/* Used C compiler description */
+struct sof_ext_man_cc_version {
+	struct sof_ext_man_elem_header hdr;
+	/* use sof_ipc struct because of code re-use */
+	struct sof_ipc_cc_version cc_version;
+} __packed;
+
 #endif /* __SOF_FIRMWARE_EXT_MANIFEST_H__ */
sound/soc/sof/loader.c +21 -0
index 6e92a1285b91..b94fa5f5d480 100644
@@ -49,6 +49,14 @@ static int get_cc_info(struct snd_sof_dev *sdev,
 	const struct sof_ipc_cc_version *cc =
 		container_of(ext_hdr, struct sof_ipc_cc_version, ext_hdr);
 
+	if (sdev->cc_version) {
+		if (memcmp(sdev->cc_version, cc, cc->ext_hdr.hdr.size)) {
+			dev_err(sdev->dev, "error: receive diverged cc_version descriptions");
+			return -EINVAL;
+		}
+		return 0;
+	}
+
 	dev_dbg(sdev->dev, "Firmware info: used compiler %s %d:%d:%d%s used optimization flags %s\n",
 		cc->name, cc->major, cc->minor, cc->micro, cc->desc,
 		cc->optim);
@@ -158,6 +166,16 @@ static int ext_man_get_windows(struct snd_sof_dev *sdev,
 	return get_ext_windows(sdev, &w->ipc_window.ext_hdr);
 }
 
+static int ext_man_get_cc_info(struct snd_sof_dev *sdev,
+			       const struct sof_ext_man_elem_header *hdr)
+{
+	const struct sof_ext_man_cc_version *cc;
+
+	cc = container_of(hdr, struct sof_ext_man_cc_version, hdr);
+
+	return get_cc_info(sdev, &cc->cc_version.ext_hdr);
+}
+
 static ssize_t snd_sof_ext_man_size(const struct firmware *fw)
 {
 	const struct sof_ext_man_header *head;
@@ -234,6 +252,9 @@ static int snd_sof_fw_ext_man_parse(struct snd_sof_dev *sdev,
 		case SOF_EXT_MAN_ELEM_WINDOW:
 			ret = ext_man_get_windows(sdev, elem_hdr);
 			break;
+		case SOF_EXT_MAN_ELEM_CC_VERSION:
+			ret = ext_man_get_cc_info(sdev, elem_hdr);
+			break;
 		default:
 			dev_warn(sdev->dev, "warning: unknown sof_ext_man header type %d size 0x%X\n",
 				 elem_hdr->type, elem_hdr->size);
Signature · 1 line
2.26.2
author reviewer
#4 lore raw

PATCH 4/5 ASoC: SOF: ext_manifest: parse windows

In reply to Kai Vehmanen

From: Karol Trzcinski <[email protected]>

The window description can be extracted from the extended manifest content. This information known at build time does not need to be provided in a mailbox.

---
 include/sound/sof/ext_manifest.h |  8 ++++++++
 sound/soc/sof/loader.c           | 25 +++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)
include/sound/sof/ext_manifest.h +8 -0
index 6ed787eb788c..0001fc5779ef 100644
@@ -58,6 +58,7 @@ struct sof_ext_man_header {
 /* Extended manifest elements types */
 enum sof_ext_man_elem_type {
 	SOF_EXT_MAN_ELEM_FW_VERSION		= 0,
+	SOF_EXT_MAN_ELEM_WINDOW			= SOF_IPC_EXT_WINDOW,
 };
 
 /* extended manifest element header */
@@ -76,4 +77,11 @@ struct sof_ext_man_fw_version {
 	uint32_t flags;
 } __packed;
 
+/* extended data memory windows for IPC, trace and debug */
+struct sof_ext_man_window {
+	struct sof_ext_man_elem_header hdr;
+	/* use sof_ipc struct because of code re-use */
+	struct sof_ipc_window ipc_window;
+} __packed;
+
 #endif /* __SOF_FIRMWARE_EXT_MANIFEST_H__ */
sound/soc/sof/loader.c +23 -2
index 8b42613304a7..6e92a1285b91 100644
@@ -20,13 +20,21 @@ static int get_ext_windows(struct snd_sof_dev *sdev,
 {
 	const struct sof_ipc_window *w =
 		container_of(ext_hdr, struct sof_ipc_window, ext_hdr);
+	size_t w_size = struct_size(w, window, w->num_windows);
 
 	if (w->num_windows == 0 || w->num_windows > SOF_IPC_MAX_ELEMS)
 		return -EINVAL;
 
+	if (sdev->info_window) {
+		if (memcmp(sdev->info_window, w, w_size)) {
+			dev_err(sdev->dev, "error: mismatch between window descriptor from extended manifest and mailbox");
+			return -EINVAL;
+		}
+		return 0;
+	}
+
 	/* keep a local copy of the data */
-	sdev->info_window = kmemdup(w, struct_size(w, window, w->num_windows),
-				    GFP_KERNEL);
+	sdev->info_window = kmemdup(w, w_size, GFP_KERNEL);
 	if (!sdev->info_window)
 		return -ENOMEM;
 
@@ -140,6 +148,16 @@ static int ext_man_get_fw_version(struct snd_sof_dev *sdev,
 	return snd_sof_ipc_valid(sdev);
 }
 
+static int ext_man_get_windows(struct snd_sof_dev *sdev,
+			       const struct sof_ext_man_elem_header *hdr)
+{
+	const struct sof_ext_man_window *w;
+
+	w = container_of(hdr, struct sof_ext_man_window, hdr);
+
+	return get_ext_windows(sdev, &w->ipc_window.ext_hdr);
+}
+
 static ssize_t snd_sof_ext_man_size(const struct firmware *fw)
 {
 	const struct sof_ext_man_header *head;
@@ -213,6 +231,9 @@ static int snd_sof_fw_ext_man_parse(struct snd_sof_dev *sdev,
 		case SOF_EXT_MAN_ELEM_FW_VERSION:
 			ret = ext_man_get_fw_version(sdev, elem_hdr);
 			break;
+		case SOF_EXT_MAN_ELEM_WINDOW:
+			ret = ext_man_get_windows(sdev, elem_hdr);
+			break;
 		default:
 			dev_warn(sdev->dev, "warning: unknown sof_ext_man header type %d size 0x%X\n",
 				 elem_hdr->type, elem_hdr->size);
Signature · 1 line
2.26.2
author reviewer
#1 lore raw

PATCH 1/5 ASoC: SOF: loader: Adjust validation condition for fw_offset

In reply to Kai Vehmanen

From: Karol Trzcinski <[email protected]>

Condition in if statement should be same as trace message and FW size equal to zero (after skipping offset) should be marked as invalid.

---
 sound/soc/sof/intel/hda-loader.c | 2 +-
 sound/soc/sof/loader.c           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
sound/soc/sof/intel/hda-loader.c +1 -1
index d762b3e1ce4a..441d05cda604 100644
@@ -293,7 +293,7 @@ int hda_dsp_cl_boot_firmware(struct snd_sof_dev *sdev)
 
 	chip_info = desc->chip_info;
 
-	if (plat_data->fw->size < plat_data->fw_offset) {
+	if (plat_data->fw->size <= plat_data->fw_offset) {
 		dev_err(sdev->dev, "error: firmware size must be greater than firmware offset\n");
 		return -EINVAL;
 	}
sound/soc/sof/loader.c +1 -1
index 4a5b57ecf359..eed3d1e65685 100644
@@ -385,7 +385,7 @@ static int check_header(struct snd_sof_dev *sdev, const struct firmware *fw,
 	struct snd_sof_fw_header *header;
 	size_t fw_size = fw->size - fw_offset;
 
-	if (fw->size < fw_offset) {
+	if (fw->size <= fw_offset) {
 		dev_err(sdev->dev, "error: firmware size must be greater than firmware offset\n");
 		return -EINVAL;
 	}
Signature · 1 line
2.26.2
maintainer
#6 lore raw
In reply to Kai Vehmanen
Quoted 10 lines · Kai Vehmanen

extended firmware manifest is a method to retrieve capabilities directly from the firmware file instead of routing the information via the DSP and reading it back via IPC (latter mechanism still supported but will be deprecated).

This feature was briefly merged to 5.8 with the series sent on 2020-Apr-15, but due to a regression hit with exporting uapi headers, the patches got dropped.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/5] ASoC: SOF: loader: Adjust validation condition for fw_offset

      commit: 523773b9ea9f430810332aa117ea48f8feafce9a
[2/5] ASoC: SOF: Introduce extended manifest
      commit: a80cf1987a6e728b4d5c8e5041132d46e89c7a45
[3/5] ASoC: SOF: ext_manifest: parse firmware version
      commit: 3e2a89d3ee052ef5346ba933e557c807333ced11
[4/5] ASoC: SOF: ext_manifest: parse windows
      commit: 8d809c15acf23bb2863ec08578ab72de860b3abc
[5/5] ASoC: SOF: ext_manifest: parse compiler version
      commit: 4c4a975178ef06324c80baef0e95209f431645a5

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark