From patchwork Mon Aug 8 02:58:32 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: 656527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s72F92Yzfz9sDk for ; Mon, 8 Aug 2016 12:59:25 +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=WP7gXTfo; dkim-atps=neutral Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3s72F91VHNzDqZW for ; Mon, 8 Aug 2016 12:59:25 +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=WP7gXTfo; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pa0-x241.google.com (mail-pa0-x241.google.com [IPv6:2607:f8b0:400e:c03::241]) (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 3s72Db0SRSzDqZq for ; Mon, 8 Aug 2016 12:58:55 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=WP7gXTfo; dkim-atps=neutral Received: by mail-pa0-x241.google.com with SMTP id hh10so23183795pac.1 for ; Sun, 07 Aug 2016 19:58:54 -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=SREdUcRax+xbi8YXCh5pm4F0G6q06Q3M8QEO4q54ZQY=; b=WP7gXTfoCifmnPsQy1aRHR3DK4ja6fGIqad9X/HSZAhECxmswYK8oTYpym3HUbL26/ phtBXFDilHWWi64LjK45h4BiDrc0x6/27XJLlUr0qBXBbPpoXi0veVTy523jOSjESiXj lpR+7wMNbBfR2E1aONs9wRBrdhOcsvCNwkj5g+NL8ZM5r2eFsVt+ctWlRYXhZTtfNLjX ppLWMKmD8i8uzMQieLCkzCgCpBmV0XiAkUJc737BHGWQjaoHIx8P42ioqNoXlCO84tcd oWRhQY9oXyIs3d5srX7GhLXJuyRvc34NGlwy26YXg5bwyewfYb2faKDfgkyQcQ6XOAxW F2qw== 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=SREdUcRax+xbi8YXCh5pm4F0G6q06Q3M8QEO4q54ZQY=; b=YBp493c2gHPlJ/78eELNUPIDlJp36AGLP7pcebJSJ6BTNn+N1SU54vRIi+7OLLkNxZ v14ydI7kQnDY/sVhOafK8kBl9eQ6EXFMYPb7/PhXfpTDQV3VfoQZSVUCk3DfC8SR9Tj/ btG+IdDnEQQecrraYS17SIK+y0dqgW9wHmd0Qv7jx4TiECkT2+xaoGSKOEyFrcAHkVOU Qrqt0dBgpIpRK4P21HqMtcJNwVBKlZJ2OtS8DkEPWN9FkBN5VB7nZm2h3HQ2NVwJgKrW gCCY30MBKVDJwGoP2Rj3lf1gIzc/X0pcYQrS9VG/VqK+CYiguZITuK9G1j+bt8NCMDRj gafA== X-Gm-Message-State: AEkoousnO4D45VdEz/qHdOBEI+MBFHoijrd+J5oYz+Q/zbk415f7IhI6uF9ImGw54E0tNQ== X-Received: by 10.66.217.170 with SMTP id oz10mr148523202pac.61.1470625133092; Sun, 07 Aug 2016 19:58:53 -0700 (PDT) Received: from canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id 184sm43374144pfg.20.2016.08.07.19.58.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 19:58:52 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Mon, 8 Aug 2016 12:58:32 +1000 Message-Id: <1470625113-29275-4-git-send-email-oohall@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1470625113-29275-1-git-send-email-oohall@gmail.com> References: <1470625113-29275-1-git-send-email-oohall@gmail.com> Subject: [Skiboot] [PATCH 4/5] 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 | 67 +++++++++++++++++++++++++++++++++++++++++++++++++---- include/nvram.h | 2 ++ 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/core/nvram-format.c b/core/nvram-format.c index be8d77f8394b..57d51842e360 100644 --- a/core/nvram-format.c +++ b/core/nvram-format.c @@ -28,6 +28,8 @@ struct chrp_nvram_hdr { char name[12]; }; +struct chrp_nvram_hdr *skiboot_part_hdr; + #define NVRAM_SIG_FW_PRIV 0x51 #define NVRAM_SIG_SYSTEM 0x70 #define NVRAM_SIG_FREE 0x7f @@ -115,7 +117,8 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size) { unsigned int offset = 0; bool found_common = false; - bool found_skiboot = false; + + skiboot_part_hdr = NULL; while (offset + sizeof(struct chrp_nvram_hdr) < nvram_size) { struct chrp_nvram_hdr *h = nvram_image + offset; @@ -138,7 +141,7 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size) if (h->sig == NVRAM_SIG_FW_PRIV && strcmp(h->name, NVRAM_NAME_FW_PRIV) == 0) - found_skiboot = true; + skiboot_part_hdr = h; offset += h->len << 4; if (offset > nvram_size) { @@ -151,9 +154,9 @@ int nvram_check(void *nvram_image, const uint32_t nvram_size) prerror("NVRAM: Common partition not found !\n"); goto failed; } - if (!found_skiboot) { - prerror("NVRAM: Skiboot private partition " - "not found !\n"); + + if (!skiboot_part_hdr) { + prerror("NVRAM: Skiboot private partition not found !\n"); goto failed; } else { /* @@ -176,3 +179,57 @@ 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) +{ + while (start < end) { + if (*start == 0) + return start + 1; + + start++; + } + + return end; +} + +/* + * nvram_query() - Returns the value associated with a key. The ibm,skiboot + * partition contains a set of key=value pairs separated by NUL terminators. + */ +const void *nvram_query(const char *key, size_t *length) +{ + const char *part_end = (const void *) skiboot_part_hdr + + skiboot_part_hdr->len * 16; + const char *start = (void *)skiboot_part_hdr + + sizeof(*skiboot_part_hdr); + const char *end = find_next_key(start, part_end); + int key_len = strlen(key); + + prlog(PR_TRACE, "start: %p %s\n", start, start); + prlog(PR_TRACE, "end: %p %s\n", end, end); + + while (start < end) { + int remaining = part_end - start; + + if (key_len + 1 > remaining) + return NULL; + + if (strlen(start)) + prlog(PR_TRACE, "NVRAM: '%s' (%lu)\n", + start, strlen(start)); + + if (!strncmp(key, start, key_len) && start[key_len] == '=') { + const char *value = &start[key_len + 1]; + + if (length) + *length = end - value; + + return value; + } + + start = end; + end = find_next_key(end, part_end); + } + + return NULL; +} diff --git a/include/nvram.h b/include/nvram.h index c90c5712a2f7..b4faa2e72dc8 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 void *nvram_query(const char *name, size_t *length); + #endif /* __NVRAM_H */