coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spm.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <assert.h>
4 #include <console/console.h>
5 #include <soc/mcu_common.h>
6 #include <soc/spm.h>
7 #include <soc/spm_common.h>
8 #include <string.h>
9 
10 #define SPMFW_HEADER_SIZE 16
11 
12 void spm_parse_firmware(struct mtk_mcu *mcu)
13 {
14  size_t file_size, copy_size;
15  int offset;
16  u16 firmware_size;
17 
18  struct dyna_load_pcm *pcm = (struct dyna_load_pcm *)mcu->priv;
19  file_size = mcu->run_size;
20 
21  /*
22  * spmfw layout:
23  * u16 firmware_size
24  * u32 binary[firmware_size]
25  * struct pcm_desc descriptor
26  * char *version
27  */
28 
29  /* Firmware size */
30  offset = 0;
31  copy_size = sizeof(firmware_size);
32  memcpy(&firmware_size, mcu->load_buffer + offset, copy_size);
33  printk(BIOS_DEBUG, "SPM: binary array size = %#x\n", firmware_size);
34 
35  /* Binary */
36  offset = SPMFW_HEADER_SIZE; /* binary start offset */
37  copy_size = firmware_size * sizeof(u32);
38  assert(offset < file_size);
39  pcm->buf = (u8 *)(mcu->load_buffer + offset);
40 
41  /* Descriptor */
42  offset += copy_size;
43  assert(offset < file_size);
44  copy_size = sizeof(pcm->desc);
45  memcpy(&pcm->desc, mcu->load_buffer + offset, copy_size);
46 
47  /* Firmware size and total words need to be the same */
48  assert(firmware_size == pcm->desc.total_words);
49 
50  /* Version */
51  offset += copy_size;
52  assert(offset < file_size);
53  printk(BIOS_INFO, "SPM: spmfw (version %.*s)\n",
54  (int)(file_size - offset),
55  (u8 *)mcu->load_buffer + offset);
56 }
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
#define assert(statement)
Definition: assert.h:74
void spm_parse_firmware(struct mtk_mcu *mcu)
Definition: spm.c:12
#define SPMFW_HEADER_SIZE
Definition: spm.c:10
#define printk(level,...)
Definition: stdlib.h:16
static size_t offset
Definition: flashconsole.c:16
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
u32 * buf
Definition: spm.h:578
struct pcm_desc desc
Definition: spm.h:579
void * priv
Definition: mcu_common.h:12
void * load_buffer
Definition: mcu_common.h:10
size_t run_size
Definition: mcu_common.h:9
uint32_t total_words
Definition: spm.h:848