[PATCH i-g-t v2 4/6] tools/intel-gfx-fw-info: Override kernel types

Lucas De Marchi lucas.demarchi at intel.com
Wed Aug 21 18:37:09 UTC 2024


On Wed, Aug 21, 2024 at 02:18:02PM GMT, Gustavo Sousa wrote:
>Quoting Lucas De Marchi (2024-08-20 20:29:26-03:00)
>>Previously we were defining u32 type as part of the string we are
>>loading. However in order to use other types like u8 and u16 in upcoming
>>changes, it would be better to have them all defined in a single place.
>>We can't create a typedef like done with u32 because cstruct already
>>defines a few types for convenience. However it's very surprising it's
>>defining e.g. u8 as a 64-bit variable.
>>
>>Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
>>---
>> tools/intel-gfx-fw-info | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>
>>diff --git a/tools/intel-gfx-fw-info b/tools/intel-gfx-fw-info
>>index 0f1da8bff..57d6f935b 100755
>>--- a/tools/intel-gfx-fw-info
>>+++ b/tools/intel-gfx-fw-info
>>@@ -23,8 +23,6 @@ import typing
>> #          dumpstruct(): give it a name
>>
>> CDEF = """
>>-typedef uint32 u32;
>>-
>> struct uc_css_header {
>>         u32 module_type;
>>         /*
>>@@ -120,6 +118,13 @@ class Fw(abc.ABC):
>>     @classmethod
>>     def create(cls, f):
>>         cparser = cstruct.cstruct()
>>+        # cstruct defines some "convenience types" that are not very convenient
>>+        # when parsing a kernel header - e.g. we don't want u16 to be parsed as
>>+        # uint128
>
>Yikes.
>
>>+        cparser.typedefs["u8"] = "uint8_t"
>>+        cparser.typedefs["u16"] = "uint16_t"
>>+        cparser.typedefs["u32"] = "uint32_t"
>>+        cparser.typedefs["u64"] = "uint64_t"
>
>Well, typedefs is exposed in the documentation, but not properly
>documented [1]...
>
>Have you tried using cparser.add_type()? Well, if that doesn't work:

yeah... if we pass cparser.add_type(..., replace=True) then it works.

>
>     Reviewed-by: Gustavo Sousa <gustavo.sousa at intel.com>

thanks
Lucas De Marchi

>
>[1] https://docs.dissect.tools/en/latest/api/dissect/cstruct/cstruct/index.html#dissect.cstruct.cstruct.cstruct.typedefs
>
>>         cparser.load(CDEF)
>>
>>         magic = cparser.magic(f).data
>>--
>>2.43.0
>>


More information about the igt-dev mailing list