[PATCH] Add magic number support for HW/SW compatibility check

21 views
Skip to first unread message

Isak Lichtenstein

unread,
Aug 25, 2014, 9:44:28 AM8/25/14
to swup...@googlegroups.com
This patch allows to define a magic number to override the
hardware / software compatibility check. Any update package having
defined the magic number in the hardware-compatibility field of its
sw-description file will be installed even when the hw/sw compatibility check
is enabled.

To enable this option HW_COMPATIBILITY_MAGIC must be enabled and
HW_COMPATIBILITY_MAGIC_NUMBER must be set.

Signed-off-by: Isak Lichtenstein <isak.lic...@kistler.com>

Index: git/core/util.c
===================================================================
--- git.orig/core/util.c 2014-08-25 15:15:46.365550653 +0200
+++ git/core/util.c 2014-08-25 15:17:19.913554429 +0200
@@ -204,8 +204,13 @@
TRACE("Hardware %s Revision: %s", hwrev.boardname, hwrev.revision);
LIST_FOREACH(hw, &cfg->hardware, next) {
printf("%s %s\n", hw->revision, hwrev.revision);
- if (hw && strlen(hw->revision) == strlen(hwrev.revision) &&
- (!strcmp(hw->revision, hwrev.revision)))
+ if ( hw &&
+ ( (!strcmp(hw->revision, hwrev.revision))
+#ifdef CONFIG_HW_COMPATIBILITY_MAGIC
+ || (!strcmp(hw->revision, CONFIG_HW_COMPATIBILITY_MAGIC_NUMBER))
+#endif
+ )
+ )
return 0;
}

Index: git/Config.in
===================================================================
--- git.orig/Config.in 2014-08-25 15:15:46.365550653 +0200
+++ git/Config.in 2014-08-25 15:15:46.849550673 +0200
@@ -27,20 +27,33 @@
default n
help
If enabled, check if the hardware revision
- supports the softwrae version. Detecting the hardware
+ supports the software version. Detecting the hardware
revision is very board specific, and it cannot be generalized.
For this reason, the software expects that the detected
version is written into a file by a previous software.

config HW_COMPATIBILITY_FILE
- string "File with detected hardare revisions"
+ string "File with detected hardware revisions"
depends on HW_COMPATIBILITY
default "/etc/hwrevision"
help
File where to read the detected hardware revsion
that must be compared with the software version.
- The file has simple entries (one per line) in the
- format of "major.minor".
+ The file has simple entries (one per line).
+
+config HW_COMPATIBILITY_MAGIC
+ bool "Allow a magic number to override hardware / software compatibility check"
+ depends on HW_COMPATIBILITY
+ default n
+ help
+ If enabled, SWupdate will allow update packages containing the defined magic number
+ in the hardware-compatibility field of its sw-description to be installed, in spite
+ the fact that it does not match the hardware compatibility string.
+
+config HW_COMPATIBILITY_MAGIC_NUMBER
+ string "Magic number to be used for overriding hardware / software compatibility check"
+ depends on HW_COMPATIBILITY_MAGIC
+ default "123456"

config LUA
bool "lua"

Stefano Babic

unread,
Aug 31, 2014, 6:22:17 AM8/31/14
to Isak Lichtenstein, swup...@googlegroups.com
Hi Isak,

On 25/08/2014 15:44, Isak Lichtenstein wrote:
> This patch allows to define a magic number to override the
> hardware / software compatibility check. Any update package having
> defined the magic number in the hardware-compatibility field of its
> sw-description file will be installed even when the hw/sw compatibility check
> is enabled.
>

Instead of defining a magic number, it is preferable to have a wildcard,
even if we do not add regex rules. Something like "*" for accepting any
hardware version.

> To enable this option HW_COMPATIBILITY_MAGIC must be enabled and
> HW_COMPATIBILITY_MAGIC_NUMBER must be set.

Drop HW_COMPATIBILITY_MAGIC_NUMBER, and instead of
HW_COMPATIBILITY_MAGIC I think something like
HW_COMPATIBILITY_ALLOW_OVERRIDE is more appropriate.
Thanks for fix that. Send a separate patch for mispelling, because
different issues are addressed.

> depends on HW_COMPATIBILITY
> default "/etc/hwrevision"
> help
> File where to read the detected hardware revsion
> that must be compared with the software version.
> - The file has simple entries (one per line) in the
> - format of "major.minor".
> + The file has simple entries (one per line).
> +
> +config HW_COMPATIBILITY_MAGIC
> + bool "Allow a magic number to override hardware / software compatibility check"
> + depends on HW_COMPATIBILITY
> + default n
> + help
> + If enabled, SWupdate will allow update packages containing the defined magic number
> + in the hardware-compatibility field of its sw-description to be installed, in spite
> + the fact that it does not match the hardware compatibility string.
> +
> +config HW_COMPATIBILITY_MAGIC_NUMBER
> + string "Magic number to be used for overriding hardware / software compatibility check"
> + depends on HW_COMPATIBILITY_MAGIC
> + default "123456"
>
> config LUA
> bool "lua"
>


Best regards,
Stefano Babic

--
=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================

Isak Lichtenstein

unread,
Sep 1, 2014, 2:35:45 AM9/1/14
to Stefano Babic, swup...@googlegroups.com
Hi Stefano,

Thank you for comments.
>
> Hi Isak,
>
> On 25/08/2014 15:44, Isak Lichtenstein wrote:
> > This patch allows to define a magic number to override the hardware /
> > software compatibility check. Any update package having defined the
> > magic number in the hardware-compatibility field of its sw-description
> > file will be installed even when the hw/sw compatibility check is
> > enabled.
> >
>
> Instead of defining a magic number, it is preferable to have a wildcard, even if we
> do not add regex rules. Something like "*" for accepting any hardware version.

See comment below.
>
> > To enable this option HW_COMPATIBILITY_MAGIC must be enabled and
> > HW_COMPATIBILITY_MAGIC_NUMBER must be set.
>
> Drop HW_COMPATIBILITY_MAGIC_NUMBER, and instead of
> HW_COMPATIBILITY_MAGIC I think something like
> HW_COMPATIBILITY_ALLOW_OVERRIDE is more appropriate.

Agreed, the naming wasn't well chosen. Never the less I would advocate to define HW_COMPATIBILITY_OVERRIDE_STRING so that the overriding wildcard can be configured for each product and isn't an integral part of SWupdate.

Obviously, the ideal implementation would support regex rules, but unfortunately I haven't got the time to implement this.

Concerning the code: if (hw && strlen(hw->revision) == strlen(hwrev.revision) && (!strcmp(hw->revision, hwrev.revision))),
Is there a special reason why you check on using strlen and strcmp? Would strcmp be enough?

BR

Isak

>
> >
> > Signed-off-by: Isak Lichtenstein <isak.lic...@kistler.com>
> >
> > Index: git/core/util.c
> >
> =============================================================
> ======
> > --- git.orig/core/util.c 2014-08-25 15:15:46.365550653 +0200
> > +++ git/core/util.c 2014-08-25 15:17:19.913554429 +0200
> > @@ -204,8 +204,13 @@
> > TRACE("Hardware %s Revision: %s", hwrev.boardname, hwrev.revision);
> > LIST_FOREACH(hw, &cfg->hardware, next) {
> > printf("%s %s\n", hw->revision, hwrev.revision);
> > - if (hw && strlen(hw->revision) == strlen(hwrev.revision) &&
> > - (!strcmp(hw->revision, hwrev.revision)))
> > + if ( hw &&
> > + ( (!strcmp(hw->revision, hwrev.revision)) #ifdef
> > +CONFIG_HW_COMPATIBILITY_MAGIC

Stefano Babic

unread,
Sep 7, 2014, 11:01:19 AM9/7/14
to Isak Lichtenstein, Stefano Babic, swup...@googlegroups.com
Hi Isak,

Am 01.09.2014 um 08:35 schrieb Isak Lichtenstein:
> Hi Stefano,
>
> Thank you for comments.
>>
>> Hi Isak,
>>
>> On 25/08/2014 15:44, Isak Lichtenstein wrote:
>>> This patch allows to define a magic number to override the hardware /
>>> software compatibility check. Any update package having defined the
>>> magic number in the hardware-compatibility field of its sw-description
>>> file will be installed even when the hw/sw compatibility check is
>>> enabled.
>>>
>>
>> Instead of defining a magic number, it is preferable to have a wildcard, even if we
>> do not add regex rules. Something like "*" for accepting any hardware version.
>
> See comment below.
>>
>>> To enable this option HW_COMPATIBILITY_MAGIC must be enabled and
>>> HW_COMPATIBILITY_MAGIC_NUMBER must be set.
>>
>> Drop HW_COMPATIBILITY_MAGIC_NUMBER, and instead of
>> HW_COMPATIBILITY_MAGIC I think something like
>> HW_COMPATIBILITY_ALLOW_OVERRIDE is more appropriate.
>
> Agreed, the naming wasn't well chosen. Never the less I would advocate to define HW_COMPATIBILITY_OVERRIDE_STRING so that the overriding wildcard can be configured for each product and isn't an integral part of SWupdate.
>

What is the benefit to have it configurable ? If it is a way to try to
hide the string, it is very easy to find, even checking the binary code.
Then there is no specific advantage to select on a product base which is
the matching string that disable the check.


> Obviously, the ideal implementation would support regex rules, but unfortunately I haven't got the time to implement this.
>

Of course, I understand it requires more effort.

> Concerning the code: if (hw && strlen(hw->revision) == strlen(hwrev.revision) && (!strcmp(hw->revision, hwrev.revision))),
> Is there a special reason why you check on using strlen and strcmp? Would strcmp be enough?
>

Yes, it is redundant. And using strncmp() instead of strcmp() is better.

Best regards,
Stefano Babic

Reply all
Reply to author
Forward
0 new messages