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
)
31 len
= strlen(str
) + 1;
32 memcpy(&nvram
[addr
], str
, len
);
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
;
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
]);
59 end
= (end
+ 15) & ~15;
60 /* XXX: OpenBIOS is not able to grow up a partition. Leave some space for
65 chrp_nvram_finish_partition(part_header
, end
);
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
);