xref: /aosp_15_r20/external/coreboot/src/drivers/camera/cros_camera.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <crc_byte.h>
5 #include <string.h>
6 
7 #include "cros_camera.h"
8 
check_cros_camera_info(const struct cros_camera_info * info)9 int check_cros_camera_info(const struct cros_camera_info *info)
10 {
11 	if (memcmp(info->magic, CROS_CAMERA_INFO_MAGIC, sizeof(info->magic))) {
12 		printk(BIOS_ERR, "Invalid magic in camera info\n");
13 		return -1;
14 	}
15 
16 	const uint8_t *ptr = (void *)(&info->crc16 + 1);
17 	uint16_t crc16 = 0;
18 	while (ptr < (uint8_t *)info + sizeof(struct cros_camera_info))
19 		crc16 = crc16_byte(crc16, *ptr++);
20 
21 	if (info->crc16 != crc16) {
22 		printk(BIOS_ERR, "Incorrect CRC16: expected %#06x, got %#06x\n",
23 		       crc16, info->crc16);
24 		return -1;
25 	}
26 
27 	if (info->version != CROS_CAMERA_INFO_VERSION) {
28 		printk(BIOS_ERR, "Unknown camera info version: %u\n",
29 		       info->version);
30 		return -1;
31 	}
32 	if (info->size < CROS_CAMERA_INFO_SIZE_MIN) {
33 		printk(BIOS_ERR, "Size of camera info is too small: %u\n",
34 		       info->size);
35 		return -1;
36 	}
37 
38 	return 0;
39 }
40