]> Git Repo - qemu.git/blame - hw/nvram/chrp_nvram.c
9p: xattr: Fix crashes due to free of uninitialized value
[qemu.git] / hw / nvram / chrp_nvram.c
CommitLineData
55d9950a
TH
1/*
2 * Common Hardware Reference Platform NVRAM helper functions.
3 *
4 * The CHRP NVRAM layout is used by OpenBIOS and SLOF. See CHRP
5 * specification, chapter 8, or the LoPAPR specification for details
6 * about the NVRAM layout.
7 *
8 * This code is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "qemu/osdep.h"
23#include "qemu/cutils.h"
24#include "hw/hw.h"
25#include "hw/nvram/chrp_nvram.h"
55d9950a
TH
26#include "sysemu/sysemu.h"
27
ad723fe5
TH
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
55d9950a
TH
38/**
39 * Create a "system partition", used for the Open Firmware
40 * environment variables.
41 */
42int chrp_nvram_create_system_partition(uint8_t *data, int min_len)
43{
ad723fe5 44 ChrpNvramPartHdr *part_header;
55d9950a
TH
45 unsigned int i;
46 int end;
47
ad723fe5
TH
48 part_header = (ChrpNvramPartHdr *)data;
49 part_header->signature = CHRP_NVPART_SYSTEM;
55d9950a
TH
50 pstrcpy(part_header->name, sizeof(part_header->name), "system");
51
ad723fe5 52 end = sizeof(ChrpNvramPartHdr);
55d9950a 53 for (i = 0; i < nb_prom_envs; i++) {
ad723fe5 54 end = chrp_nvram_set_var(data, end, prom_envs[i]);
55d9950a
TH
55 }
56
57 /* End marker */
58 data[end++] = '\0';
59
60 end = (end + 15) & ~15;
61 /* XXX: OpenBIOS is not able to grow up a partition. Leave some space for
62 new variables. */
63 if (end < min_len) {
64 end = min_len;
65 }
ad723fe5 66 chrp_nvram_finish_partition(part_header, end);
55d9950a
TH
67
68 return end;
69}
70
71/**
72 * Create a "free space" partition
73 */
74int chrp_nvram_create_free_partition(uint8_t *data, int len)
75{
ad723fe5 76 ChrpNvramPartHdr *part_header;
55d9950a 77
ad723fe5
TH
78 part_header = (ChrpNvramPartHdr *)data;
79 part_header->signature = CHRP_NVPART_FREE;
55d9950a
TH
80 pstrcpy(part_header->name, sizeof(part_header->name), "free");
81
ad723fe5 82 chrp_nvram_finish_partition(part_header, len);
55d9950a
TH
83
84 return len;
85}
This page took 0.141148 seconds and 4 git commands to generate.