From owner-svn-src-all@freebsd.org Mon Dec 14 22:00:47 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 92804A47947; Mon, 14 Dec 2015 22:00:47 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4C90A15BF; Mon, 14 Dec 2015 22:00:47 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBEM0k5V049487; Mon, 14 Dec 2015 22:00:46 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBEM0kjP049486; Mon, 14 Dec 2015 22:00:46 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201512142200.tBEM0kjP049486@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Mon, 14 Dec 2015 22:00:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292227 - head/sys/boot/uboot/common X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Dec 2015 22:00:47 -0000 Author: ian Date: Mon Dec 14 22:00:46 2015 New Revision: 292227 URL: https://svnweb.freebsd.org/changeset/base/292227 Log: Enhance the "ubenv import" command to allow importing a u-boot env var directly into a loader (and thus kernel) env var, using the syntax ubenv import ldvarname=ubvarname Without the varname= prefix it uses the historical behavior of importing to the name uboot.ubvarname. Modified: head/sys/boot/uboot/common/main.c Modified: head/sys/boot/uboot/common/main.c ============================================================================== --- head/sys/boot/uboot/common/main.c Mon Dec 14 22:00:07 2015 (r292226) +++ head/sys/boot/uboot/common/main.c Mon Dec 14 22:00:46 2015 (r292227) @@ -573,17 +573,41 @@ enum ubenv_action { static void handle_uboot_env_var(enum ubenv_action action, const char * var) { - const char * val; - char ubv[128]; + char ldvar[128]; + const char *val; + char *wrk; + int len; + + /* + * On an import with the variable name formatted as ldname=ubname, + * import the uboot variable ubname into the loader variable ldname, + * otherwise the historical behavior is to import to uboot.ubname. + */ + if (action == UBENV_IMPORT) { + len = strcspn(var, "="); + if (var[len] == 0) { + strcpy(ldvar, "uboot."); + strncat(ldvar, var, sizeof(ldvar) - 7); + } else { + len = MIN(len, sizeof(ldvar) - 1); + strncpy(ldvar, var, len); + ldvar[len] = 0; + var = &var[len + 1]; + } + } /* * If the user prepended "uboot." (which is how they usually see these * names) strip it off as a convenience. */ if (strncmp(var, "uboot.", 6) == 0) { - snprintf(ubv, sizeof(ubv), "%s", &var[6]); - var = ubv; + var = &var[6]; } + + /* If ldvar is malformed or there's no variable name left, punt. */ + if (ldvar[0] == 0 || var[0] == 0) + return; + val = ub_env_get(var); if (action == UBENV_SHOW) { if (val == NULL) @@ -592,8 +616,7 @@ handle_uboot_env_var(enum ubenv_action a printf("uboot.%s=%s\n", var, val); } else if (action == UBENV_IMPORT) { if (val != NULL) { - snprintf(ubv, sizeof(ubv), "uboot.%s", var); - setenv(ubv, val, 1); + setenv(ldvar, val, 1); } } }