From patchwork Tue May 10 12:45:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josua Mayer X-Patchwork-Id: 620617 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r3zXc42dmz9t45 for ; Tue, 10 May 2016 22:46:56 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0730-0001rc-RN; Tue, 10 May 2016 12:45:58 +0000 Received: from mailgw1.uni-kl.de ([2001:638:208:120::220]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b072y-0001Z3-4q for lede-dev@lists.infradead.org; Tue, 10 May 2016 12:45:56 +0000 Received: from linux-k8dt.fritz.box (x4db1d26d.dyn.telefonica.de [77.177.210.109]) (authenticated bits=0) by mailgw1.uni-kl.de (8.14.4/8.14.4/Debian-8) with ESMTP id u4ACjWnJ018896 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 10 May 2016 14:45:33 +0200 From: josua.mayer97@gmail.com To: lede-dev@lists.infradead.org Date: Tue, 10 May 2016 14:45:32 +0200 Message-Id: <1462884332-3653-1-git-send-email-josua.mayer97@gmail.com> X-Mailer: git-send-email 2.6.6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160510_054556_409874_C9BAA64B X-CRM114-Status: GOOD ( 15.81 ) X-Spam-Score: -2.4 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [2001:638:208:120:0:0:0:220 listed in] [list.dnswl.org] 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (josua.mayer97[at]gmail.com) 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (josua.mayer97[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.9 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list Subject: [LEDE-DEV] [PATCH v2] mount_root: implement overlay= boot option X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: josua.mayer97@gmail.com MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Josua Mayer This change adds code to handle a new option on cmdline: overlay= This is used to find the rootfs_data partition / disk when it has a non-standard name or location. It takes either the device node name, or the partition name: i.e. /dev/mmcblk0p3, mmcblk0p3, rootfs_data This option has precedence over the default name "rootfs_data", and extroot. Signed-off-by: Josua Mayer . --- libfstools/ext4.c | 4 +-- mount_root.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 4 deletions(-) diff --git a/libfstools/ext4.c b/libfstools/ext4.c index f648aa8..2c6dd91 100644 --- a/libfstools/ext4.c +++ b/libfstools/ext4.c @@ -77,8 +77,8 @@ ext4_part_match(char *dev, char *name, char *filename) strcpy(devname, buf + strlen("DEVNAME=")); continue; } - /* Match partition name */ - if (strstr(buf, name)) { + /* Match either partition name or device node name */ + if (strstr(buf, name) || strstr(devname, name)) { ret = 0; break; } diff --git a/mount_root.c b/mount_root.c index 47a3409..9bc3356 100644 --- a/mount_root.c +++ b/mount_root.c @@ -28,11 +28,56 @@ static int start(int argc, char *argv[1]) { struct volume *root; - struct volume *data = volume_find("rootfs_data"); + struct volume *data = NULL; if (!getenv("PREINIT")) return -1; + /* + * Check cmdline for a hint about overlay device + * e.g. /dev/mmcblk0p3 + */ + { + FILE *fp; + struct stat fs = {0}; + char *buffer; + + fp = fopen("/proc/cmdline", "r"); + fstat(fileno(fp), &fs); + buffer = calloc(1, fs.st_size+1); + while (!feof(fp)) { + if(fscanf(fp, "overlay=%s", buffer)) + break; + + fseek(fp, 1, SEEK_CUR); + } + fclose(fp); + + /* + * If an overlay= argument was found, look for a volume with that name + */ + if (buffer[0]) { + /* + * strip /dev/ prefix if any + */ + int offset = 0; + if (strstr(buffer, "/dev/")) + offset = 5; + + ULOG_NOTE("Looking for overlay device given on commandline\n"); + data = volume_find(buffer + offset); + } + free(buffer); + } + + /* + * Look for default rootfs_data partition name + */ + data = volume_find("rootfs_data"); + + /* + * In case rootfs_data doesn't exist, only mount /dev/root for now + */ if (!data) { root = volume_find("rootfs"); volume_init(root); @@ -95,8 +140,49 @@ stop(int argc, char *argv[1]) static int done(int argc, char *argv[1]) { - struct volume *v = volume_find("rootfs_data"); + struct volume *v = NULL; + FILE *fp; + struct stat fs = {0}; + char *buffer; + /* + * First check if there is an overlay device hint in cmdline + */ + fp = fopen("/proc/cmdline", "r"); + fstat(fileno(fp), &fs); + buffer = calloc(1, fs.st_size+1); + while (!feof(fp)) { + if (fscanf(fp, "overlay=%s", buffer)) + break; + + fseek(fp, 1, SEEK_CUR); + } + fclose(fp); + + /* + * If an overlay= argument was found, look for a volume with that name + */ + if (buffer[0]) { + /* + * strip /dev/ prefix if any + */ + int offset = 0; + if (strstr(buffer, "/dev/")) + offset = 5; + + v = volume_find(buffer + offset); + } + free(buffer); + + /* + * Now look for standard overlay partition name + */ + if (!v) + v = volume_find("rootfs_data"); + + /* + * If no overlay device exists, then there is nothing to do here + */ if (!v) return -1;