mtlv.git
2 weeks ago[SUBMIT] tlv_eeprom: fix bug when decoding TLV string of decimal numbers
Hugo Villeneuve [Fri, 14 Nov 2025 16:32:02 +0000 (11:32 -0500)]
[SUBMIT] tlv_eeprom: fix bug when decoding TLV string of decimal numbers

This bug is not present in U-Boot, but happens if you compile the TLV code base
with glibc.

For default or TLV_CODE_VENDOR_EXT types, the decoded value as a string is
incorrect and display only the last byte.

For example, if TLV contains type TLV_CODE_VENDOR_EXT with a length of 6,
and bytes "0x66 0x6F 0x6F 0x62 0x61 0x72", here is the decoded output:

    TLV Name             Code Len Value
    -------------------- ---- --- -----
    Vendor Extension     0xFD   6  0x72

The reason (also identified by GCC warning message below) is that the behavior
of glibc sprintf is undefined if copying takes place between objects that
overlap - for example, if s is also given as an argument to be printed under
control of the ‘%s’ conversion.

Fix by using strcat and sprintf with an intermediate variable.

This also has the nice benefit of fixing this warning:

    In function ‘sprintf’,
    inlined from ‘decode_tlv_value’ at tlv_eeprom.c:343:4:
    ...stdio2.h:30:10: warning: ‘__builtin___sprintf_chk’ argument 5 overlaps destination object ‘value’ [-Wrestrict]
    30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ...

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks ago[SUBMIT] tlv_eeprom: avoid code duplication in decode_tlv()
Hugo Villeneuve [Thu, 6 Nov 2025 16:29:14 +0000 (11:29 -0500)]
[SUBMIT] tlv_eeprom: avoid code duplication in decode_tlv()

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: add tlvinfo_show_tlv()
Hugo Villeneuve [Thu, 6 Nov 2025 16:17:48 +0000 (11:17 -0500)]
tlv_eeprom: add tlvinfo_show_tlv()

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: add decode_tlv_value()
Hugo Villeneuve [Thu, 6 Nov 2025 16:17:33 +0000 (11:17 -0500)]
tlv_eeprom: add decode_tlv_value()

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: add is_valid_tlvinfo()
Hugo Villeneuve [Wed, 5 Nov 2025 17:19:23 +0000 (12:19 -0500)]
tlv_eeprom: add is_valid_tlvinfo()

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: do not start over with default contents if invalid
Hugo Villeneuve [Wed, 5 Nov 2025 17:18:23 +0000 (12:18 -0500)]
tlv_eeprom: do not start over with default contents if invalid

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: delete old key before updating if it already exists
Hugo Villeneuve [Wed, 5 Nov 2025 17:09:58 +0000 (12:09 -0500)]
tlv_eeprom: delete old key before updating if it already exists

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: make sure key exist when deleting it
Hugo Villeneuve [Wed, 5 Nov 2025 16:50:16 +0000 (11:50 -0500)]
tlv_eeprom: make sure key exist when deleting it

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: suppress -Wstringop-truncation warning for false positive
Hugo Villeneuve [Wed, 5 Nov 2025 04:38:46 +0000 (23:38 -0500)]
tlv_eeprom: suppress -Wstringop-truncation warning for false positive

Suppress this warning:

tlv_eeprom.c:490:17: warning: ‘__builtin_strncpy’ specified bound 256 equals destination size [-Wstringop-truncation]
  490 |                 strncpy(data, strval, MAX_TLV_VALUE_LEN);
      |                 ^

Data is a fixed-length buffer, and no terminating null character is required,
thus this warning is a false positive.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv-eeprom: adapt for integration with hvtlv
Hugo Villeneuve [Wed, 5 Nov 2025 05:14:05 +0000 (00:14 -0500)]
tlv-eeprom: adapt for integration with hvtlv

Replace calls to i2c_eeprom_read/write and call eeprom_block_read/write
from main.c.

Use zlib crc32 function.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: suppress success log messages
Hugo Villeneuve [Wed, 5 Nov 2025 16:32:48 +0000 (11:32 -0500)]
tlv_eeprom: suppress success log messages

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: convert local functions to public scope
Hugo Villeneuve [Wed, 5 Nov 2025 05:04:16 +0000 (00:04 -0500)]
tlv_eeprom: convert local functions to public scope

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: remove U-Boot specific code
Hugo Villeneuve [Tue, 4 Nov 2025 17:15:40 +0000 (12:15 -0500)]
tlv_eeprom: remove U-Boot specific code

2 weeks agotlv_eeprom: fix comparison of integer expressions of different signedness
Hugo Villeneuve [Tue, 4 Nov 2025 20:20:15 +0000 (15:20 -0500)]
tlv_eeprom: fix comparison of integer expressions of different signedness

Fixes the following warnings:

tlv_eeprom.c:246:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  246 |         for (i = 0; i < ARRAY_SIZE(tlv_code_list); i++) {
      |                       ^

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agotlv_eeprom: import code from U-Boot v2026.01-rc1
Hugo Villeneuve [Tue, 4 Nov 2025 16:24:24 +0000 (11:24 -0500)]
tlv_eeprom: import code from U-Boot v2026.01-rc1

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agoAdd kernel/U-Boot compatibility header file
Hugo Villeneuve [Wed, 5 Nov 2025 05:13:56 +0000 (00:13 -0500)]
Add kernel/U-Boot compatibility header file

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agoRemove include of <linux/printk.h> in kernel.h
Hugo Villeneuve [Tue, 4 Nov 2025 18:27:23 +0000 (13:27 -0500)]
Remove include of <linux/printk.h> in kernel.h

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agoImport kernel.h from U-Boot
Hugo Villeneuve [Tue, 4 Nov 2025 18:25:18 +0000 (13:25 -0500)]
Import kernel.h from U-Boot

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agoAdd Yocto recipe
Hugo Villeneuve [Wed, 5 Nov 2025 20:48:49 +0000 (15:48 -0500)]
Add Yocto recipe

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agooptions: redefine help to replace -? with -h
Hugo Villeneuve [Mon, 17 Nov 2025 15:34:37 +0000 (10:34 -0500)]
options: redefine help to replace -? with -h

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
2 weeks agoInitial import
Hugo Villeneuve [Tue, 4 Nov 2025 18:02:54 +0000 (13:02 -0500)]
Initial import

Setup autotools project.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>