Re: [PATCH v4 3/3] media: iris: Add Gen2 firmware autodetect and fallback

From: Dmitry Baryshkov

Date: Wed May 13 2026 - 11:52:47 EST


On Fri, May 08, 2026 at 12:34:04AM +0530, Vikash Garodia wrote:
> On 4/29/2026 5:39 PM, Dikshita Agarwal wrote:
> > Some Iris platforms support both Gen1 and Gen2 HFI firmware images.
> > Update the firmware loading logic to handle this generically by
> > preferring Gen2 when available, while safely falling back to Gen1
> > when required.
> >
> > The firmware loading logic is updated with the following priority:
> > 1. Device Tree (`firmware-name`): If specified, load unconditionally.
> > 2. Gen2 default : If no DT override exists, select the Gen2 firmware
> > descriptor when present and attempt to load the corresponding
> > firmware image.
> > 3. Gen1 Fallback: If loading the Gen2 firmware fails and a Gen1
> > descriptor is available, retry with the Gen1 firmware image.
> >
> > When a platform provides both Gen1 and Gen2 firmware descriptors and the
> > firmware is loaded via a DT override, the driver detects the
> > firmware generation at runtime before authentication by inspecting
> > the firmware data. The firmware is classified as Gen2 if the
> > QC_IMAGE_VERSION_STRING starts with "vfw" or matches the
> > "video-firmware.N.M" format with N >= 2.
> >
> > If a Gen1 firmware image is detected in this case, the driver switches
> > to the Gen1 firmware descriptor and associated platform data so that
> > the correct HFI implementation is used.
> >
> > This change makes firmware generation detection platform‑agnostic,
> > preserves DT overrides, prefers newer Gen2 firmware when available,
> > and maintains compatibility with platforms that only support Gen1.
> >
> > Co-developed-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxxxxxxxx>
> > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxxxxxxxx>
> > Signed-off-by: Dikshita Agarwal <dikshita.agarwal@xxxxxxxxxxxxxxxx>
> > ---
> > drivers/media/platform/qcom/iris/iris_firmware.c | 105 +++++++++++++++++----
> > .../platform/qcom/iris/iris_platform_common.h | 6 +-
> > .../media/platform/qcom/iris/iris_platform_vpu2.c | 11 ++-
> > .../media/platform/qcom/iris/iris_platform_vpu3x.c | 8 +-
> > drivers/media/platform/qcom/iris/iris_probe.c | 4 -
> > drivers/media/platform/qcom/iris/iris_vidc.c | 3 +
> > 6 files changed, 105 insertions(+), 32 deletions(-)
> >
> > diff --git a/drivers/media/platform/qcom/iris/iris_firmware.c b/drivers/media/platform/qcom/iris/iris_firmware.c
> > index 1a476146d7580849d7b68c7c15dd7f82f89a680b..64a2170bf538a6d291b3d909f5563408a3a75e50 100644
> > --- a/drivers/media/platform/qcom/iris/iris_firmware.c
> > +++ b/drivers/media/platform/qcom/iris/iris_firmware.c
> > @@ -16,20 +16,95 @@
> > #define MAX_FIRMWARE_NAME_SIZE 128
> > -static int iris_load_fw_to_memory(struct iris_core *core, const char *fw_name)
> > +/* Detect Gen2 firmware by scanning the blob for:
> > + * QC_IMAGE_VERSION_STRING=<version>
> > + * and then checking:
> > + * - version starts with "vfw", OR
> > + * - version matches "video-firmware.N.M" with N >= 2
> > + */
> > +
> > +static bool iris_detect_gen2_from_fwdata(const u8 *data, size_t size)
> > +{
> > + const char *marker = "QC_IMAGE_VERSION_STRING=";
> > + const size_t mlen = strlen(marker);
> > + int major = 0, minor = 0;
> > + char version_buf[64];
> > + size_t max;
> > +
> > + max = (size > mlen) ? size - mlen : 0;
>
> better to limit the size of the blob to be parsed to 4K ? version strings
> should be in the initial part of the firmware image.
>
> A bad (and big enough) firmware blob might slow down the system with the
> current logic
>
> something like
> size = min(size, (size_t)SZ_4K);

And if you've checked the actual firmware, you'd have seen that the
version strings can't be a part of the first 4k of it. The actual
offsets (and file sizes) for existing files in linux-firmware:

venus-1.8/venus.mbn 856876 992976
venus-4.2/venus.mbn 846796 925432
venus-5.2/venus.mbn 812224 883264
venus-5.4/venus.mbn 846904 922312
venus-6.0/venus.mbn 1159212 1794924
ar50lt_p1_gen2_s6.mbn 1167572 1861732
vpu20_p1_gen2_s6.mbn 1193056 2030620
vpu20_p1.mbn: 1188900 2026452
vpu20_p4.mbn: 1178644 1980084
vpu20_p4_sm8450_s7.mbn 1199172 2024040
vpu30_p4_s6_16mb.mbn 1356852 2315172
vpu30_p4_s6.mbn 1356852 2315156
vpu30_p4_s7.mbn 1357204 2323048
vpu33_p4_s7.mbn 1345968 2343624
vpu35_p4_s7.mbn 1339952 2409160
vpu36_p4_s7.mbn 1364016 2503368
vpu40_p2_s7.mbn 1350400 2474696

I don't think we can easily limit file area to scan for the version
string.


--
With best wishes
Dmitry