Skip to content

Commit

Permalink
DT: Add ibm,firmware-versions node
Browse files Browse the repository at this point in the history
In P8, hostboot provides mini device tree. It contains /ibm,firmware-versions
node which has various firmware component version details.

In P9, OPAL is building device tree. This patch adds support to parse VERSION
section of PNOR and create "/ibm,firmware-versions" device tree node.

Sample output:
	/sys/firmware/devicetree/base/ibm,firmware-versions # lsprop .
	occ              "6a00709"
	skiboot          "v5.7-rc1-p344fb62"
	buildroot        "2017.02.2-7-g23118ce"
	capp-ucode       "9c73e9f"
	petitboot        "v1.4.3-p98b6d83"
	sbe              "02021c6"
	open-power       "witherspoon-v1.17-128-gf1b53c7-dirty"
	....
	....

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Mukesh Ojha <mukesh02@linux.vnet.ibm.com>
Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
Vasant Hegde authored and stewartsmith committed Sep 5, 2017
1 parent 7b7428f commit 9727fe3
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
109 changes: 109 additions & 0 deletions core/flash.c
Expand Up @@ -19,6 +19,7 @@
#include <lock.h>
#include <opal.h>
#include <opal-msg.h>
#include <platform.h>
#include <device.h>
#include <libflash/libflash.h>
#include <libflash/libffs.h>
Expand Down Expand Up @@ -47,6 +48,10 @@ static struct lock flash_lock;
static struct flash *nvram_flash;
static u32 nvram_offset, nvram_size;

/* ibm,firmware-versions support */
static char *version_buf;
static size_t version_buf_size = 0x1000;

bool flash_reserve(void)
{
bool rc = false;
Expand Down Expand Up @@ -148,6 +153,109 @@ static int flash_nvram_write(uint32_t dst, void *src, uint32_t len)
return rc;
}

static void __flash_dt_add_fw_version(struct dt_node *fw_version, char* data)
{
char *prop;
int version_len, i;
int len = strlen(data);
const char * version_str[] = {"open-power", "buildroot", "skiboot",
"hostboot-binaries", "hostboot", "linux",
"petitboot", "occ", "capp-ucode", "sbe",
"machine-xml"};

/*
* PNOR version strings are not easily consumable. Split them into
* property, value.
*
* Example input from PNOR :
* "open-power-firestone-v1.8"
* "linux-4.4.6-openpower1-8420e0f"
*
* Desired output in device tree:
* open-power = "firestone-v1.8";
* linux = "4.4.6-openpower1-8420e0f";
*/
for(i = 0; i < ARRAY_SIZE(version_str); i++)
{
version_len = strlen(version_str[i]);
if (len < version_len)
continue;

if (memcmp(data, version_str[i], version_len) != 0)
continue;

/* Found a match, add property */
if (dt_find_property(fw_version, version_str[i]))
continue;

/* Increment past "key-" */
prop = data + version_len + 1;
dt_add_property_string(fw_version, version_str[i], prop);
}
}

void flash_dt_add_fw_version(void)
{
uint8_t version_data[80];
int rc;
int numbytes = 0, i = 0;
struct dt_node *fw_version;

if (version_buf == NULL)
return;

rc = wait_for_resource_loaded(RESOURCE_ID_VERSION, RESOURCE_SUBID_NONE);
if (rc != OPAL_SUCCESS) {
prlog(PR_WARNING, "FLASH: Failed to load VERSION data\n");
free(version_buf);
return;
}

fw_version = dt_new(dt_root, "ibm,firmware-versions");
assert(fw_version);

for ( ; (numbytes < version_buf_size) && version_buf[numbytes]; numbytes++) {
if (version_buf[numbytes] == '\n') {
version_data[i] = '\0';
__flash_dt_add_fw_version(fw_version, version_data);
memset(version_data, 0, sizeof(version_data));
i = 0;
continue;
} else if (version_buf[numbytes] == '\t') {
continue; /* skip tabs */
}

version_data[i++] = version_buf[numbytes];
}

free(version_buf);
}

void flash_fw_version_preload(void)
{
int rc;

if (proc_gen < proc_gen_p9)
return;

prlog(PR_INFO, "FLASH: Loading VERSION section\n");

version_buf = malloc(version_buf_size);
if (!version_buf) {
prlog(PR_WARNING, "FLASH: Failed to allocate memory\n");
return;
}

rc = start_preload_resource(RESOURCE_ID_VERSION, RESOURCE_SUBID_NONE,
version_buf, &version_buf_size);
if (rc != OPAL_SUCCESS) {
prlog(PR_WARNING,
"FLASH: Failed to start loading VERSION data\n");
free(version_buf);
version_buf = NULL;
}
}

static int flash_nvram_probe(struct flash *flash, struct ffs_handle *ffs)
{
uint32_t start, size, part;
Expand Down Expand Up @@ -422,6 +530,7 @@ static struct {
{ RESOURCE_ID_INITRAMFS,RESOURCE_SUBID_NONE, "ROOTFS" },
{ RESOURCE_ID_CAPP, RESOURCE_SUBID_SUPPORTED, "CAPP" },
{ RESOURCE_ID_IMA_CATALOG, RESOURCE_SUBID_SUPPORTED, "IMA_CATALOG" },
{ RESOURCE_ID_VERSION, RESOURCE_SUBID_NONE, "VERSION" },
};


Expand Down
1 change: 1 addition & 0 deletions include/platform.h
Expand Up @@ -28,6 +28,7 @@ enum resource_id {
RESOURCE_ID_INITRAMFS,
RESOURCE_ID_CAPP,
RESOURCE_ID_IMA_CATALOG,
RESOURCE_ID_VERSION,
};
#define RESOURCE_SUBID_NONE 0
#define RESOURCE_SUBID_SUPPORTED 1
Expand Down
3 changes: 3 additions & 0 deletions include/skiboot.h
Expand Up @@ -243,6 +243,9 @@ extern int flash_subpart_info(void *part_header, uint32_t header_len,
uint32_t part_size, uint32_t *part_actual,
uint32_t subid, uint32_t *offset,
uint32_t *size);
extern void flash_fw_version_preload(void);
extern void flash_dt_add_fw_version(void);

/* NVRAM support */
extern void nvram_init(void);
extern void nvram_read_complete(bool success);
Expand Down
6 changes: 6 additions & 0 deletions platforms/astbmc/common.c
Expand Up @@ -134,6 +134,9 @@ void astbmc_init(void)
astbmc_fru_init();
ipmi_sensor_init();

/* Preload PNOR VERSION section */
flash_fw_version_preload();

/* As soon as IPMI is up, inform BMC we are in "S0" */
ipmi_set_power_state(IPMI_PWR_SYS_S0_WORKING, IPMI_PWR_NOCHANGE);

Expand All @@ -144,6 +147,9 @@ void astbmc_init(void)

/* Setup UART console for use by Linux via OPAL API */
set_opal_console(&uart_opal_con);

/* Add ibm,firmware-versions node */
flash_dt_add_fw_version();
}

int64_t astbmc_ipmi_power_down(uint64_t request)
Expand Down

0 comments on commit 9727fe3

Please sign in to comment.