objutils 0.10.1__tar.gz → 0.10.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. {objutils-0.10.1 → objutils-0.10.3}/PKG-INFO +1 -1
  2. {objutils-0.10.1 → objutils-0.10.3}/objutils/__init__.py +1 -1
  3. {objutils-0.10.1 → objutils-0.10.3}/objutils/cosmac.py +7 -4
  4. {objutils-0.10.1 → objutils-0.10.3}/objutils/emon52.py +3 -1
  5. {objutils-0.10.1 → objutils-0.10.3}/objutils/etek.py +12 -6
  6. {objutils-0.10.1 → objutils-0.10.3}/objutils/hexfile.py +3 -0
  7. {objutils-0.10.1 → objutils-0.10.3}/objutils/image.py +47 -0
  8. {objutils-0.10.1 → objutils-0.10.3}/objutils/section.py +100 -7
  9. {objutils-0.10.1 → objutils-0.10.3}/objutils/shf.py +1 -1
  10. {objutils-0.10.1 → objutils-0.10.3}/objutils/srec.py +2 -2
  11. objutils-0.10.3/objutils/tests/test_etek.py +161 -0
  12. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_image.py +27 -0
  13. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_section.py +44 -0
  14. {objutils-0.10.1 → objutils-0.10.3}/objutils/version.py +1 -1
  15. {objutils-0.10.1 → objutils-0.10.3}/pyproject.toml +2 -2
  16. {objutils-0.10.1 → objutils-0.10.3}/CMakeLists.txt +0 -0
  17. {objutils-0.10.1 → objutils-0.10.3}/LICENSE +0 -0
  18. {objutils-0.10.1 → objutils-0.10.3}/build_ext.py +0 -0
  19. {objutils-0.10.1 → objutils-0.10.3}/docs/README.rst +0 -0
  20. {objutils-0.10.1 → objutils-0.10.3}/objutils/.coveragerc +0 -0
  21. {objutils-0.10.1 → objutils-0.10.3}/objutils/.vscode/launch.json +0 -0
  22. {objutils-0.10.1 → objutils-0.10.3}/objutils/.vscode/settings.json +0 -0
  23. {objutils-0.10.1 → objutils-0.10.3}/objutils/a2l_test.shf +0 -0
  24. {objutils-0.10.1 → objutils-0.10.3}/objutils/ash.py +0 -0
  25. {objutils-0.10.1 → objutils-0.10.3}/objutils/binfile.py +0 -0
  26. {objutils-0.10.1 → objutils-0.10.3}/objutils/checksums.py +0 -0
  27. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/.traverser.py.un~ +0 -0
  28. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/__init__.py +0 -0
  29. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/attrparser.py +0 -0
  30. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/c_generator.py +0 -0
  31. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/constants.py +0 -0
  32. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/encoding.py +0 -0
  33. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/lineprog.py +0 -0
  34. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/readers.py +0 -0
  35. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/sm.py +0 -0
  36. {objutils-0.10.1 → objutils-0.10.3}/objutils/dwarf/traverser.py +0 -0
  37. {objutils-0.10.1 → objutils-0.10.3}/objutils/elf/__init__.py +0 -0
  38. {objutils-0.10.1 → objutils-0.10.3}/objutils/elf/arm/__init__.py +0 -0
  39. {objutils-0.10.1 → objutils-0.10.3}/objutils/elf/arm/attributes.py +0 -0
  40. {objutils-0.10.1 → objutils-0.10.3}/objutils/elf/defs.py +0 -0
  41. {objutils-0.10.1 → objutils-0.10.3}/objutils/elf/model.py +0 -0
  42. {objutils-0.10.1 → objutils-0.10.3}/objutils/exceptions.py +0 -0
  43. {objutils-0.10.1 → objutils-0.10.3}/objutils/extensions/__init__.py +0 -0
  44. {objutils-0.10.1 → objutils-0.10.3}/objutils/extensions/ctre.hpp +0 -0
  45. {objutils-0.10.1 → objutils-0.10.3}/objutils/extensions/difflib.h +0 -0
  46. {objutils-0.10.1 → objutils-0.10.3}/objutils/extensions/exceptions.cpp +0 -0
  47. {objutils-0.10.1 → objutils-0.10.3}/objutils/extensions/exceptions.hpp +0 -0
  48. {objutils-0.10.1 → objutils-0.10.3}/objutils/extensions/hexfile.cpp +0 -0
  49. {objutils-0.10.1 → objutils-0.10.3}/objutils/extensions/wrapper.cpp +0 -0
  50. {objutils-0.10.1 → objutils-0.10.3}/objutils/fpc.py +0 -0
  51. {objutils-0.10.1 → objutils-0.10.3}/objutils/hexdump.py +0 -0
  52. {objutils-0.10.1 → objutils-0.10.3}/objutils/ieee695.py +0 -0
  53. {objutils-0.10.1 → objutils-0.10.3}/objutils/ihex.py +0 -0
  54. {objutils-0.10.1 → objutils-0.10.3}/objutils/logger.py +0 -0
  55. {objutils-0.10.1 → objutils-0.10.3}/objutils/mostec.py +0 -0
  56. {objutils-0.10.1 → objutils-0.10.3}/objutils/objutils.code-workspace +0 -0
  57. {objutils-0.10.1 → objutils-0.10.3}/objutils/pecoff/__init__.py +0 -0
  58. {objutils-0.10.1 → objutils-0.10.3}/objutils/pecoff/defs.py +0 -0
  59. {objutils-0.10.1 → objutils-0.10.3}/objutils/pecoff/model.py +0 -0
  60. {objutils-0.10.1 → objutils-0.10.3}/objutils/pecoff/pdb/__init__.py +0 -0
  61. {objutils-0.10.1 → objutils-0.10.3}/objutils/pickleif.py +0 -0
  62. {objutils-0.10.1 → objutils-0.10.3}/objutils/rca.py +0 -0
  63. {objutils-0.10.1 → objutils-0.10.3}/objutils/readers.py +0 -0
  64. {objutils-0.10.1 → objutils-0.10.3}/objutils/registry.py +0 -0
  65. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/arduino_build_artifacts.py +0 -0
  66. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_cgen.py +0 -0
  67. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_coff_extract.py +0 -0
  68. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_coff_import.py +0 -0
  69. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_coff_info.py +0 -0
  70. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_coff_syms.py +0 -0
  71. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_dwarf_import.py +0 -0
  72. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_elf_arm_attrs.py +0 -0
  73. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_elf_extract.py +0 -0
  74. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_elf_import.py +0 -0
  75. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_elf_info.py +0 -0
  76. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_elf_syms.py +0 -0
  77. {objutils-0.10.1 → objutils-0.10.3}/objutils/scripts/oj_hex_info.py +0 -0
  78. {objutils-0.10.1 → objutils-0.10.3}/objutils/sig.py +0 -0
  79. {objutils-0.10.1 → objutils-0.10.3}/objutils/tek.py +0 -0
  80. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/__init__.py +0 -0
  81. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_arm_attributes.py +0 -0
  82. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_ash.py +0 -0
  83. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_c_generator.py +0 -0
  84. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_checksums.py +0 -0
  85. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_cygpath.py +0 -0
  86. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_diff_bin.py +0 -0
  87. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_elf.py +0 -0
  88. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_emon52.py +0 -0
  89. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_examples_cgen.py +0 -0
  90. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_fpc.py +0 -0
  91. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_hexdump.py +0 -0
  92. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_hexfile.py +0 -0
  93. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_ihex.py +0 -0
  94. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_mostec.py +0 -0
  95. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_readers.py +0 -0
  96. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_registry.py +0 -0
  97. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_repr.py +0 -0
  98. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_section_join.py +0 -0
  99. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_shf.py +0 -0
  100. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_sm.py +0 -0
  101. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_srec.py +0 -0
  102. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_tek.py +0 -0
  103. {objutils-0.10.1 → objutils-0.10.3}/objutils/tests/test_titext.py +0 -0
  104. {objutils-0.10.1 → objutils-0.10.3}/objutils/titxt.py +0 -0
  105. {objutils-0.10.1 → objutils-0.10.3}/objutils/utils/__init__.py +0 -0
  106. {objutils-0.10.1 → objutils-0.10.3}/objutils/utils/arduino.py +0 -0
  107. {objutils-0.10.1 → objutils-0.10.3}/objutils/utils/diff.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: objutils
3
- Version: 0.10.1
3
+ Version: 0.10.3
4
4
  Summary: Objectfile library for Python
5
5
  License: GPLv2
6
6
  License-File: LICENSE
@@ -13,7 +13,7 @@ Registers CODECS and implements an interface to them.
13
13
  The first parameter is always the codec name.
14
14
  """
15
15
 
16
- __version__ = "0.10.1"
16
+ __version__ = "0.10.3"
17
17
 
18
18
  __all__ = [
19
19
  "Image",
@@ -5,11 +5,14 @@ This module handles the RCA Cosmac hex format, used with RCA 1802/1804/1805
5
5
  microprocessors and COSMAC development systems.
6
6
 
7
7
  Format specification:
8
+
8
9
  - Four data record formats with optional address:
9
- 1. !MAAAA DD - Full format with start symbol
10
- 2. ?MAAAA DD - Alternate start symbol
11
- 3. AAAA DD - Address only (no symbol)
12
- 4. DD - Data only (address continues from previous)
10
+
11
+ 1. ``!MAAAA DD`` – Full format with start symbol
12
+ 2. ``?MAAAA DD`` – Alternate start symbol
13
+ 3. ``AAAA DD`` – Address only (no symbol)
14
+ 4. ``DD`` – Data only (address continues from previous)
15
+
13
16
  - M: Memory identifier (single hex digit)
14
17
  - AAAA: 16-bit address (hex)
15
18
  - DD: Data bytes (hex, space-separated)
@@ -5,7 +5,9 @@ This module handles the EMON52 hex format used by the Elektor
5
5
  Electronics EMON52 8052 development system.
6
6
 
7
7
  Format specification:
8
- - Data records: LL AAAA:DD CCCC
8
+
9
+ - Data records: ``LL AAAA:DD CCCC``
10
+
9
11
  - LL: Length/byte count (hex)
10
12
  - AAAA: 16-bit address (hex)
11
13
  - DD: Data bytes (hex, space-separated)
@@ -5,18 +5,24 @@ This module handles the Extended Tektronix hex format, an extension
5
5
  of the standard Tektronix format with 24-bit addressing and symbol support.
6
6
 
7
7
  Format specification:
8
- - Data records: %LL6CCAAAAADD
9
- - LL: Length field (2 * (data_length + 5) in hex)
8
+
9
+ - Data records: ``%LL6CCAAAAADD``
10
+
11
+ - LL: Length field (``2 * (data_length + 5)`` in hex)
10
12
  - 6: Record type identifier
11
13
  - CC: Checksum (nibble sum)
12
14
  - AAAAAA: 24-bit address (hex)
13
15
  - DD: Data bytes (hex)
14
- - Symbol records: %LL3CCU
16
+
17
+ - Symbol records: ``%LL3CCU``
18
+
15
19
  - LL: Length field
16
20
  - 3: Symbol type identifier
17
21
  - CC: Checksum
18
22
  - U: Symbol string (name + address)
19
- - EOF records: %LL8CCAAAAADD
23
+
24
+ - EOF records: ``%LL8CCAAAAADD``
25
+
20
26
  - 8: EOF type identifier
21
27
  """
22
28
 
@@ -67,9 +73,9 @@ class Reader(hexfile.Reader):
67
73
  VALID_CHARS = re.compile(r"^[a-zA-Z0-9_ %\n\r]*$")
68
74
 
69
75
  FORMAT_SPEC = (
70
- (DATA, "%LL6CCAAAAADD"),
76
+ (DATA, "%LL6CCAAAAAADD"),
71
77
  (SYMBOL, "%LL3CCU"),
72
- (EOF, "%LL8CCAAAAADD"),
78
+ (EOF, "%LL8CCAAAAAADD"),
73
79
  )
74
80
 
75
81
  def check_line(self, line: Any, format_type: int) -> None:
@@ -508,6 +508,7 @@ class Container:
508
508
  length: Optional[int] = None
509
509
  type: Optional[int] = None
510
510
  checksum: Optional[int] = None
511
+ addrChecksum: Optional[int] = None
511
512
  chunk: Optional[bytearray] = None
512
513
  junk: Optional[str] = None
513
514
  processing_instructions: list[Any] = field(default_factory=list)
@@ -892,6 +893,7 @@ class Reader(BaseType):
892
893
  length = self._parse_optional_int(dict_, "length")
893
894
  record_type = self._parse_optional_int(dict_, "type")
894
895
  checksum = self._parse_optional_int(dict_, "checksum")
896
+ addr_checksum = self._parse_optional_int(dict_, "addrChecksum")
895
897
  junk = dict_.get("junk")
896
898
 
897
899
  # Parse data chunk
@@ -912,6 +914,7 @@ class Reader(BaseType):
912
914
  length=length,
913
915
  type=record_type,
914
916
  checksum=checksum,
917
+ addrChecksum=addr_checksum,
915
918
  chunk=chunk,
916
919
  junk=junk,
917
920
  )
@@ -640,6 +640,28 @@ class Image:
640
640
  """Write an ASAM string datatype (ASCII/UTF8/UTF16/UTF32)."""
641
641
  self._call_address_function("write_asam_string", addr, value, dtype, **kws)
642
642
 
643
+ def read_asam_numeric_array(
644
+ self,
645
+ addr: int,
646
+ length: int,
647
+ dtype: str,
648
+ byte_order: str = "MSB_LAST",
649
+ **kws: Any,
650
+ ) -> list[Union[int, float]]:
651
+ """Read an ASAM numeric array with ECU byte order semantics."""
652
+ return self._call_address_function("read_asam_numeric_array", addr, length, dtype, byte_order, **kws)
653
+
654
+ def write_asam_numeric_array(
655
+ self,
656
+ addr: int,
657
+ data: Iterable[Union[int, float]],
658
+ dtype: str,
659
+ byte_order: str = "MSB_LAST",
660
+ **kws: Any,
661
+ ) -> None:
662
+ """Write an ASAM numeric array with ECU byte order semantics."""
663
+ self._call_address_function("write_asam_numeric_array", addr, data, dtype, byte_order, **kws)
664
+
643
665
  def read_numeric_array(self, addr: int, length: int, dtype: str, **kws: Any) -> list[Union[int, float]]:
644
666
  """Read array of numeric values from image.
645
667
 
@@ -688,6 +710,18 @@ class Image:
688
710
  """
689
711
  self._call_address_function("write_ndarray", addr, array, order=order, **kws)
690
712
 
713
+ def write_asam_ndarray(
714
+ self,
715
+ addr: int,
716
+ array: Any,
717
+ dtype: str,
718
+ byte_order: str = "MSB_LAST",
719
+ order: Optional[str] = None,
720
+ **kws: Any,
721
+ ) -> None:
722
+ """Write a NumPy ndarray using ASAM datatype and ECU byte order semantics."""
723
+ self._call_address_function("write_asam_ndarray", addr, array, dtype, byte_order, order=order, **kws)
724
+
691
725
  def read_ndarray(
692
726
  self,
693
727
  addr: int,
@@ -715,6 +749,19 @@ class Image:
715
749
  """
716
750
  return self._call_address_function("read_ndarray", addr, length, dtype, shape, order, **kws)
717
751
 
752
+ def read_asam_ndarray(
753
+ self,
754
+ addr: int,
755
+ length: int,
756
+ dtype: str,
757
+ shape: Optional[tuple[int, ...]] = None,
758
+ order: Optional[str] = None,
759
+ byte_order: str = "MSB_LAST",
760
+ **kws: Any,
761
+ ) -> Any:
762
+ """Read a NumPy ndarray using ASAM datatype and ECU byte order semantics."""
763
+ return self._call_address_function("read_asam_ndarray", addr, length, dtype, shape, order, byte_order, **kws)
764
+
718
765
  def read_string(self, addr: int, encoding: str = "latin1", length: int = -1, **kws: Any) -> str:
719
766
  """Read string from image.
720
767
 
@@ -32,6 +32,9 @@ Architecture
32
32
  ├── read/write(addr, length) # Raw bytes
33
33
  ├── read_numeric/write_numeric(addr, dtype) # Single values
34
34
  ├── read_numeric_array/write_numeric_array() # Arrays
35
+ ├── read_asam_numeric/write_asam_numeric() # ASAM scalars
36
+ ├── read_asam_numeric_array/write_asam_numeric_array() # ASAM arrays
37
+ ├── read_asam_ndarray/write_asam_ndarray() # ASAM NumPy arrays
35
38
  ├── read_string/write_string() # Null-terminated strings
36
39
  └── read_ndarray/write_ndarray() # NumPy arrays
37
40
 
@@ -587,10 +590,24 @@ class Section:
587
590
  internal_dtype = ASAM_NUMERIC_DTYPES.get(normalized_dtype)
588
591
  if internal_dtype is None:
589
592
  raise TypeError(f"Unsupported ASAM datatype {asam_dtype!r}")
590
- if internal_dtype in ("uint8", "int8"):
591
- return internal_dtype
592
593
  return f"{internal_dtype}_{ASAM_ENDIAN_FOR_BYTEORDER[asam_byte_order]}"
593
594
 
595
+ def _numpy_dtype_from_internal(self, dtype: str) -> np.dtype:
596
+ type_, byte_order = self._verify_dtype(dtype)
597
+ return np.dtype(type_).newbyteorder(BYTEORDER[byte_order])
598
+
599
+ def _permute_asam_buffer(self, data: bytes, internal_dtype: str, byte_order: str) -> bytes:
600
+ type_name = internal_dtype.split("_")[0]
601
+ element_size = TYPE_SIZES.get(type_name, 0)
602
+ if element_size <= 1 or not data:
603
+ return data
604
+ if len(data) % element_size != 0:
605
+ raise ValueError("ASAM buffer length must be a multiple of the element size")
606
+ return b"".join(
607
+ self._permute_asam_bytes_for_read(data[idx : idx + element_size], byte_order)
608
+ for idx in range(0, len(data), element_size)
609
+ )
610
+
594
611
  def read(self, addr: int, length: int, **kws) -> bytes:
595
612
  """Read raw bytes from section at specified address.
596
613
 
@@ -763,7 +780,7 @@ class Section:
763
780
 
764
781
  fmt = self._getformat(internal_dtype)
765
782
  packed = struct.pack(fmt, value)
766
- permuted = self._permute_asam_bytes_for_read(packed, asam_byte_order)
783
+ permuted = self._permute_asam_buffer(packed, internal_dtype, asam_byte_order)
767
784
  return struct.unpack(fmt, permuted)[0]
768
785
 
769
786
  def write_asam_numeric(
@@ -782,9 +799,44 @@ class Section:
782
799
 
783
800
  fmt = self._getformat(internal_dtype)
784
801
  packed = struct.pack(fmt, value)
785
- permuted = self._permute_asam_bytes_for_write(packed, asam_byte_order)
802
+ permuted = self._permute_asam_buffer(packed, internal_dtype, asam_byte_order)
786
803
  self.write(addr, permuted)
787
804
 
805
+ def read_asam_numeric_array(
806
+ self,
807
+ addr: int,
808
+ length: int,
809
+ dtype: str,
810
+ byte_order: str = "MSB_LAST",
811
+ **kws,
812
+ ) -> Union[tuple[int, ...], tuple[float, ...]]:
813
+ asam_byte_order = self._resolve_asam_byteorder(byte_order)
814
+ internal_dtype = self._asam_numeric_dtype_to_internal(dtype, asam_byte_order)
815
+ fmt = self._getformat(internal_dtype, length)
816
+ data_size = struct.calcsize(fmt)
817
+ raw_data = self.read(addr, data_size, **kws)
818
+ permuted = self._permute_asam_buffer(raw_data, internal_dtype, asam_byte_order)
819
+ return struct.unpack(fmt, permuted)
820
+
821
+ def write_asam_numeric_array(
822
+ self,
823
+ addr: int,
824
+ data: Union[list[int], list[float]],
825
+ dtype: str,
826
+ byte_order: str = "MSB_LAST",
827
+ **kws,
828
+ ) -> None:
829
+ if not hasattr(data, "__iter__"):
830
+ raise TypeError("data must be iterable")
831
+
832
+ values = tuple(data)
833
+ asam_byte_order = self._resolve_asam_byteorder(byte_order)
834
+ internal_dtype = self._asam_numeric_dtype_to_internal(dtype, asam_byte_order)
835
+ fmt = self._getformat(internal_dtype, len(values))
836
+ packed = struct.pack(fmt, *values)
837
+ permuted = self._permute_asam_buffer(packed, internal_dtype, asam_byte_order)
838
+ self.write(addr, permuted, **kws)
839
+
788
840
  def read_asam_string(self, addr: int, dtype: str, length: int = -1, **kws) -> str:
789
841
  encoding = ASAM_STRING_ENCODINGS.get(dtype.strip().upper())
790
842
  if encoding is None:
@@ -920,6 +972,28 @@ class Section:
920
972
  else:
921
973
  self.data[offset : offset + data_size] = array.tobytes()
922
974
 
975
+ def write_asam_ndarray(
976
+ self,
977
+ addr: int,
978
+ array: np.ndarray,
979
+ dtype: str,
980
+ byte_order: str = "MSB_LAST",
981
+ order: str = None,
982
+ **kws,
983
+ ) -> None:
984
+ if not isinstance(array, np.ndarray):
985
+ raise TypeError("array must be of type numpy.ndarray.")
986
+
987
+ asam_byte_order = self._resolve_asam_byteorder(byte_order)
988
+ internal_dtype = self._asam_numeric_dtype_to_internal(dtype, asam_byte_order)
989
+ typed_array = np.asarray(array, dtype=self._numpy_dtype_from_internal(internal_dtype))
990
+ if order is not None and order == "F":
991
+ raw_data = fortran_array_to_buffer(array=typed_array)
992
+ else:
993
+ raw_data = typed_array.tobytes()
994
+ permuted = self._permute_asam_buffer(raw_data, internal_dtype, asam_byte_order)
995
+ self.write(addr, permuted, **kws)
996
+
923
997
  def read_ndarray(self, addr: int, length: int, dtype: str, shape: tuple = None, order: str = None, **kws) -> np.ndarray:
924
998
  """ """
925
999
  offset = addr - self.start_address
@@ -927,9 +1001,7 @@ class Section:
927
1001
  raise InvalidAddressError(f"read_ndarray(0x{addr:08x}) access out of bounds.")
928
1002
  if offset + length > self.length:
929
1003
  raise InvalidAddressError(f"read_ndarray(0x{addr:08x}) access out of bounds.")
930
- type_, byte_order = self._verify_dtype(dtype)
931
- dt = np.dtype(type_)
932
- dt = dt.newbyteorder(BYTEORDER.get(byte_order))
1004
+ dt = self._numpy_dtype_from_internal(dtype)
933
1005
  if order is not None and order == "F":
934
1006
  arr = fortran_array_from_buffer(arr=self.data[offset : offset + length], shape=shape, dtype=dt)
935
1007
  else:
@@ -937,6 +1009,27 @@ class Section:
937
1009
  arr = flat.reshape(shape) if shape else flat
938
1010
  return arr
939
1011
 
1012
+ def read_asam_ndarray(
1013
+ self,
1014
+ addr: int,
1015
+ length: int,
1016
+ dtype: str,
1017
+ shape: tuple = None,
1018
+ order: str = None,
1019
+ byte_order: str = "MSB_LAST",
1020
+ **kws,
1021
+ ) -> np.ndarray:
1022
+ asam_byte_order = self._resolve_asam_byteorder(byte_order)
1023
+ internal_dtype = self._asam_numeric_dtype_to_internal(dtype, asam_byte_order)
1024
+ dt = self._numpy_dtype_from_internal(internal_dtype)
1025
+ raw_data = self.read(addr, length, **kws)
1026
+ permuted = self._permute_asam_buffer(raw_data, internal_dtype, asam_byte_order)
1027
+ if order is not None and order == "F":
1028
+ return fortran_array_from_buffer(arr=permuted, shape=shape, dtype=dt)
1029
+
1030
+ flat = np.frombuffer(permuted, dtype=dt)
1031
+ return flat.reshape(shape) if shape else flat
1032
+
940
1033
  """
941
1034
  def write_timestamp():
942
1035
  pass
@@ -30,7 +30,7 @@ from hashlib import sha1
30
30
 
31
31
  from objutils.image import Image
32
32
  from objutils.logger import Logger
33
- from objutils.section import Section
33
+ from objutils.section import Section, join_sections
34
34
  from objutils.utils import create_string_buffer
35
35
 
36
36
  SHF_DTD = """<!--
@@ -151,14 +151,14 @@ class Reader(hexfile.Reader):
151
151
  )
152
152
  else:
153
153
  raise TypeError(f"Invalid format type {format_type}.")
154
- if hasattr(line, "chunk"):
154
+ if hasattr(line, "chunk") and line.chunk is not None:
155
155
  checksum = (~(sum([line.length, checksum_of_address]) + sum(line.chunk))) & 0xFF
156
156
  else:
157
157
  checksum = (~(sum([line.length, checksum_of_address]))) & 0xFF
158
158
  if line.checksum != checksum:
159
159
  raise hexfile.InvalidRecordChecksumError()
160
160
  line.length -= BIAS[format_type] # calculate actual data length.
161
- if hasattr(line, "chunk") and line.length and (line.length != len(line.chunk)):
161
+ if hasattr(line, "chunk") and line.chunk is not None and line.length and (line.length != len(line.chunk)):
162
162
  raise hexfile.InvalidRecordLengthError("Byte count doesn't match length of actual data.")
163
163
 
164
164
  def is_data_line(self, line: Any, format_type: int) -> bool:
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env python
2
+ """Tests for the Extended Tektronix (ETek) hex file format.
3
+
4
+ Coverage:
5
+ - loads(): parsing ETek → Image
6
+ - dumps(): serialising Image → ETek
7
+ - Roundtrip fidelity in both directions (ETek↔SREC)
8
+ - Single-byte records at extreme 24-bit addresses
9
+ - Checksum mismatch detection
10
+ - Record-length mismatch detection
11
+ """
12
+
13
+ import pytest
14
+
15
+ from objutils import dumps, loads
16
+ from objutils.hexfile import InvalidRecordChecksumError, InvalidRecordLengthError
17
+
18
+
19
+ # ---------------------------------------------------------------------------
20
+ # Test vectors
21
+ # ---------------------------------------------------------------------------
22
+
23
+ # 60-byte message split into three 16-byte and one 12-byte data record
24
+ # starting at address 0xB000 (24-bit addressing).
25
+ ETEK = (
26
+ b"%2A6C200B000576F77212044696420796F7520726561\n"
27
+ b"%2A6DF00B0106C6C7920676F207468726F7567682061\n"
28
+ b"%2A6CE00B0206C6C20746861742074726F75626C6520\n"
29
+ b"%246A700B030746F207265616420746869733F\n"
30
+ )
31
+
32
+ # Equivalent Motorola S-Record representation (used for cross-format checks).
33
+ S19 = (
34
+ b"S113B000576F77212044696420796F7520726561D8\n"
35
+ b"S113B0106C6C7920676F207468726F756768206143\n"
36
+ b"S113B0206C6C20746861742074726F75626C652036\n"
37
+ b"S110B030746F207265616420746869733F59\n"
38
+ b"S5030004F8\n"
39
+ )
40
+
41
+ # Single-byte records for boundary / 24-bit address tests.
42
+ ETEK_SINGLE_BYTE_LOW = b"%0C628000001AB\n" # address 0x000001, data 0xAB
43
+ ETEK_SINGLE_BYTE_HIGH = b"%0C649FF0000CD\n" # address 0xFF0000, data 0xCD
44
+
45
+
46
+ # ---------------------------------------------------------------------------
47
+ # Helpers
48
+ # ---------------------------------------------------------------------------
49
+
50
+
51
+ def _etek_loads(raw: bytes):
52
+ """Load an ETek byte string and return the Image."""
53
+ return loads("etek", raw)
54
+
55
+
56
+ def _srec_loads(raw: bytes):
57
+ """Load an SREC byte string and return the Image."""
58
+ return loads("srec", raw)
59
+
60
+
61
+ # ---------------------------------------------------------------------------
62
+ # loads() – parsing
63
+ # ---------------------------------------------------------------------------
64
+
65
+
66
+ def test_loads_produces_correct_srec_output():
67
+ """Parsing ETek data produces byte-identical S-Record output."""
68
+ img = _etek_loads(ETEK)
69
+ assert dumps("srec", img, s5record=True) == S19
70
+
71
+
72
+ def test_loads_single_byte_low_address():
73
+ """Single data byte at address 0x000001 is read correctly."""
74
+ img = _etek_loads(ETEK_SINGLE_BYTE_LOW)
75
+ assert img.read(0x000001, 1) == b"\xAB"
76
+
77
+
78
+ def test_loads_single_byte_high_address():
79
+ """Single data byte at address 0xFF0000 (max 24-bit) is read correctly."""
80
+ img = _etek_loads(ETEK_SINGLE_BYTE_HIGH)
81
+ assert img.read(0xFF0000, 1) == b"\xCD"
82
+
83
+
84
+ def test_loads_image_min_address():
85
+ """Parsed image starts at the expected minimum address."""
86
+ img = _etek_loads(ETEK)
87
+ first_section = next(iter(img.sections))
88
+ assert first_section.start_address == 0xB000
89
+
90
+
91
+ def test_loads_image_data_length():
92
+ """Parsed image contains the correct number of data bytes (61 = 3×16 + 13)."""
93
+ img = _etek_loads(ETEK)
94
+ total = sum(len(s.data) for s in img.sections)
95
+ assert total == 61
96
+
97
+
98
+ # ---------------------------------------------------------------------------
99
+ # dumps() – serialisation
100
+ # ---------------------------------------------------------------------------
101
+
102
+
103
+ def test_dumps_produces_correct_etek_output():
104
+ """Serialising an Image loaded from S-Records gives identical ETek bytes."""
105
+ img = _srec_loads(S19)
106
+ assert dumps("etek", img) == bytearray(ETEK)
107
+
108
+
109
+ def test_dumps_single_byte_low_address():
110
+ """A one-byte section at address 0x000001 serialises to the expected record."""
111
+ img = _etek_loads(ETEK_SINGLE_BYTE_LOW)
112
+ assert dumps("etek", img) == bytearray(ETEK_SINGLE_BYTE_LOW)
113
+
114
+
115
+ def test_dumps_single_byte_high_address():
116
+ """A one-byte section at address 0xFF0000 serialises to the expected record."""
117
+ img = _etek_loads(ETEK_SINGLE_BYTE_HIGH)
118
+ assert dumps("etek", img) == bytearray(ETEK_SINGLE_BYTE_HIGH)
119
+
120
+
121
+ # ---------------------------------------------------------------------------
122
+ # Roundtrip tests
123
+ # ---------------------------------------------------------------------------
124
+
125
+
126
+ def test_roundtrip_etek_to_srec_to_etek():
127
+ """ETek → SREC → ETek roundtrip preserves all data and addresses."""
128
+ img1 = _etek_loads(ETEK)
129
+ srec_data = dumps("srec", img1, s5record=True)
130
+ img2 = _srec_loads(srec_data)
131
+ assert dumps("etek", img2) == bytearray(ETEK)
132
+
133
+
134
+ def test_roundtrip_srec_to_etek_to_srec():
135
+ """SREC → ETek → SREC roundtrip preserves all data and addresses."""
136
+ img1 = _srec_loads(S19)
137
+ etek_data = dumps("etek", img1)
138
+ img2 = _etek_loads(etek_data)
139
+ assert dumps("srec", img2, s5record=True) == S19
140
+
141
+
142
+ # ---------------------------------------------------------------------------
143
+ # Error handling
144
+ # ---------------------------------------------------------------------------
145
+
146
+
147
+ def test_invalid_checksum_raises():
148
+ """A record with a corrupted checksum raises InvalidRecordChecksumError."""
149
+ # Flip one nibble in the CC field (chars 4-5 of the record).
150
+ bad = b"%2A6FF00B000576F77212044696420796F7520726561\n"
151
+ with pytest.raises(InvalidRecordChecksumError):
152
+ _etek_loads(bad)
153
+
154
+
155
+ def test_invalid_length_raises():
156
+ """A record with a wrong LL field raises InvalidRecordLengthError."""
157
+ # Change LL from 2A to 2C (claims 19 data bytes but only 16 are present).
158
+ bad = b"%2C6C200B000576F77212044696420796F7520726561\n"
159
+ with pytest.raises(InvalidRecordLengthError):
160
+ _etek_loads(bad)
161
+
@@ -6,6 +6,13 @@ from array import array
6
6
 
7
7
  import pytest
8
8
 
9
+ try:
10
+ import numpy as np
11
+ except ImportError:
12
+ NUMPY_SUPPORT = False
13
+ else:
14
+ NUMPY_SUPPORT = True
15
+
9
16
  from objutils import dumps
10
17
  from objutils.exceptions import InvalidAddressError
11
18
  from objutils.image import Image
@@ -1343,5 +1350,25 @@ def test_image_asam_string_ascii_roundtrip():
1343
1350
  assert img.read_asam_string(0x1000, "ASCII") == "ABC"
1344
1351
 
1345
1352
 
1353
+ def test_image_asam_numeric_array_word_swap_32bit():
1354
+ img = Image(Section(data=bytearray(16), start_address=0x1000))
1355
+ img.write_asam_numeric_array(0x1000, [0x11223344, 0x55667788], "ULONG", byte_order="MSB_LAST_MSW_FIRST")
1356
+ assert img.read(0x1000, 8) == b"\x33\x44\x11\x22\x77\x88\x55\x66"
1357
+ assert img.read_asam_numeric_array(0x1000, 2, "ULONG", byte_order="MSB_LAST_MSW_FIRST") == (
1358
+ 0x11223344,
1359
+ 0x55667788,
1360
+ )
1361
+
1362
+
1363
+ @pytest.mark.skipif("NUMPY_SUPPORT == False")
1364
+ def test_image_asam_ndarray_fortran_roundtrip():
1365
+ img = Image(Section(data=bytearray(32), start_address=0x1000))
1366
+ arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint16)
1367
+ img.write_asam_ndarray(0x1000, arr, "UWORD", byte_order="MSB_FIRST_MSW_LAST", order="F")
1368
+ assert img.read(0x1000, 12) == b"\x01\x00\x04\x00\x02\x00\x05\x00\x03\x00\x06\x00"
1369
+ result = img.read_asam_ndarray(0x1000, 12, "UWORD", shape=(3, 2), order="F", byte_order="MSB_FIRST_MSW_LAST")
1370
+ assert np.array_equal(result, arr)
1371
+
1372
+
1346
1373
  if __name__ == "__main__":
1347
1374
  unittest.main()
@@ -638,6 +638,24 @@ def test_asam_float16_ieee_roundtrip():
638
638
  assert sec.read_asam_numeric(0, "FLOAT16_IEEE", byte_order="MSB_LAST") == pytest.approx(1.5, rel=1e-3)
639
639
 
640
640
 
641
+ def test_write_asam_numeric_array_msb_last_msw_first_ulong():
642
+ sec = Section(data=bytearray(16))
643
+ sec.write_asam_numeric_array(0, [0x11223344, 0x55667788], "ULONG", byte_order="MSB_LAST_MSW_FIRST")
644
+ assert sec.data[:8] == bytearray([0x33, 0x44, 0x11, 0x22, 0x77, 0x88, 0x55, 0x66])
645
+
646
+
647
+ def test_read_asam_numeric_array_msb_last_msw_first_ulong():
648
+ sec = Section(data=bytearray([0x33, 0x44, 0x11, 0x22, 0x77, 0x88, 0x55, 0x66] + [0x00] * 8))
649
+ assert sec.read_asam_numeric_array(0, 2, "ULONG", byte_order="MSB_LAST_MSW_FIRST") == (0x11223344, 0x55667788)
650
+
651
+
652
+ def test_asam_numeric_array_signed_roundtrip():
653
+ sec = Section(data=bytearray(16))
654
+ sec.write_asam_numeric_array(0, [-1, -2, 3], "SWORD", byte_order="MSB_FIRST")
655
+ assert sec.data[:6] == bytearray([0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x03])
656
+ assert sec.read_asam_numeric_array(0, 3, "SWORD", byte_order="MSB_FIRST") == (-1, -2, 3)
657
+
658
+
641
659
  @pytest.mark.skipif("NUMPY_SUPPORT == False")
642
660
  def test_write_ndarray1():
643
661
  sec = Section(start_address=0x1000, data=bytearray(32))
@@ -819,3 +837,29 @@ def test_write_ndarray_fortan_02():
819
837
  assert sec.read(0x1000, 24) == bytearray(
820
838
  b"\x01\x00\x04\x00\x07\x00\n\x00\x02\x00\x05\x00\x08\x00\x0b\x00\x03\x00\x06\x00\t\x00\x0c\x00"
821
839
  )
840
+
841
+
842
+ @pytest.mark.skipif("NUMPY_SUPPORT == False")
843
+ def test_write_asam_ndarray_msb_last_msw_first_ulong():
844
+ sec = Section(start_address=0x1000, data=bytearray(32))
845
+ arr = np.array([0x11223344, 0x55667788], dtype=np.uint32)
846
+ sec.write_asam_ndarray(0x1000, arr, "ULONG", byte_order="MSB_LAST_MSW_FIRST")
847
+ assert sec.read(0x1000, 8) == bytearray([0x33, 0x44, 0x11, 0x22, 0x77, 0x88, 0x55, 0x66])
848
+
849
+
850
+ @pytest.mark.skipif("NUMPY_SUPPORT == False")
851
+ def test_read_asam_ndarray_msb_last_msw_first_ulong():
852
+ sec = Section(start_address=0x1000, data=bytearray([0x33, 0x44, 0x11, 0x22, 0x77, 0x88, 0x55, 0x66] + [0x00] * 24))
853
+ result = sec.read_asam_ndarray(0x1000, 8, "ULONG", shape=(2,), byte_order="MSB_LAST_MSW_FIRST")
854
+ assert np.array_equal(result, np.array([0x11223344, 0x55667788], dtype=np.uint32))
855
+
856
+
857
+ @pytest.mark.skipif("NUMPY_SUPPORT == False")
858
+ def test_asam_ndarray_fortran_roundtrip():
859
+ sec = Section(start_address=0x1000, data=bytearray(32))
860
+ arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint16)
861
+ sec.write_asam_ndarray(0x1000, arr, "UWORD", byte_order="MSB_FIRST_MSW_LAST", order="F")
862
+ assert sec.read(0x1000, 12) == bytearray(b"\x01\x00\x04\x00\x02\x00\x05\x00\x03\x00\x06\x00")
863
+ result = sec.read_asam_ndarray(0x1000, 12, "UWORD", shape=(3, 2), order="F", byte_order="MSB_FIRST_MSW_LAST")
864
+ assert np.array_equal(result, arr)
865
+
@@ -1,3 +1,3 @@
1
1
  """objutils version module"""
2
2
 
3
- __version__ = "0.10.1"
3
+ __version__ = "0.10.3"
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "objutils"
3
- version = "0.10.1"
3
+ version = "0.10.3"
4
4
  description = "Objectfile library for Python"
5
5
  authors = ["Christoph Schueler <cpu12.gems@googlemail.com>"]
6
6
  license = "GPLv2"
@@ -121,7 +121,7 @@ skip = ["*_i686", "*-musllinux*"]
121
121
  build-frontend = "build"
122
122
 
123
123
  [tool.bumpver]
124
- current_version = "0.10.1"
124
+ current_version = "0.10.3"
125
125
  version_pattern = "MAJOR.MINOR.PATCH"
126
126
  commit_message = "bump version {old_version} -> {new_version}"
127
127
  commit = true
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes