1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "qemu/osdep.h"
23#include "qemu/cutils.h"
24#include "hw/hw.h"
25#include "hw/nvram/chrp_nvram.h"
26#include "sysemu/sysemu.h"
27
28static int chrp_nvram_set_var(uint8_t *nvram, int addr, const char *str)
29{
30 int len;
31
32 len = strlen(str) + 1;
33 memcpy(&nvram[addr], str, len);
34
35 return addr + len;
36}
37
38
39
40
41
42int chrp_nvram_create_system_partition(uint8_t *data, int min_len)
43{
44 ChrpNvramPartHdr *part_header;
45 unsigned int i;
46 int end;
47
48 part_header = (ChrpNvramPartHdr *)data;
49 part_header->signature = CHRP_NVPART_SYSTEM;
50 pstrcpy(part_header->name, sizeof(part_header->name), "system");
51
52 end = sizeof(ChrpNvramPartHdr);
53 for (i = 0; i < nb_prom_envs; i++) {
54 end = chrp_nvram_set_var(data, end, prom_envs[i]);
55 }
56
57
58 data[end++] = '\0';
59
60 end = (end + 15) & ~15;
61
62
63 if (end < min_len) {
64 end = min_len;
65 }
66 chrp_nvram_finish_partition(part_header, end);
67
68 return end;
69}
70
71
72
73
74int chrp_nvram_create_free_partition(uint8_t *data, int len)
75{
76 ChrpNvramPartHdr *part_header;
77
78 part_header = (ChrpNvramPartHdr *)data;
79 part_header->signature = CHRP_NVPART_FREE;
80 pstrcpy(part_header->name, sizeof(part_header->name), "free");
81
82 chrp_nvram_finish_partition(part_header, len);
83
84 return len;
85}
86