summaryrefslogtreecommitdiffstats
path: root/src/core/nvo.c
diff options
context:
space:
mode:
authorMichael Brown2010-11-25 01:05:20 +0100
committerMichael Brown2010-11-25 01:05:20 +0100
commitb87ed3295eb1cdeec36db45799113f4ce79537ca (patch)
tree101f7dc174efa6ddd2d740563fd94d72d6fe66c0 /src/core/nvo.c
parent[pci] Add a mechanism for using a PCI VPD field as an NVS device (diff)
downloadipxe-b87ed3295eb1cdeec36db45799113f4ce79537ca.tar.gz
ipxe-b87ed3295eb1cdeec36db45799113f4ce79537ca.tar.xz
ipxe-b87ed3295eb1cdeec36db45799113f4ce79537ca.zip
[nvo] Allow fragment list to be omitted
Allow the fragment list to be omitted when calling nvo_init(). Omitting the list will cause the whole of the NVS device to be used for NVO storage. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/nvo.c')
-rw-r--r--src/core/nvo.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/core/nvo.c b/src/core/nvo.c
index 327f4f98..00f2d9ff 100644
--- a/src/core/nvo.c
+++ b/src/core/nvo.c
@@ -197,7 +197,7 @@ static struct settings_operations nvo_settings_operations = {
*
* @v nvo Non-volatile options block
* @v nvs Underlying non-volatile storage device
- * @v fragments List of option-containing fragments
+ * @v fragments List of option-containing fragments, or NULL
* @v refcnt Containing object reference counter, or NULL
*/
void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
@@ -219,18 +219,32 @@ int register_nvo ( struct nvo_block *nvo, struct settings *parent ) {
struct nvo_fragment *fragment = nvo->fragments;
int rc;
- /* Calculate total length of all fragments */
- for ( fragment = nvo->fragments ; fragment->len ; fragment++ )
- nvo->total_len += fragment->len;
+ /* Calculate total length of all fragments, if applicable */
+ if ( fragment ) {
+ for ( ; fragment->len ; fragment++ )
+ nvo->total_len += fragment->len;
+ } else {
+ nvo->total_len = nvo->nvs->size;
+ }
- /* Allocate memory for options and read in from NVS */
- nvo->data = malloc ( nvo->total_len );
+ /* Allocate memory for options (and fragment list, if applicable) */
+ nvo->data = zalloc ( nvo->total_len +
+ ( fragment ? 0 : ( 2 * sizeof ( *fragment ) ) ) );
if ( ! nvo->data ) {
DBGC ( nvo, "NVO %p could not allocate %zd bytes\n",
nvo, nvo->total_len );
rc = -ENOMEM;
goto err_malloc;
}
+
+ /* Create fragment list, if applicable */
+ if ( ! fragment ) {
+ fragment = ( nvo->data + nvo->total_len );
+ fragment->len = nvo->total_len;
+ nvo->fragments = fragment;
+ }
+
+ /* Read data from NVS */
if ( ( rc = nvo_load ( nvo ) ) != 0 )
goto err_load;