From patchwork Wed Aug 17 05:32:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 659904 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sDdFT5sftz9sD5 for ; Wed, 17 Aug 2016 15:34:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=By2n9m4S; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3sDdFT4d9fzDr4d for ; Wed, 17 Aug 2016 15:34:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=By2n9m4S; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pa0-x242.google.com (mail-pa0-x242.google.com [IPv6:2607:f8b0:400e:c03::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3sDdDp6ycpzDr4r for ; Wed, 17 Aug 2016 15:33:30 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=By2n9m4S; dkim-atps=neutral Received: by mail-pa0-x242.google.com with SMTP id vy10so6296021pac.0 for ; Tue, 16 Aug 2016 22:33:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YmO2XYFD6Of807vtQWnLk4dXuY5tE/3loCuTpZJGWvA=; b=By2n9m4STpJ/wGrTrC3VYTBXPVa/0irIyZv4tnt0/iQPNFhWrcwNpd8CQldYk7Zzml k3M0sGmzmq+Bfrojk448cArWVAwvZ6UthQ4Zx6MAzJZFpZvkM5eHcV0przF6h0Clhf3w FbCmfdLtDequ8TfqgfW+Pw1RmEkYsodwkDS+r+ETevW9Fvo4gVj7q+oj2BeYy6ROw5jf UC414mtymjTMyMIYr8OzOJUiP7pe5ewUiHTV0QPhSlLFwZgIzApM4OgP/u63E9hNZIOr HyayIDo7+p98Pt+cc1nFhyKOcEVHLzzDPisnOmzTYY928VJFMzYE8EECTxj53t2XPPE1 IgHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YmO2XYFD6Of807vtQWnLk4dXuY5tE/3loCuTpZJGWvA=; b=LSMQYbt4Mw1PKlbGanimHnL8aTuBVVw9AUnpeqQMXK91CCBxflk0Eb5LqjuiAizfI0 vW1ZZGUNFqbZk21jaBOcRYvTG2Y3XFYwcTxqnPOlSn2fxKbskxE96j3OVn9VpoB3u/8I sjh8pJhP7fz6RH6B8XZzmGTWmhpaLDjxsI1T4Qr1MaK/+bzOfkRdz7JbbRiL46xkATN5 pWqztNnkyGqBK01a8eANQ/nAFitb6LQ8Ag+P9H9Oi9ZAirf9CXZmU8OKPuI4WSJ8JHX0 kLo6oQ9OKyOBk2zWYgXUufVHoio+zQUegW/TDrs7sFKhEz3o0CbEinV4pTKQIsFtOqOC qHDA== X-Gm-Message-State: AEkoouuQTJDocx23r1amhgfM6SZSHPTMvi3FBvtPNu0Va3gGdCsfMcXpHLzffgk30+Mvag== X-Received: by 10.66.234.161 with SMTP id uf1mr70628583pac.93.1471412009320; Tue, 16 Aug 2016 22:33:29 -0700 (PDT) Received: from canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id p75sm43376027pfa.71.2016.08.16.22.33.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Aug 2016 22:33:28 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Wed, 17 Aug 2016 15:32:51 +1000 Message-Id: <1471411974-8179-5-git-send-email-oohall@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1471411974-8179-1-git-send-email-oohall@gmail.com> References: <1471411974-8179-1-git-send-email-oohall@gmail.com> Subject: [Skiboot] [PATCH v2 4/7] core/nvram: add support for skiboot config strings X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This allows the ibm,skiboot partition to be used to store NUL terminated key=value OF configuration strings. These strings can be written using the nvram utility found in the linux powerpc-utils package. Currently the only use case for this is passing command line arguments to the boot kernel so only ASCII strings are supported. The 0xFF binary escaping mechanism for configuration strings is not supported. Signed-off-by: Oliver O'Halloran --- core/nvram-format.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/nvram.h | 2 ++ 2 files changed, 70 insertions(+) diff --git a/core/nvram-format.c b/core/nvram-format.c index 5d15a60f05b5..227147efbaa9 100644 --- a/core/nvram-format.c +++ b/core/nvram-format.c @@ -179,3 +179,71 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size) failed: return -1; } + +static const char *find_next_key(const char *start, const char *end) +{ + /* + * Unused parts of the partition are set to NUL. If we hit two + * NULs in a row then we assume that we have hit the end of the + * partition. + */ + if (*start == 0) + return NULL; + + while (start < end) { + if (*start == 0) + return start + 1; + + start++; + } + + return NULL; +} + +/* + * nvram_query() - Searches skiboot NVRAM partition for a key=value pair. + * + * Returns a pointer to a NUL terminated string that contains the value + * associated with the given key. + */ +const char *nvram_query(const char *key) +{ + const char *part_end = (const char *) skiboot_part_hdr + + skiboot_part_hdr->len * 16 - 1; + const char *start = (const char *) skiboot_part_hdr + + sizeof(*skiboot_part_hdr); + int key_len = strlen(key); + + if (!key_len) { + prlog(PR_WARNING, "NVRAM: search key is empty!\n"); + return NULL; + } + + if (key_len > 32) + prlog(PR_WARNING, "NVRAM: search key '%s' is longer than 32 chars\n", key); + + while (start) { + int remaining = part_end - start; + + prlog(PR_TRACE, "NVRAM: '%s' (%lu)\n", + start, strlen(start)); + + if (key_len + 1 > remaining) + return NULL; + + if (!strncmp(key, start, key_len) && start[key_len] == '=') { + const char *value = &start[key_len + 1]; + + prlog(PR_DEBUG, "NVRAM: Searched for '%s' found '%s'\n", + key, value); + + return value; + } + + start = find_next_key(start, part_end); + } + + prlog(PR_DEBUG, "NVRAM: '%s' not found\n", key); + + return NULL; +} diff --git a/include/nvram.h b/include/nvram.h index c90c5712a2f7..19f8eff633e4 100644 --- a/include/nvram.h +++ b/include/nvram.h @@ -21,4 +21,6 @@ int nvram_format(void *nvram_image, uint32_t nvram_size); int nvram_check(void *nvram_image, uint32_t nvram_size); void nvram_reinit(void); +const char *nvram_query(const char *name); + #endif /* __NVRAM_H */