error: Avoid error_propagate() after migrate_add_blocker()
[qemu/ar7.git] / hw / nvram / chrp_nvram.c
blobd969f267048e626007d284dcfa72844ddcd61c84
1 /*
2 * Common Hardware Reference Platform NVRAM helper functions.
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.
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.
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.
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/>.
22 #include "qemu/osdep.h"
23 #include "qemu/cutils.h"
24 #include "hw/nvram/chrp_nvram.h"
25 #include "sysemu/sysemu.h"
27 static int chrp_nvram_set_var(uint8_t *nvram, int addr, const char *str)
29 int len;
31 len = strlen(str) + 1;
32 memcpy(&nvram[addr], str, len);
34 return addr + len;
37 /**
38 * Create a "system partition", used for the Open Firmware
39 * environment variables.
41 int chrp_nvram_create_system_partition(uint8_t *data, int min_len)
43 ChrpNvramPartHdr *part_header;
44 unsigned int i;
45 int end;
47 part_header = (ChrpNvramPartHdr *)data;
48 part_header->signature = CHRP_NVPART_SYSTEM;
49 pstrcpy(part_header->name, sizeof(part_header->name), "system");
51 end = sizeof(ChrpNvramPartHdr);
52 for (i = 0; i < nb_prom_envs; i++) {
53 end = chrp_nvram_set_var(data, end, prom_envs[i]);
56 /* End marker */
57 data[end++] = '\0';
59 end = (end + 15) & ~15;
60 /* XXX: OpenBIOS is not able to grow up a partition. Leave some space for
61 new variables. */
62 if (end < min_len) {
63 end = min_len;
65 chrp_nvram_finish_partition(part_header, end);
67 return end;
70 /**
71 * Create a "free space" partition
73 int chrp_nvram_create_free_partition(uint8_t *data, int len)
75 ChrpNvramPartHdr *part_header;
77 part_header = (ChrpNvramPartHdr *)data;
78 part_header->signature = CHRP_NVPART_FREE;
79 pstrcpy(part_header->name, sizeof(part_header->name), "free");
81 chrp_nvram_finish_partition(part_header, len);
83 return len;