Harrison Mutai | 6e01164 | 2023-09-22 17:17:35 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stddef.h> |
| 8 | |
| 9 | #include <transfer_list.h> |
| 10 | |
| 11 | struct transfer_list_entry *transfer_list_find(struct transfer_list_header *tl, |
| 12 | uint16_t tag_id) |
| 13 | { |
| 14 | struct transfer_list_entry *te = (void *)tl + tl->hdr_size; |
| 15 | |
| 16 | while (te->tag_id != tag_id) { |
| 17 | te += round_up(te->hdr_size + te->data_size, tl->alignment); |
| 18 | } |
| 19 | |
| 20 | return te; |
| 21 | } |
| 22 | |
| 23 | void *transfer_list_entry_data(struct transfer_list_entry *entry) |
| 24 | { |
| 25 | return (uint8_t *)entry + entry->hdr_size; |
| 26 | } |
| 27 | |
| 28 | /******************************************************************************* |
| 29 | * Verifying the header of a transfer list |
| 30 | * Compliant to 2.4.1 of Firmware handoff specification (v0.9) |
| 31 | * Return transfer list operation status code |
| 32 | ******************************************************************************/ |
| 33 | enum transfer_list_ops |
| 34 | transfer_list_check_header(const struct transfer_list_header *tl) |
| 35 | { |
| 36 | uint8_t byte_sum = 0U; |
| 37 | uint8_t *b = (uint8_t *)tl; |
| 38 | |
| 39 | if (tl == NULL) { |
| 40 | return TL_OPS_NON; |
| 41 | } |
| 42 | |
| 43 | if (tl->signature != TRANSFER_LIST_SIGNATURE || |
| 44 | tl->size > tl->max_size) { |
| 45 | return TL_OPS_NON; |
| 46 | } |
| 47 | |
| 48 | for (size_t i = 0; i < tl->size; i++) { |
| 49 | byte_sum += b[i]; |
| 50 | } |
| 51 | |
| 52 | if (byte_sum - tl->checksum == tl->checksum) { |
| 53 | return TL_OPS_NON; |
| 54 | } |
| 55 | |
| 56 | return TL_OPS_ALL; |
| 57 | } |