treewide: Move device_tree to commonlib
[coreboot2.git] / util / cbfstool / cse_helpers.c
blobc60005a21acf4fb2c50aa4200c36aaf7ad24106c
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Helper functions for cse_serger and cse_fpt */
4 #include <commonlib/endian.h>
6 #include "cse_helpers.h"
8 void write_member(struct buffer *buff, void *src, size_t size)
10 void *dst = buffer_get(buff);
12 switch (size) {
13 case 1:
14 write_le8(dst, *(uint8_t *)src);
15 break;
16 case 2:
17 write_le16(dst, *(uint16_t *)src);
18 break;
19 case 4:
20 write_le32(dst, *(uint32_t *)src);
21 break;
22 case 8:
23 write_le64(dst, *(uint64_t *)src);
24 break;
25 default:
26 memcpy(dst, src, size);
27 break;
30 buffer_seek(buff, size);
33 void read_member(struct buffer *buff, void *dst, size_t size)
35 const void *src = buffer_get(buff);
37 switch (size) {
38 case 1:
39 *(uint8_t *)dst = read_le8(src);
40 break;
41 case 2:
42 *(uint16_t *)dst = read_le16(src);
43 break;
44 case 4:
45 *(uint32_t *)dst = read_le32(src);
46 break;
47 case 8:
48 *(uint64_t *)dst = read_le64(src);
49 break;
50 default:
51 memcpy(dst, src, size);
52 break;
55 buffer_seek(buff, size);