]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ASoC: SOF: Introduce offset in firmware data
authorKarol Trzcinski <karolx.trzcinski@linux.intel.com>
Wed, 15 Apr 2020 20:27:55 +0000 (15:27 -0500)
committerMark Brown <broonie@kernel.org>
Wed, 15 Apr 2020 23:23:00 +0000 (00:23 +0100)
It makes possible to provide extra information to host
before downloading firmware. Extra data should be put
at the beginning of firmware binary.
Exchange is done without any effort on DSP side.
This mechanism will be used in extended manifest.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20200415202816.934-4-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/sof.h
sound/soc/sof/intel/hda-loader.c
sound/soc/sof/loader.c

index a0cbca02123074fdf95b366a2f526915d133f8ff..969f554b0b7da8c12a420e6b3e528b7b11232fe9 100644 (file)
@@ -27,6 +27,9 @@ struct snd_sof_pdata {
 
        struct device *dev;
 
+       /* indicate how many first bytes shouldn't be loaded into DSP memory. */
+       size_t fw_offset;
+
        /*
         * notification callback used if the hardware initialization
         * can take time or is handled in a workqueue. This callback
index e1550ccd0a49b4df52a0e7a74d2a96d7b1ac05e8..1beaaf5879e21d39aeed0459e0feefddc129ea55 100644 (file)
@@ -293,8 +293,13 @@ int hda_dsp_cl_boot_firmware(struct snd_sof_dev *sdev)
 
        chip_info = desc->chip_info;
 
-       stripped_firmware.data = plat_data->fw->data;
-       stripped_firmware.size = plat_data->fw->size;
+       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;
+       }
+
+       stripped_firmware.data = plat_data->fw->data + plat_data->fw_offset;
+       stripped_firmware.size = plat_data->fw->size - plat_data->fw_offset;
 
        /* init for booting wait */
        init_waitqueue_head(&sdev->boot_wait);
index 312f7fffcb2cc24ceb3decd5c97632a0786cf32f..89f35db2577d7d579214fc1b52dfd6f8e3713379 100644 (file)
@@ -379,12 +379,19 @@ int snd_sof_parse_module_memcpy(struct snd_sof_dev *sdev,
 }
 EXPORT_SYMBOL(snd_sof_parse_module_memcpy);
 
-static int check_header(struct snd_sof_dev *sdev, const struct firmware *fw)
+static int check_header(struct snd_sof_dev *sdev, const struct firmware *fw,
+                       size_t fw_offset)
 {
        struct snd_sof_fw_header *header;
+       size_t fw_size = 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;
+       }
 
        /* Read the header information from the data pointer */
-       header = (struct snd_sof_fw_header *)fw->data;
+       header = (struct snd_sof_fw_header *)(fw->data + fw_offset);
 
        /* verify FW sig */
        if (strncmp(header->sig, SND_SOF_FW_SIG, SND_SOF_FW_SIG_SIZE) != 0) {
@@ -393,9 +400,9 @@ static int check_header(struct snd_sof_dev *sdev, const struct firmware *fw)
        }
 
        /* check size is valid */
-       if (fw->size != header->file_size + sizeof(*header)) {
+       if (fw_size != header->file_size + sizeof(*header)) {
                dev_err(sdev->dev, "error: invalid filesize mismatch got 0x%zx expected 0x%zx\n",
-                       fw->size, header->file_size + sizeof(*header));
+                       fw_size, header->file_size + sizeof(*header));
                return -EINVAL;
        }
 
@@ -406,7 +413,8 @@ static int check_header(struct snd_sof_dev *sdev, const struct firmware *fw)
        return 0;
 }
 
-static int load_modules(struct snd_sof_dev *sdev, const struct firmware *fw)
+static int load_modules(struct snd_sof_dev *sdev, const struct firmware *fw,
+                       size_t fw_offset)
 {
        struct snd_sof_fw_header *header;
        struct snd_sof_mod_hdr *module;
@@ -415,14 +423,15 @@ static int load_modules(struct snd_sof_dev *sdev, const struct firmware *fw)
        int ret, count;
        size_t remaining;
 
-       header = (struct snd_sof_fw_header *)fw->data;
+       header = (struct snd_sof_fw_header *)(fw->data + fw_offset);
        load_module = sof_ops(sdev)->load_module;
        if (!load_module)
                return -EINVAL;
 
        /* parse each module */
-       module = (struct snd_sof_mod_hdr *)((u8 *)(fw->data) + sizeof(*header));
-       remaining = fw->size - sizeof(*header);
+       module = (struct snd_sof_mod_hdr *)(fw->data + fw_offset +
+                                           sizeof(*header));
+       remaining = fw->size - sizeof(*header) - fw_offset;
        /* check for wrap */
        if (remaining > fw->size) {
                dev_err(sdev->dev, "error: fw size smaller than header size\n");
@@ -502,7 +511,7 @@ int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev)
                return ret;
 
        /* make sure the FW header and file is valid */
-       ret = check_header(sdev, plat_data->fw);
+       ret = check_header(sdev, plat_data->fw, plat_data->fw_offset);
        if (ret < 0) {
                dev_err(sdev->dev, "error: invalid FW header\n");
                goto error;
@@ -516,7 +525,7 @@ int snd_sof_load_firmware_memcpy(struct snd_sof_dev *sdev)
        }
 
        /* parse and load firmware modules to DSP */
-       ret = load_modules(sdev, plat_data->fw);
+       ret = load_modules(sdev, plat_data->fw, plat_data->fw_offset);
        if (ret < 0) {
                dev_err(sdev->dev, "error: invalid FW modules\n");
                goto error;