From patchwork Fri Dec 14 09:47:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 153791 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1856440ljp; Fri, 14 Dec 2018 01:44:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/UioxOavy21qazSOFKHOBsyIr5fzLlaOB8SlstDv15e36S0Wz3T6iyICayQRO8EzrWJMHIu X-Received: by 2002:a50:c182:: with SMTP id m2mr2421626edf.139.1544780653989; Fri, 14 Dec 2018 01:44:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544780653; cv=none; d=google.com; s=arc-20160816; b=xfeXS5kesTACT3cRXrWibP8ivY1w9/eijKnoX0ZRfJ1JvzPb7g/11AkI7fO4YS25x+ tA5jo4to1puUYINy5SHHsi/3zNoqWKwBUFqjHdG4wFmjeOR8yzdx3nD2psgtG3z5/Vs6 RiT5YghhOCEa4m65dP4CzzT/VD/ue6fUS6wF70H7JUbXOBK5LE+d/ZSa1ix7INn2gJEz arv7HvGA6V/YdUProFc1l+L//BHRvjfYAQWun9qTtZS6EH+ZrHFYrE7kqslVfZhhKi0q taDjYSWkmFkk/aniQWxuzJnQO6WJmE10A69D0Hf58fK5cG4RGWYOv3VYk23/Iu7jxsFh Z4FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:message-id:date:to:from:dkim-signature; bh=pfUlnKUHQ+wwUnUlDo0mOql2Y4vPhrwPsL4NxRjaT2Y=; b=dSSagXc2PbbpaqE2uqj1rEmBtmCiXxHsdtzcR/+6Eq1APuDgvt//jRkI9MDszReXMu ena+qyCKfsB5XhIJbQKEp/vBMgE+kv3/nXOIrVm63aedi0/bTGv1EHXb5+rJxYoGq/f3 LBWiunCkE6SBaaS7/y/2V1CJDQnBrizIMJReBBI9f0pFMatjVEFmdcZEV3eYpRiG2ZiX APyGmzyliMe0EHcx1UOPfL4DJ0+LCXXt0XUz7d1V8ZfiG/VgWWDtAolLsBF0RhyhFGrP DnmO3LfwJHHaEoV0seb60+vuF0rvuk0/bZlaNEF+XrsJHHl5SgOecYrJ7TYw0sRiECf2 PVDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=P4A9YlfH; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id g5si83846edn.354.2018.12.14.01.44.13; Fri, 14 Dec 2018 01:44:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=P4A9YlfH; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 95E4FC225D0; Fri, 14 Dec 2018 09:44:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C0104C21FD6; Fri, 14 Dec 2018 09:44:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 33FE7C21FD6; Fri, 14 Dec 2018 09:44:07 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 445D7C21F49 for ; Fri, 14 Dec 2018 09:44:06 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id d2so2004814ybs.11 for ; Fri, 14 Dec 2018 01:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=r7wwdbRQz3B4/PVs5NP2Ot9MNqM5YCL6BiIWB0lHZRY=; b=P4A9YlfHF6PC14WBZXHT3YajezS0jBb9/xAtLjkp3I2PykYDoWyUtUYZnuvtWwt3H4 ePZmlHfmQEeoSu1HDiA4x2bp0WSl18WgxUBahKYRNhOQ0nZpPeMKtaV5eF8+tqWx/0kZ HU/DJF99akRt9gjWTHCrQUbYslhFeVMXJUsPc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=r7wwdbRQz3B4/PVs5NP2Ot9MNqM5YCL6BiIWB0lHZRY=; b=rNOhI2OtAggyFPZ/wrdTLEOD+vf6iSf8kmK+kbJDvWXdkPRPoM3Ozygl66RWt3pI7c xT4cUAV3tX+TbHae8CjVIML4YDSVUP2HGn9APMBBT2CJVo0cJcoRAN+nuyOhpxeEwQi4 t9ASGj6C3yCNRd9kOO7OCkT442fDW6IUSduNYnJYmjgLry0g+2bJlvheG5Mx2Gk0cJGt ZRcrmkn22H5NMuIJI1Zf2LWiiAn57MVn6s5PfxE002Gq2eI3cX/zf0BcOnjtb5zrs7XP DVKmsbTuSxHfCCkPszwC+V+jcF2oju95f7m8JLd3VVOMWjlXtqyZsISXJTvG7/DdK5lH 5O3A== X-Gm-Message-State: AA+aEWYb+tA0rl8H70X0bfA6V/eRMueA4JxQ1NgEiaJzsEiOXHQeG22T czeJUTx8XPuKtzpGERwwg/jw3Q== X-Received: by 2002:a25:3852:: with SMTP id f79mr2098651yba.237.1544780644935; Fri, 14 Dec 2018 01:44:04 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j2sm1425422ywa.73.2018.12.14.01.44.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 01:44:04 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Fri, 14 Dec 2018 18:47:11 +0900 Message-Id: <20181214094712.9051-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/2] efi_loader: implement GetNextVariableName() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The current GetNextVariableName() is a placeholder. With this patch, it works well as expected. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_variable.c | 116 +++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 19d9cb865f25..dac2f49aa1cc 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #define READ_ONLY BIT(31) @@ -241,14 +244,125 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name, efi_guid_t *vendor, return EFI_EXIT(EFI_SUCCESS); } +static char *efi_variables_list; +static char *efi_cur_variable; + +static efi_status_t parse_uboot_variable(char *variable, + efi_uintn_t *variable_name_size, + u16 *variable_name, + efi_guid_t *vendor, + u32 *attribute) +{ + char *guid, *name, *end, c; + unsigned long name_size; + u16 *p; + + guid = strchr(variable, '_'); + if (!guid) + return EFI_NOT_FOUND; + guid++; + name = strchr(guid, '_'); + if (!name) + return EFI_NOT_FOUND; + name++; + end = strchr(name, '='); + if (!end) + return EFI_NOT_FOUND; + + /* FIXME: size is in byte or u16? */ + name_size = end - name; + if (*variable_name_size < (name_size + 1)) { + *variable_name_size = name_size + 1; + return EFI_BUFFER_TOO_SMALL; + } + end++; /* point to value */ + + p = variable_name; + utf8_utf16_strncpy(&p, name, name_size); + variable_name[name_size] = 0; + + c = *(name - 1); + *(name - 1) = '\0'; /* guid need be null-terminated here */ + uuid_str_to_bin(guid, (unsigned char *)vendor, UUID_STR_FORMAT_GUID); + *(name - 1) = c; + + parse_attr(end, attribute); + + return EFI_SUCCESS; +} + /* http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#GetNextVariableName.28.29 */ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, u16 *variable_name, efi_guid_t *vendor) { + char *native_name, *variable; + ssize_t name_len, list_len; + char regex[256]; + char * const regexlist[] = {regex}; + u32 attribute; + int i; + efi_status_t ret; + EFI_ENTRY("%p \"%ls\" %pUl", variable_name_size, variable_name, vendor); - return EFI_EXIT(EFI_DEVICE_ERROR); + if (!variable_name_size || !variable_name || !vendor) + EFI_EXIT(EFI_INVALID_PARAMETER); + + if (variable_name[0]) { + /* check null-terminated string */ + for (i = 0; i < *variable_name_size; i++) + if (!variable_name[i]) + break; + if (i >= *variable_name_size) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + /* search for the last-returned variable */ + ret = efi_to_native(&native_name, variable_name, vendor); + if (ret) + return EFI_EXIT(ret); + + name_len = strlen(native_name); + for (variable = efi_variables_list; variable && *variable;) { + if (!strncmp(variable, native_name, name_len) && + variable[name_len] == '=') + break; + + variable = strchr(variable, '\n'); + if (variable) + variable++; + } + + free(native_name); + if (!(variable && *variable)) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + /* next variable */ + variable = strchr(variable, '\n'); + if (variable) + variable++; + if (!(variable && *variable)) + return EFI_EXIT(EFI_NOT_FOUND); + } else { + /* new search */ + free(efi_variables_list); + efi_variables_list = NULL; + efi_cur_variable = NULL; + + snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_.*"); + list_len = hexport_r(&env_htab, '\n', + H_MATCH_REGEX | H_MATCH_KEY, + &efi_variables_list, 0, 1, regexlist); + if (list_len <= 0) + return EFI_EXIT(EFI_NOT_FOUND); + + variable = efi_variables_list; + } + + ret = parse_uboot_variable(variable, variable_name_size, variable_name, + vendor, &attribute); + + return EFI_EXIT(ret); } /* http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#SetVariable.28.29 */