blob: c83b0b368ccbe33da1ed60a841d775a42d282821 [file] [log] [blame]
Harrison Mutai6e011642023-09-22 17:17:35 +01001/*
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
11struct 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
23void *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 ******************************************************************************/
33enum transfer_list_ops
34transfer_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}