2016-10-18 22:46:40 +02:00
|
|
|
/*
|
|
|
|
* Common Hardware Reference Platform NVRAM helper functions.
|
|
|
|
*
|
|
|
|
* The CHRP NVRAM layout is used by OpenBIOS and SLOF. See CHRP
|
|
|
|
* specification, chapter 8, or the LoPAPR specification for details
|
|
|
|
* about the NVRAM layout.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 2 of the License,
|
|
|
|
* or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qemu/cutils.h"
|
|
|
|
#include "hw/nvram/chrp_nvram.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
|
2016-10-18 22:46:43 +02:00
|
|
|
static int chrp_nvram_set_var(uint8_t *nvram, int addr, const char *str)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(str) + 1;
|
|
|
|
memcpy(&nvram[addr], str, len);
|
|
|
|
|
|
|
|
return addr + len;
|
|
|
|
}
|
|
|
|
|
2016-10-18 22:46:40 +02:00
|
|
|
/**
|
|
|
|
* Create a "system partition", used for the Open Firmware
|
|
|
|
* environment variables.
|
|
|
|
*/
|
|
|
|
int chrp_nvram_create_system_partition(uint8_t *data, int min_len)
|
|
|
|
{
|
2016-10-18 22:46:43 +02:00
|
|
|
ChrpNvramPartHdr *part_header;
|
2016-10-18 22:46:40 +02:00
|
|
|
unsigned int i;
|
|
|
|
int end;
|
|
|
|
|
2016-10-18 22:46:43 +02:00
|
|
|
part_header = (ChrpNvramPartHdr *)data;
|
|
|
|
part_header->signature = CHRP_NVPART_SYSTEM;
|
2016-10-18 22:46:40 +02:00
|
|
|
pstrcpy(part_header->name, sizeof(part_header->name), "system");
|
|
|
|
|
2016-10-18 22:46:43 +02:00
|
|
|
end = sizeof(ChrpNvramPartHdr);
|
2016-10-18 22:46:40 +02:00
|
|
|
for (i = 0; i < nb_prom_envs; i++) {
|
2016-10-18 22:46:43 +02:00
|
|
|
end = chrp_nvram_set_var(data, end, prom_envs[i]);
|
2016-10-18 22:46:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* End marker */
|
|
|
|
data[end++] = '\0';
|
|
|
|
|
|
|
|
end = (end + 15) & ~15;
|
|
|
|
/* XXX: OpenBIOS is not able to grow up a partition. Leave some space for
|
|
|
|
new variables. */
|
|
|
|
if (end < min_len) {
|
|
|
|
end = min_len;
|
|
|
|
}
|
2016-10-18 22:46:43 +02:00
|
|
|
chrp_nvram_finish_partition(part_header, end);
|
2016-10-18 22:46:40 +02:00
|
|
|
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a "free space" partition
|
|
|
|
*/
|
|
|
|
int chrp_nvram_create_free_partition(uint8_t *data, int len)
|
|
|
|
{
|
2016-10-18 22:46:43 +02:00
|
|
|
ChrpNvramPartHdr *part_header;
|
2016-10-18 22:46:40 +02:00
|
|
|
|
2016-10-18 22:46:43 +02:00
|
|
|
part_header = (ChrpNvramPartHdr *)data;
|
|
|
|
part_header->signature = CHRP_NVPART_FREE;
|
2016-10-18 22:46:40 +02:00
|
|
|
pstrcpy(part_header->name, sizeof(part_header->name), "free");
|
|
|
|
|
2016-10-18 22:46:43 +02:00
|
|
|
chrp_nvram_finish_partition(part_header, len);
|
2016-10-18 22:46:40 +02:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|