Skip to content

Commit

Permalink
Switch to an xor for the checksum
Browse files Browse the repository at this point in the history
Update the text to use xor instead of add.

Signed-off-by: Simon Glass <sjg@chromium.org>
  • Loading branch information
sjg20 authored and jmarinho committed Oct 24, 2023
1 parent f70c184 commit ae94bd1
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions source/transfer_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ changes will be backwards-compatible to older readers.
* - checksum
- 0x1
- 0x4
- If enabled by the flags, the checksum is used to provide basic protection against something overwriting the TL in memory. The checksum is set to a value such that the sum over every byte in the {`tl_base_pa`, …, `tl_base_pa + size - 1`} address range, modulo 256, is equal to 0. For the purposes of this calculation, the value of this checksum field in the TL header must be assumed as 0. Note that the checksum includes the TL header, all TEs and the inter-TE padding, but not the range reserved for future TE additions up to max_size. The values of inter-TE padding bytes are not defined by this specification and may be uninitialized memory. (This means that multiple TLs with exactly the same size and contents may still have different checksum values.). If checksums are not used, this must be 0.
- If enabled by the flags, the checksum is used to provide basic protection against something overwriting the TL in memory. The checksum is set to a value such that the xor over every byte in the {`tl_base_pa`, …, `tl_base_pa + size - 1`} address range, is equal to 0. For the purposes of this calculation, the value of this checksum field in the TL header must be assumed as 0. Note that the checksum includes the TL header, all TEs and the inter-TE padding, but not the range reserved for future TE additions up to max_size. The values of inter-TE padding bytes are not defined by this specification and may be uninitialized memory. (This means that multiple TLs with exactly the same size and contents may still have different checksum values.). If checksums are not used, this must be 0.

* - version
- 0x1
Expand Down Expand Up @@ -216,9 +216,8 @@ Inputs:
equal to the size of the total area reserved for the TL (if known). If not,
abort (TL is corrupted).

#. *(optional)* If `has_checksum`, check that the sum of `tl.size` bytes
starting at `tl_base_addr` minus `tl.checksum` is equal to `tl.checksum`. If
not, abort (TL is corrupted).
#. *(optional)* If `has_checksum`, check that the xor of `tl.size` bytes
starting at `tl_base_addr` is 0x0. If not, abort (TL is corrupted).

Reading a TL
^^^^^^^^^^^^
Expand Down Expand Up @@ -260,8 +259,8 @@ Inputs:

#. Use the `te_base_addr` of this tag for the rest of the operation.

#. If `has_checksum`, Subtract the sum of `align8(new_data_size + 0x8)` bytes
starting at `te_base_addr` from `tl.checksum`.
#. If `has_checksum`, xor the `align8(new_data_size + 0x8)` bytes starting at
`te_base_addr` with `tl.checksum`.

#. Skip the next step (step 2) with all its substeps.

Expand All @@ -270,13 +269,13 @@ Inputs:
#. If `tl.max_size - tl.size` is smaller than `align8(new_data_size + 0x8)`,
abort (not enough room to add TE).

#. If `has_checksum`, subtract the sum of the 4 bytes from
`tl_base_addr + 0x8` to `tl_base_addr + 0xc` from `tl.checksum`.
#. If `has_checksum`, xor the 4 bytes from `tl_base_addr + 0x8` with
`tl_base_addr + 0xc` from `tl.checksum`.

#. Add `align8(new_data_size + 0x8)` to `tl.size`.

#. If `has_checksum`, add the sum of the 4 bytes from `tl_base_addr + 0x8` to
`tl_base_addr + 0xc` to `tl.checksum`.
#. If `has_checksum`, xor the 4 bytes from `tl_base_addr + 0x8` to
`tl_base_addr + 0xc` with `tl.checksum`.

#. Set `te.tag_id` (`te_base_addr + 0x0`) to `new_tag_id`.

Expand All @@ -286,17 +285,17 @@ Inputs:

#. Copy or generate the TE data into `te_base_addr + 0x8`.

#. If `has_checksum`, add the sum of `align8(new_data_size + 0x8)` bytes
starting at `te_base_addr` to `tl.checksum`.
#. If `has_checksum`, xor the `align8(new_data_size + 0x8)` bytes starting at
`te_base_addr` with `tl.checksum`.

#. If an existing XFERLIST_VOID TE was chosen to be overwritten in step 1, and
`old_void_data_size - new_data_size` is greater or equal to `0x8`:

#. Use `te_base_addr + align8(new_data_size + 0x8)` as the new `te_base_addr`
for a new XFERLIST_VOID tag.

#. If `has_checksum`, subtract the sum of the 8 bytes from `te_base_addr` to
`te_base_addr + 0x8` from `tl.checksum`.
#. If `has_checksum`, xor the 8 bytes from `te_base_addr` to
`te_base_addr + 0x8` with `tl.checksum`.

#. Set `te.tag_id` (`te_base_addr + 0x0`) to `0x0` (XFERLIST_VOID).

Expand All @@ -305,8 +304,8 @@ Inputs:
#. Set `te.data_size` (`te_base_addr + 0x4`) to
`old_void_data_size - align8(new_data_size) - 0x8`.

#. If `has_checksum`, add the sum of the 8 bytes from `te_base_addr` to
`te_base_addr + 0x8` to `tl.checksum`.
#. If `has_checksum`, xor the 8 bytes from `te_base_addr` to
`te_base_addr + 0x8` with `tl.checksum`.

Adding a new TE with special data alignment requirement
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -338,11 +337,11 @@ Inputs:

#. If `new_alignment` is larger than `tl.alignment`:

#. If `has_checksum`, subtract `tl.alignment` from `tl.checksum`.
#. If `has_checksum`, xor `tl.alignment` with `tl.checksum`.

#. Set `tl.alignment` to `new_alignment`.

#. If `has_checksum`, add `tl.alignment` to `tl.checksum`.
#. If `has_checksum`, xor `tl.alignment` with `tl.checksum`.

Creating a TL
^^^^^^^^^^^^^
Expand Down Expand Up @@ -371,7 +370,7 @@ Inputs:
#. If checksums are to be used, set `tl.flags` (`tl_base_addr + 0x10`) to `1`,
else `0`. This is the value of `has_checksum`.

#. If `has_checksum`, calculate the checksum as the sum of all bytes from
#. If `has_checksum`, calculate the checksum as the xor of all bytes from
`tl_base_addr` to `tl_base_addr + tl.hdr_size`, and write the result to
`tl.checksum`.

Expand All @@ -397,13 +396,13 @@ Inputs:

#. Copy `tl.size` bytes from `tl_base_addr` to `new_tl_base`.

#. If `has_checksum`, subtract the sum of the 4 bytes from `new_tl_base + 0xc`
to `new_tl_base + 0x10` from `tl.checksum` (`new_tl_base + 0x4`).
#. If `has_checksum`, xor the the 4 bytes from `new_tl_base + 0xc`
to `new_tl_base + 0x10` with `tl.checksum` (`new_tl_base + 0x4`).

#. Set `tl.max_size` (`new_tl_base + 0xc`) to `target_size - (new_tl_base - target_base)`.

#. If `has_checksum`, add the sum of the 4 bytes from `new_tl_base + 0xc` to
`new_tl_base + 0x10` to `tl.checksum` (`new_tl_base + 0x4`).
#. If `has_checksum`, xor the 4 bytes from `new_tl_base + 0xc` to
`new_tl_base + 0x10` with `tl.checksum` (`new_tl_base + 0x4`).


Entry type allocation
Expand Down

0 comments on commit ae94bd1

Please sign in to comment.