From patchwork Thu Nov 1 17:06:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 992016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::440; helo=mail-wr1-x440.google.com; envelope-from=swupdate+bncbcxploxj6ikrbjpf5tpakgqebthyxci@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="B32KTSWD"; dkim-atps=neutral Received: from mail-wr1-x440.google.com (mail-wr1-x440.google.com [IPv6:2a00:1450:4864:20::440]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42mBSn0k4kz9sRc for ; Fri, 2 Nov 2018 04:06:48 +1100 (AEDT) Received: by mail-wr1-x440.google.com with SMTP id u8-v6sf16139976wrn.17 for ; Thu, 01 Nov 2018 10:06:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1541092006; cv=pass; d=google.com; s=arc-20160816; b=EH3XdlZpaNa8EycBwYexHaaS6gsOyKc/OnbYhRVw3TM7kiXYRDlnpCGVazTgrmQxEg iyVWt2EGSR8EOhPhhHBHO9NhzmSTgu8VFZ0W2Z2UzCtPzbVlzRFqE29N20DVKEFzBdQq 8r0sR3Mz5UNPatFAD4F/Li8WBMFoEmLlFfi4EMuzf25LbaPqIIXrjTSiknwlVyDPYUJx 7Bbc6eg30wGyuUav3Dhk+GyZKg+LymaqCSpPYVMkg9QLeEMKPk/n6mIhxM9VJDPSMlr7 B6Efzjdu2PxiIC4Jtz2OqJtYbXz+ES5Omfn8SCi7Pq/8/OWZmWSDVEgKcc9kZN2PiAZj o5Vw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:message-id:date:subject:cc:to:from :mime-version:sender:dkim-signature; bh=G8B56IZ6ftvjZVTuWXXUzlJTQ2/PbmZ/uJjVElc/Dz8=; b=qQKxQCsSCp4WA9sXHGMvh5J+S8tNiXqtTF48rbEW+kXF2nVfpAGHlYtPyYanX+qr34 U3RG1ZZtuo9ZQXvfviSX5AlFUDf6oTbmOXZy+9tZOASuuP7WYWyogSEgnx/A5SdRcjOS zmJQeZoWp9mgkdo4zXFcRS6Z3XWRuH0LsxyMk1+b6PHXyrhApVg7cURVZ0hdtQO8fSJw sqpcmKd3Td/gbfE2gfFv38A07ojtCTasYiXpo1SfrM2jmBS1pPuX5sgkF+CkOWKez3GC 1lGhE5rDlwF+GHD2ZNjUOdwSK5DuMWrXtNoefncIVOOw2iTh4CPCAE6EslZ1ZcMXvqzV qClw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=G8B56IZ6ftvjZVTuWXXUzlJTQ2/PbmZ/uJjVElc/Dz8=; b=B32KTSWDGNgwmpLRzLWVUGc9cRGYCLs41moEeqqbeYwf5RIRqZDFojPuNgywbrAjDP qCydpkph9bCWpZG7OtiQHICTjDjavY/XxuaOpxszfAf2yF1Muk0828o/zhQL7owGJmOp F7wdim/ZaT0LdYBynNfg0GsAP2IVsfXcF5tXGP+scd9K5QB2NWbt18fWZ3EfBHZ2plPA 7PaA80Yk7Ah8h0we59XUTUAKrw0CscItDrc/KM7dZuvANuro+zbdRA1dkvAatlV3l8Vc 5XHmVuWe/EJ4SxmC0HE+Rs5iIMY2m7V+6QEWK3AERkFaJMVLoUG0AhgbXGz1MCf4zwGL DbLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=G8B56IZ6ftvjZVTuWXXUzlJTQ2/PbmZ/uJjVElc/Dz8=; b=l3S/RUMmbAEN+PM4I8z/dltnEdAuqCENVkEeGd3mkNaPQjVHzjOhVyFFFlZnZN94fi 7FH2nMqAGpi6MSqgs9LSQyQoigaXeh1V8UUIbc2reekh3aVexmDR6tymKC/JIZSCGWbH QMGSzzhZxHJI+uRxsxaPcaazI5/PpTlWMhYh1olryOaDumkV+g936O5HHoSu4YNzQZLP NAQ+rawtRJ756vd4d6BmaSgcM0W8usc1pl3A9OblBaGg7Y+YczfjTqyl75hH5xkPkFVh YRwvw1OLUT64qq5dkSaj4tdMl0qyVRlXpxzvxOsYYIdqmXnbeTOBy+wwfK6gPWHIZlQt 7ppg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gI11XzGz4sgNiq3PU8cv9iLRCIv1Y3cUmvd7pgjwyckwdYv6bsf GUIQTZU+cRRaagDtnbwfTVE= X-Google-Smtp-Source: AJdET5dMb3/ShWEWgQvxs83T114awiADCgsvZpzs/awdA+XpFaNtuDtLb7BXWzChHS88BCDBk40R4Q== X-Received: by 2002:a5d:5288:: with SMTP id c8-v6mr94627wrv.4.1541092005857; Thu, 01 Nov 2018 10:06:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a5d:45c5:: with SMTP id b5-v6ls3786520wrs.2.gmail; Thu, 01 Nov 2018 10:06:45 -0700 (PDT) X-Received: by 2002:adf:e351:: with SMTP id n17-v6mr825060wrj.16.1541092005336; Thu, 01 Nov 2018 10:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541092005; cv=none; d=google.com; s=arc-20160816; b=rBB/hgICQMyeXgJQ5jS3DBkHlRf6D47Z493szBZRYe8FMmP8Ay0+IjLlAsUq2Lv0Qk Mj/lC1WR51IjBGRea+DAIqeJ0AcUwM5FndK0yfy+a7aqsKPhLdmjLBplD4EplQGLkypt Wst+IfiRkyIpEpPJbR34QEDY/0EG63Rj7N3UHV6zmjRJhtRgomGiXX9Nh149RYcLgPTP Iu2LV6NkXPIOSEBcf7SFWFj8OzG2+Y52DaPl0k3CzjIgfejftlJLWpFszmxyX/HI7xk4 GXYAzmkYou3cBZoZzYCtMNJuj+s75KTO2GVfp3rOFarbgFae/Y3EMlrs02yvuK6QXU6Q xt/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=eIzLQtx5qpvCit5sv05EumvgVRRYC1mNMl20fzMzkfA=; b=swjciETBmlpVyrHmoSkRsglmtAfqQ7dN7PMwXquyMrNX24QHT7dj4l2jeW4q8nvvPT zbOiKIBB4wpa3s5JmrwgOB1niJsoEljGrxp3McmBpdNRO5gk0ZcyssKiFWBsZEiXyvRV gnGuQDhUrzA8iw/VYujG6zmBlLvrgmpxHawizTm5+/VsgQFVA+HoWW4c3RtYSlqrNMeq UD0O4wwybUlsTkESemJqbWDBsINxh+B0r+NHuPVQ4bWFAX3jN75FHw9cScJCWOBVYm6e BCTk5NuHTiSjpu8RJayScVCviGXCRSQfugXY66rqS5GWrYvmgvl/c8CwSyYD2jSJ3Hnn HLCQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id h137-v6si792778wmd.1.2018.11.01.10.06.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 10:06:45 -0700 (PDT) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42mBSj0xKPz1qxK6; Thu, 1 Nov 2018 18:06:45 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42mBSj0lXnz1qsJN; Thu, 1 Nov 2018 18:06:45 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id pkSsQg-UTgJO; Thu, 1 Nov 2018 18:06:44 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Thu, 1 Nov 2018 18:06:43 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 71ED34540489; Thu, 1 Nov 2018 18:06:43 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v_mP0Fa8XC2R; Thu, 1 Nov 2018 18:06:41 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 0940C4540360; Thu, 1 Nov 2018 18:06:40 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 1/5] Factorize function to count elements in array of strings Date: Thu, 1 Nov 2018 18:06:31 +0100 Message-Id: <20181101170635.13493-1-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Signed-off-by: Stefano Babic --- core/util.c | 16 ++++++++++++++++ include/util.h | 1 + 2 files changed, 17 insertions(+) diff --git a/core/util.c b/core/util.c index 15d38b7..a357ea3 100644 --- a/core/util.c +++ b/core/util.c @@ -481,6 +481,22 @@ char** string_split(const char* in, const char d) return result; } +/* + * Count number of elements in an array of strings + * Last item must have a NULL terminator + */ +unsigned int count_string_array(const char **nodes) +{ + const char **iter = nodes; + int count = 0; + + while (*iter != NULL) { + iter++; + count++; + } + return count; +} + unsigned long long ustrtoull(const char *cp, unsigned int base) { errno = 0; diff --git a/include/util.h b/include/util.h index 06f4a83..0a95967 100644 --- a/include/util.h +++ b/include/util.h @@ -179,6 +179,7 @@ void get_sw_versions(char *cfgfname, struct swupdate_cfg *sw); __u64 version_to_number(const char *version_string); int check_hw_compatibility(struct swupdate_cfg *cfg); int count_elem_list(struct imglist *list); +unsigned int count_string_array(const char **nodes); /* Decryption key functions */ int load_decryption_key(char *fname); From patchwork Thu Nov 1 17:06:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 992017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13d; helo=mail-lf1-x13d.google.com; envelope-from=swupdate+bncbcxploxj6ikrbkhf5tpakgqejxdu2yi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="Otb0dHyy"; dkim-atps=neutral Received: from mail-lf1-x13d.google.com (mail-lf1-x13d.google.com [IPv6:2a00:1450:4864:20::13d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42mBSq2SRnz9sRc for ; Fri, 2 Nov 2018 04:06:51 +1100 (AEDT) Received: by mail-lf1-x13d.google.com with SMTP id o34sf1376423lfg.19 for ; Thu, 01 Nov 2018 10:06:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1541092008; cv=pass; d=google.com; s=arc-20160816; b=RiqdPTPd+QenTDDOujj+1EG/n91LcgOJJXtqSwQ2alNeq36/a+dDdgpW9FldVoJAwQ TrVaFfhS+GU2oXvcI1Rcp4cOt8bXzo6n8FAtzTkG5VQeIzqkemHc9W880EPMlYT1HYhD s2FREA1Cx7m3HpLhxaG5PZ4hjK7P/zYhzxqGhEl0NhQ3Aet4UYq4FuOSda1NFjXD9Ge7 yQv/Md5jKaPH/mPHWknju7JexPNm/ZgwhVTe7NNZGeQfZ4zjcYA8v08HPiaL0GTDR/7e G5O9wT9GMa4sILzlP9xK2eqrKxKGUprjqhpcQL79nwgK3uSEjAhNGEPps7+dRkFoMRK9 MNvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:mime-version:sender:dkim-signature; bh=RDPetkawNj7Iq//XL8zOD3gdEIfCV1BGxud6xDOUwgY=; b=uyJf2xF9Ux4bbELDY9lpYglgA9cFPVurr/dmSMCdfWd+jw/Oy/saIQq0poD0CIGvm0 mJyLJ3H+cQoR16lH+xGCyuXr4FyEeTd8bPWjWbYVRPSPBDz0H/at+S9eDBjAJiRP24nT Klh54IB78PU6YdZgtop7hTWoVK5lJs6xzGoswkYK3qRLTBbp9iXdDnpjYcp9ycqQjLmi sf7HAo5XUv3du08xjf+OGasK+yPWmRvvCrqSxK3XaKhQatFhIX69DIrXEpeJJpZO4Aly XT9I5pEA4wuXYyChcVPW3WPm8oJxgvpF6zCASEXwmp8M3Zbw97Ww7T0sTt949iwE8Se2 hlRA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=RDPetkawNj7Iq//XL8zOD3gdEIfCV1BGxud6xDOUwgY=; b=Otb0dHyyuYP98z83Bb8UJ9dtk35X7Yi0iuNaW4YERHSa5uCIYHCO8V9dMWW3wl6Ih1 UltvrdajJf7g5/YWf2cvklJlnncDGbPTT10JTB2L/FrmrlU5uFxAtpQaGRZF7HBgffuw tEr2HQqMZbrZPNQHXyREag2WGPDFwJMYTLjmZyToGGfGiR1oCmgyza1wrz6yIcPGGaJ3 EgY3/YvjjlIWJEeNGeG0P2SKhs7EUlqpVK9e849pHXzX6mZUuic/udoeWxmtLOB34uYU aewXay0PvYDIyFvDSQkq/EYtLKtvspFOsnV+bMOJ+tWpPOfNznyQDiRby76pnl3QbDbu m3sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=RDPetkawNj7Iq//XL8zOD3gdEIfCV1BGxud6xDOUwgY=; b=Z00O1KfVVGrrIsbfgDPG6imQpkZu0B0ty4bM289YXkXjWLQX6BTl75B2BlY3IsALpn WMbGeMJMLHMBnoDpoLSk5rCpVe0lxN2YcGcslPuqWhOhKr6UQWuoENdUtat1g2wJUWuP A8fyAr4Kw9/oQuwlFjao+5xwUIpZNlbkIQ7Ad9+vklJ3knn3Ph5T68tGmFMPrJUqZZXF FO1iOo3EWMWEF6Ly/d28nGMsQaXfNOTmyiT8aD2MlY0kUDyeklpZI+4mE2rUSQyj2uJL UDqr9fotzlt07mCv5jPpnjZOG/1ikE6Ij061obHXS/z2osNmqlPfCyLd7Vsd0BsG4tLD yEbw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gInoIQ+bHTB1mrGnQ2D9rY56unY6Tmd3sdzqnKjiaugiAUGa6bz qBky4novol4TRCMvklvl8F8= X-Google-Smtp-Source: AJdET5eqK7YZamrmKgLtMIOuHFZOpqhOxpyGOG+hjXG5x0boEAm7s2jFa9FSpZWuh4whwJpm/Ao/sw== X-Received: by 2002:a2e:93c5:: with SMTP id p5-v6mr48575ljh.7.1541092008431; Thu, 01 Nov 2018 10:06:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:700b:: with SMTP id l11-v6ls2028398ljc.19.gmail; Thu, 01 Nov 2018 10:06:47 -0700 (PDT) X-Received: by 2002:a2e:9597:: with SMTP id w23-v6mr205997ljh.25.1541092007887; Thu, 01 Nov 2018 10:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541092007; cv=none; d=google.com; s=arc-20160816; b=FdaREFTwCLLMIS+NREre2CPQG1VIQs+O428Ff8VkeORGzxkKQh02VrHfCgrBNgCa6C Eedu7oXEgvqwSlh/jaylxFLWEAdz3uFW3vv6gvejlrKGbXxaRMFk4K4lpFaGz01mk4+F AQytKTAL8z5uGRbGHLgTP1a6+2Y9262J/54nHm70+luOwSj7aHc/dCDXK8ToYwa+R1O5 2V5hoeci3yXfj9yc06CGIYGtheWvExAcIIWfhkG4HnjoL4YqNdsWwPx3LvGv96LZpQYy nXYGmhZqTvmCvBjag0fwmp2HH66iCf1jSw2WrlzVR0GbaWfiUhwtUcpSkjoPKsdkG/f3 9BMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=o++6yjSbjRWvCuyanK5XIrty9GLql9AI7FtnTmqdBn4=; b=RDOLl6FC2fCkRtmGOuWKnVhJKrkhOuFpuKq+TOvYZQK9LS0WpOEgK2PrBcO6uk4URA utHVocy3a7X5fRElaiVnnpBsdtDa4uSXsaUJowudkzMDb5iZhGUrWIS2PjDvVCNMUvSE wVP/5Xni17kH+vPvySsMk08WOB6W8KqdvphpjnmdnEPqN1koFfK0nN69ThF/0Mn4aOOj 3Ah8uY38xupC9Ge8XfeyWHfn1Uutj+t+zRrDrnp2fyCV6mpSBteX8JRQwWEUG71XyW4I YLkyQB201zAeK2aPJkmwcNX7jpo+iGkC21K+T6/dbFahzkIdZ7QCw9vQQotsHosCsU3n Spig== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id a79-v6si967009ljf.1.2018.11.01.10.06.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 10:06:47 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42mBSl2FtXz1qvwR; Thu, 1 Nov 2018 18:06:47 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42mBSl28fyz1qsJP; Thu, 1 Nov 2018 18:06:47 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 9A9wSKK7RwqK; Thu, 1 Nov 2018 18:06:46 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Thu, 1 Nov 2018 18:06:46 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 012DD4540360; Thu, 1 Nov 2018 18:06:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tfFDeZ7VFenD; Thu, 1 Nov 2018 18:06:43 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 487C4454046A; Thu, 1 Nov 2018 18:06:41 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 3/5] parser: function to get a new path of a node Date: Thu, 1 Nov 2018 18:06:33 +0100 Message-Id: <20181101170635.13493-3-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181101170635.13493-1-sbabic@denx.de> References: <20181101170635.13493-1-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Using links, the path to a node must be computed again. The function set_find_path() get the string pointed to the link and modify the array of strings containing the whole path to a node. A convention is used to traverse the tree upwards. If the string begins with "..", this means to go up in the tree. Multiple leading ".." are allowed to go up into the tree. Signed-off-by: Stefano Babic --- corelib/parsing_library.c | 56 +++++++++++++++++++++++++++++++++++++++ include/parselib.h | 10 +++++++ 2 files changed, 66 insertions(+) diff --git a/corelib/parsing_library.c b/corelib/parsing_library.c index e9739fe..00463a7 100644 --- a/corelib/parsing_library.c +++ b/corelib/parsing_library.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "generated/autoconf.h" #include "bsdqueue.h" @@ -19,6 +20,8 @@ #include "swupdate.h" #include "parselib.h" +#define MAX_LINKS_DEPTH 10 + void check_field_string(const char *src, char *dst, const size_t max_len) { assert(max_len>0); @@ -159,3 +162,56 @@ void get_hash_value(parsertype p, void *elem, unsigned char *hash) ascii_to_hash(hash, hash_ascii); } + +bool set_find_path(const char **nodes, const char *newpath, char **tmp) +{ + unsigned int nleading; + char **iter, **paths; + unsigned int count = count_string_array(nodes); + unsigned int countpaths; + + if (!newpath) + return false; + + /* + * Check if we have to traverse back + */ + for (nleading = 0; newpath[nleading] == '.'; nleading++); + + /* + * delimiter at the beginning indicates a relative path + * exactly as in Unix, that mean .. for the upper directory + * .. = parent + * .... = parent of parent + * The number of leading "." must be even, else + * it is a malformed path + */ + if (nleading % 2) + return false; + + nleading /= 2; + if ((count - nleading) <= 0) + return false; + + count -= nleading; + if (count > 0) count--; + + paths = string_split(newpath, '.'); + + /* + * check if there is enough space in nodes + */ + countpaths = count_string_array((const char **)paths); + if (count + countpaths >= MAX_PARSED_NODES) + return false; + if (!countpaths) + nodes[count++] = newpath; + else + for (iter = paths; *iter != NULL; iter++, count++) + nodes[count] = *iter; + nodes[count] = NULL; + + tmp = paths; + + return true; +} diff --git a/include/parselib.h b/include/parselib.h index f53dd00..2fca3b5 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -9,6 +9,7 @@ #define _PARSE_LIBRARY_H #include +#include typedef enum { LIBCFG_PARSER, @@ -18,6 +19,12 @@ typedef enum { typedef void (*iterate_callback)(const char *name, const char *value, void *data); +/* + * This is to limit the structure (array) used to save the whole + * path to the entry to be read. + */ +#define MAX_PARSED_NODES 20 + #ifdef CONFIG_LIBCONFIG #include #define LIBCONFIG_VERSION ((LIBCONFIG_VER_MAJOR << 16) | \ @@ -83,6 +90,9 @@ void get_field(parsertype p, void *e, const char *path, void *dest); int exist_field_string(parsertype p, void *e, const char *path); void get_hash_value(parsertype p, void *elem, unsigned char *hash); void check_field_string(const char *src, char *dst, const size_t max_len); +bool find_root(parsertype p, void *root, const char **nodes); +void *get_node(parsertype p, void *root, const char **nodes); +bool set_find_path(const char **nodes, const char *newpath, char **tmp); #define GET_FIELD_STRING(p, e, name, d) \ get_field_string_with_size(p, e, name, d, sizeof(d)) From patchwork Thu Nov 1 17:06:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 992018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::440; helo=mail-wr1-x440.google.com; envelope-from=swupdate+bncbcxploxj6ikrbkpf5tpakgqe3prysoq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="ouF4sFNk"; dkim-atps=neutral Received: from mail-wr1-x440.google.com (mail-wr1-x440.google.com [IPv6:2a00:1450:4864:20::440]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42mBSr0SBYz9sSG for ; Fri, 2 Nov 2018 04:06:51 +1100 (AEDT) Received: by mail-wr1-x440.google.com with SMTP id e11-v6sf16753436wrr.14 for ; Thu, 01 Nov 2018 10:06:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1541092009; cv=pass; d=google.com; s=arc-20160816; b=u/boMjKfzky4mQ4/v034XEY+u0Dafs5hhuPEsfOLqnjohVgnKJUjv5MmovZUvGWCEs 5Ny4Dm+5z6TGBA+ZiN3+sOKTPfMnk+JX0U2ohQ3UoYuljvfkcsIy9GfEnyP9qCaqEy1b ysZn89cYtw9h2vIm3jI4EmlbUqWrIInG3wi+ebELGSiz3I0PWbH82TkaT7L9YPvTwdPZ 5VvQg4Wrz8GcfC4kl0nEBv2jRKoTEuLZBzc68HfCkDkkCwp17dpUaC8spwBjCcL7VphK KhAdzT1y68JG3NXkzLA2gjCH0o8jnbeW5E5dY8DIdChq8hqRRHBNQCbGilxWRl7h3+Oj kPsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:mime-version:sender:dkim-signature; bh=l5nzoNXDGxNFwfsHWfreHAUPSU7eyxsYZChfwbQhwQM=; b=pURbg5QW2/0DWXsqyBwVnjV0Ufw62N6qBQO82nVfh0q8vmA19WhtTf8UddNGKQkRrj A9u2IYC8+YSHRdr7V5b4yWqBQk+T3eXRm08URQGecszOSCWHqaZqQQcy0/5ANcT5AiVA 0zC2EmOGKtQwD8BZ1mCR5uzmoQIXw2FK5OG8bbhsDm98eFmEFDp0yvahMoq6hkT2nTZ+ oOoa+ojyP5XFzoZ9CQRmE0Iiw9yBEr9MFLeEL917xMLRTl3cDrJYddBu8A4TPNMNJU02 5jXKMq1JNUoV2MgwzDBaNLCGnXeGX5zv5A8D6DIAR0diN1LmhzaJKBoMGF7i8zq1Nl7v pvBw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=l5nzoNXDGxNFwfsHWfreHAUPSU7eyxsYZChfwbQhwQM=; b=ouF4sFNkawizA+1UH6O0B/EcWrgBF2B6q1JxHIqksQiO7OGSd9viqbFVeldE8qgjQE 0Fj0v3AEQzgB91+Q14+4/Xi8H9uD1TWVmPstY9luQqsXhOM9NoSJdp4SEh2jhOPG3pao SQJlwnl3SDneCUAu0Meaw3Ey8b8jPw5HJ/Wl21OqGJT+BSxX8WObrSyayak8d/W3PSdj hS40Zpb7WXN1EEP+UifBc1suniL/ZRLUmVQ89LxM8FRB8SNovE2MO58pR+MI9rdW0gYn Z6gEwUJac/cgLdpnWuXTk3PyJ9gYU26WoqO6T+HEOLaDYc0Q7q/0MwfudoMQCYyN/2qZ JIIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=l5nzoNXDGxNFwfsHWfreHAUPSU7eyxsYZChfwbQhwQM=; b=KjYfdgna7arQVv5asxy+HuGAguYigvjWeiv6O95CJKKHUMpp9SjYsWkP18cdS3P+ax nXa6OqhCSqL+T3Jer0bWHmpppDasvkWJD3O9TlxzPK3Mw+FdmzH03L5afJgR+23MN3rb URshoBVzjME3sugTVMhopALKQLNDG5Kgu+5EoPh5PHRxx0dGvrJJ9Hj+4d8V452ONQ3a ujbkoSGLjPcWwwdA45dlgpt02H2Rz6ovvc0R+BDtVrrcQ+XxviyYP69RR9zBvzqspxEG MDKXVtK49NZGyZiiiEzhhNtAxj5zFxsXuLDhH6FX04lpnBR1lb3rL1L0XnFcy05w0a5u weqA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gIX2F6sIRHY4oQTtePR5lffSYgMS6DAYFpVKzYvBukF7vysRMEa xuL7HrrswkY3+CAoC0/0aJc= X-Google-Smtp-Source: AJdET5dG/yBbju9UH52up19jlrz7nXqHvHkvtinuqaxvuKmRt1Mxhqq23efflgmvtZOSiKv9kKRH3A== X-Received: by 2002:adf:fb8a:: with SMTP id a10-v6mr103139wrr.1.1541092009713; Thu, 01 Nov 2018 10:06:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a5d:45c5:: with SMTP id b5-v6ls3786549wrs.2.gmail; Thu, 01 Nov 2018 10:06:49 -0700 (PDT) X-Received: by 2002:adf:f989:: with SMTP id f9-v6mr877998wrr.0.1541092009377; Thu, 01 Nov 2018 10:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541092009; cv=none; d=google.com; s=arc-20160816; b=VMHWVcweRTV8qWVqxQT7EuU37xSWZa7XvLpyxyG1zll0e94uw0WSsEm/5X5NHk6PYU tf7Y3fMOURfSYfZbS/4+wUVjafEK+lEs8FUYtJ07emIxewqVXOovWAw+rqm3115E+OLo BZBBbt/qnOWGSqAFpeWXO6ZOUyariIX0mFaOlv7gYP8LD007DA3jK2FPODzxIiTDL2zw t96OMNTvMa/RXOM6xyaeTcyVOajG8eVjq8gaI6QB8wNL2A6g114osg14G172V3eSM6kt j7Ju9TtRyMvP6MQzNcfmlPrzCHsT4y6y134pIaF567BRAhBzkNdLkBK2FXnL01iLiAJr GJxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=47Q3jjStESitB0RiVLTFOO26zvCtRrKsfye44KXapUw=; b=gN6uLOGF1Eyuqd1ozEF5tjKU1Lle5dSUe7P+JjJQSNFgd8iwl1QfOSCy+KaAdeG0s7 Y4O2ECLTd2kXERvytKJ72gGzORKCqzkGv+y2DnapK/pWMeh/5nzuCKu1m8Tr3tExdCPY MZ40uHpW/taJi9MANpgw7Sa3BfdANhXSK2Y134geHgpohfNID0/y5QqoVDCrXQqm8Xge CjZ9c4MM20ddXP1E/0c7AAZIT3cfHi9zPqbimVg+CRfsjyF15PK2kTjqsRkTBbmiCx1o YC6kpaDQu4VBRKQEln7EnN5ui/185VV78bkOx4XVUbvo/YJU3oqf6C08rQjmxjJGVOSD kD9Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id u13-v6si806176wrn.3.2018.11.01.10.06.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 10:06:49 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42mBSn1GvJz1qvwR; Thu, 1 Nov 2018 18:06:49 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42mBSn12pyz1qsJP; Thu, 1 Nov 2018 18:06:49 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id MYr8diTBXzLM; Thu, 1 Nov 2018 18:06:47 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Thu, 1 Nov 2018 18:06:47 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 159584540452; Thu, 1 Nov 2018 18:06:47 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id anoMA0-OolYf; Thu, 1 Nov 2018 18:06:44 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 6F08D454047E; Thu, 1 Nov 2018 18:06:41 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 4/5] parser: introduce links in sw-description Date: Thu, 1 Nov 2018 18:06:34 +0100 Message-Id: <20181101170635.13493-4-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181101170635.13493-1-sbabic@denx.de> References: <20181101170635.13493-1-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , There are a lot of use cases when special configurations are needed. Current sw-description requires that each entry is full described and does not allow to factorize some parts. This means that in most cases entries are duplicated multiple times even if changes are minimal between sections. This patch introduce links for the root node. If the node is a string instead of an object, it is interpreted as new link to be follow. The parser tries to follow the links recursively (a maximum number of 10 links is introduce to avoid deadlocks). The patch factorizes how to call find_node() for the specific parser. Instead of using two mechanism (a formatted sting and an array of strings) for libconfig and json, use an array of strings for both. Signed-off-by: Stefano Babic --- corelib/parsing_library.c | 33 ++++ corelib/parsing_library_libconfig.c | 73 +++++++++ corelib/parsing_library_libjson.c | 44 +++++ include/parselib.h | 8 + parser/parser.c | 242 ++++++++++++++-------------- 5 files changed, 276 insertions(+), 124 deletions(-) diff --git a/corelib/parsing_library.c b/corelib/parsing_library.c index 00463a7..5a8445a 100644 --- a/corelib/parsing_library.c +++ b/corelib/parsing_library.c @@ -153,6 +153,39 @@ int exist_field_string(parsertype p, void *e, const char *path) return 0; } +bool find_root(parsertype p, void *root, const char **nodes) +{ + + switch (p) { + case LIBCFG_PARSER: + return find_root_libconfig((config_t *)root, nodes, MAX_LINKS_DEPTH); + + case JSON_PARSER: + return find_root_json((json_object *)root, nodes, MAX_LINKS_DEPTH); + default: + (void)root; + (void)nodes; + } + + return false; +} + +void *get_node(parsertype p, void *root, const char **nodes) +{ + + switch (p) { + case LIBCFG_PARSER: + return get_node_libconfig((config_t *)root, nodes); + case JSON_PARSER: + return get_node_json((json_object *)root, nodes); + default: + (void)root; + (void)nodes; + } + + return NULL; +} + void get_hash_value(parsertype p, void *elem, unsigned char *hash) { char hash_ascii[80]; diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c index 415116b..5763416 100644 --- a/corelib/parsing_library_libconfig.c +++ b/corelib/parsing_library_libconfig.c @@ -13,12 +13,34 @@ #include #include #include +#include #include "generated/autoconf.h" #include "bsdqueue.h" #include "util.h" #include "swupdate.h" #include "parselib.h" +static void path_libconfig(const char **nodes, char *root, unsigned int rootsize) +{ + const char **node; + int nbytes, left; + char *buf; + const char *concat; + bool first=true; + + root[0] = '\0'; + + for (node = nodes, buf = root, left = rootsize; *node != NULL; node++) { + concat = first ? "" : "."; + nbytes = snprintf(buf, left, "%s%s", concat, *node); + buf += nbytes; + left -= nbytes; + first = false; + if (left ==0) + break; + } +} + void get_value_libconfig(const config_setting_t *e, void *dest) { int type = config_setting_type(e); @@ -108,3 +130,54 @@ const char *get_field_string_libconfig(config_setting_t *e, const char *path) return NULL; } + +void *get_node_libconfig(config_t *cfg, const char **nodes) +{ + config_setting_t *setting; + char root[1024]; + + path_libconfig(nodes, root, sizeof(root)); + setting = config_lookup(cfg, root); + if (setting) + return setting; + + return NULL; +} + +bool find_root_libconfig(config_t *cfg, const char **nodes, unsigned int depth) +{ + config_setting_t *elem; + const char *str; + char root[1024]; + char **tmp = NULL; + bool result = false; + + /* + * check for deadlock links, block recursion + */ + if (!(--depth)) + return false; + + path_libconfig(nodes, root, sizeof(root)); + + /* + * If this is root node for the device, + * it is a group and lenght is not 0. + * If it is a link, follow it + */ + elem = config_lookup(cfg, root); + + if (elem && config_setting_length(elem) > 0) + return true; + + if (!elem || config_setting_type(elem) != CONFIG_TYPE_STRING) + return false; + if ((str = config_setting_get_string(elem)) != NULL) { + if (!set_find_path(nodes, str, tmp)) + return false; + result = find_root_libconfig(cfg, nodes, depth); + free_string_array(tmp); + return result; + } + return false; +} diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c index b1f5775..8cc3a4b 100644 --- a/corelib/parsing_library_libjson.c +++ b/corelib/parsing_library_libjson.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -179,4 +180,47 @@ char *json_get_data_url(json_object *json_root, const char *key) : strndup(json_object_get_string(json_data), MAX_URL_LENGTH); } +bool find_root_json(json_object *root, const char **nodes, unsigned int depth) +{ + json_object *node; + enum json_type type; + char **tmp = NULL; + bool result; + const char *str; + + /* + * check for deadlock links, block recursion + */ + if (!(--depth)) + return false; + + node = find_json_recursive_node(root, nodes); + + if (node) { + type = json_object_get_type(node); + + switch (type) { + case json_type_object: + case json_type_array: + return true; + case json_type_string: + str = json_object_get_string(node); + if (!set_find_path(nodes, str, tmp)) + return false; + result = find_root_json(root, nodes, depth); + free_string_array(tmp); + return result; + default: + return false; + } + } + + return false; +} + +void *get_node_json(json_object *root, const char **nodes) +{ + return find_json_recursive_node(root, nodes); +} + diff --git a/include/parselib.h b/include/parselib.h index 2fca3b5..61ebce9 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -39,6 +39,8 @@ void *get_child_libconfig(void *e, const char *name); void iterate_field_libconfig(config_setting_t *e, iterate_callback cb, void *data); const char *get_field_string_libconfig(config_setting_t *e, const char *path); +bool find_root_libconfig(config_t *cfg, const char **nodes, unsigned int depth); +void *get_node_libconfig(config_t *cfg, const char **nodes); #else #define config_setting_get_elem(a,b) (NULL) @@ -49,6 +51,8 @@ const char *get_field_string_libconfig(config_setting_t *e, const char *path); #define get_child_libconfig(e, name) (NULL) #define iterate_field_libconfig(e, cb, data) { } #define get_field_cfg(e, path, dest) +#define find_root_libconfig(cfg, nodes, depth) (false) +#define get_node_libconfig(cfg, nodes) (NULL) #endif #ifdef CONFIG_JSON @@ -65,6 +69,8 @@ const char *json_get_value(struct json_object *json_root, const char *key); json_object *json_get_path_key(json_object *json_root, const char **json_path); char *json_get_data_url(json_object *json_root, const char *key); +bool find_root_json(json_object *root, const char **nodes, unsigned int depth); +void *get_node_json(json_object *root, const char **nodes); #else #define find_node_json(a, b, c) (NULL) @@ -75,6 +81,8 @@ char *json_get_data_url(json_object *json_root, const char *key); #define json_object_object_get_ex(a,b,c) (0) #define json_object_array_get_idx(a, b) (0) #define json_object_array_length(a) (0) +#define find_root_json(root, nodes, depth) (false) +#define get_node_json(root, nodes) (NULL) #endif typedef int (*settings_callback)(void *elem, void *data); diff --git a/parser/parser.c b/parser/parser.c index 19181d1..4588f5d 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -29,115 +30,136 @@ #define NODEROOT (!strlen(CONFIG_PARSERROOT) ? \ "software" : CONFIG_PARSERROOT) -#ifdef CONFIG_LIBCONFIG -static config_setting_t *find_node_libconfig(config_t *cfg, - const char *field, struct swupdate_cfg *swcfg) +#if defined(CONFIG_LIBCONFIG) || defined(CONFIG_JSON) + +static bool path_append(const char **nodes, const char *field) { - config_setting_t *setting; - struct hw_type *hardware; + unsigned int count = 0; + + count = count_string_array(nodes); + + if (count >= MAX_PARSED_NODES) + return false; + + nodes[count++] = field; + nodes[count] = NULL; - char node[1024]; + return true; +} + +static void *find_node_common(parsertype p, void *root, const char *field, + struct swupdate_cfg *swcfg, bool followlinks) +{ + + struct hw_type *hardware; + const char **nodes; + int i; if (!field) return NULL; hardware = &swcfg->hw; - if (strlen(swcfg->running_mode) && strlen(swcfg->software_set)) { - /* Try with both software set and board name */ - if (strlen(hardware->boardname)) { - snprintf(node, sizeof(node), "%s.%s.%s.%s.%s", - NODEROOT, - hardware->boardname, - swcfg->software_set, - swcfg->running_mode, - field); - setting = config_lookup(cfg, node); - if (setting) - return setting; + nodes = (const char **)calloc(MAX_PARSED_NODES, sizeof(*nodes)); + + for (i = 0; i < 4; i++) { + nodes[0] = NULL; + switch(i) { + case 0: + if (strlen(swcfg->running_mode) && strlen(swcfg->software_set) && + strlen(hardware->boardname)) { + nodes[0] = NODEROOT; + nodes[1] = hardware->boardname; + nodes[2] = swcfg->software_set; + nodes[3] = swcfg->running_mode; + nodes[4] = NULL; + } + break; + case 1: + /* try with software set and mode */ + if (strlen(swcfg->running_mode) && strlen(swcfg->software_set)) { + nodes[0] = NODEROOT; + nodes[1] = swcfg->software_set; + nodes[2] = swcfg->running_mode; + nodes[3] = NULL; + } + break; + case 2: + /* Try with board name */ + if (strlen(hardware->boardname)) { + nodes[0] = NODEROOT; + nodes[1] = hardware->boardname; + nodes[2] = NULL; + } + break; + case 3: + /* Fall back without board entry */ + nodes[0] = NODEROOT; + nodes[1] = NULL; + break; } - /* still here, try with software set and mode */ - snprintf(node, sizeof(node), "%s.%s.%s.%s", - NODEROOT, - swcfg->software_set, - swcfg->running_mode, - field); - setting = config_lookup(cfg, node); - if (setting) - return setting; - } + /* + * If conditions are not set, + * skip to the next option + */ + if (!nodes[0]) + continue; - /* Try with board name */ - if (strlen(hardware->boardname)) { - snprintf(node, sizeof(node), "%s.%s.%s", - NODEROOT, - hardware->boardname, - field); - setting = config_lookup(cfg, node); - if (setting) - return setting; + if (find_root(p, root, nodes)) { + void *node = NULL; + if (!path_append(nodes, field)) + return NULL; + if (!followlinks) { + node = get_node(p, root, nodes); + } else { + if (find_root(p, root, nodes)) + node = get_node(p, root, nodes); + } + + if (node) { + free(nodes); + return node; + } + } } - /* Fall back without board entry */ - snprintf(node, sizeof(node), "%s.%s", - NODEROOT, - field); - return config_lookup(cfg, node); + + free(nodes); + + return NULL; } -#endif +static void *find_node_element(parsertype p, void *root, const char *field, + struct swupdate_cfg *swcfg) +{ + return find_node_common(p, root, field, swcfg, false); +} -#ifdef CONFIG_JSON -static json_object *find_node_json(json_object *root, const char *node, +static void *find_node_group(parsertype p, void *root, const char *field, struct swupdate_cfg *swcfg) { - json_object *jnode = NULL; - const char *simple_nodes[] = {NODEROOT, node, NULL}; - struct hw_type *hardware; + return find_node_common(p, root, field, swcfg, true); +} - hardware = &swcfg->hw; +static bool get_common_fields(parsertype p, void *cfg, struct swupdate_cfg *swcfg) +{ - if (strlen(swcfg->running_mode) && strlen(swcfg->software_set)) { - if (strlen(hardware->boardname)) { - const char *nodes[] = {NODEROOT, hardware->boardname, - swcfg->software_set, swcfg->running_mode, - node, NULL}; - jnode = find_json_recursive_node(root, nodes); - if (jnode) - return jnode; - } else { - const char *nodes[] = {NODEROOT, swcfg->software_set, - swcfg->running_mode, node, NULL}; - jnode = find_json_recursive_node(root, nodes); - if (jnode) - return jnode; - } - } + void *setting; - if (strlen(hardware->boardname)) { - const char *nodes[] = {NODEROOT, hardware->boardname, node, - NULL}; - jnode = find_json_recursive_node(root, nodes); - if (jnode) - return jnode; + if((setting = find_node_element(p, cfg, "version", swcfg)) == NULL) { + ERROR("Missing version in configuration file"); + return false; } + + GET_FIELD_STRING(p, setting, NULL, swcfg->version); + TRACE("Version %s", swcfg->version); - return find_json_recursive_node(root, simple_nodes); -} -#endif - -#if defined(CONFIG_LIBCONFIG) || defined(CONFIG_JSON) -static void *find_node(parsertype p, void *root, const char *node, - struct swupdate_cfg *swcfg) -{ - switch (p) { - case LIBCFG_PARSER: - return find_node_libconfig((config_t *)root, node, swcfg); - case JSON_PARSER: - return find_node_json((json_object *)root, node, swcfg); + if((setting = find_node_element(p, cfg, "description", swcfg)) != NULL) { + GET_FIELD_STRING(p, setting, NULL, swcfg->description); + TRACE("Description %s", swcfg->description); } - return NULL; + return true; } static void add_properties_cb(const char *name, const char *value, void *data) @@ -175,7 +197,7 @@ static int parse_hw_compatibility(parsertype p, void *cfg, struct swupdate_cfg * char s[SWUPDATE_GENERAL_STRING_SIZE]; struct hw_type *hwrev; - setting = find_node(p, cfg, "hardware-compatibility", swcfg); + setting = find_node_element(p, cfg, "hardware-compatibility", swcfg); if (setting == NULL) { ERROR("HW compatibility not found"); return -1; @@ -273,7 +295,7 @@ static int parse_partitions(parsertype p, void *cfg, struct swupdate_cfg *swcfg) int count, i; struct img_type *partition; - setting = find_node(p, cfg, "partitions", swcfg); + setting = find_node_group(p, cfg, "partitions", swcfg); if (setting == NULL) return 0; @@ -330,7 +352,7 @@ static int parse_scripts(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lu int count, i, skip; struct img_type *script; - setting = find_node(p, cfg, "scripts", swcfg); + setting = find_node_group(p, cfg, "scripts", swcfg); if (setting == NULL) return 0; @@ -401,10 +423,10 @@ static int parse_bootloader(parsertype p, void *cfg, struct swupdate_cfg *swcfg) char name[32]; char value[255]; - setting = find_node(p, cfg, "uboot", swcfg); + setting = find_node_group(p, cfg, "uboot", swcfg); if (setting == NULL) { - setting = find_node(p, cfg, "bootenv", swcfg); + setting = find_node_group(p, cfg, "bootenv", swcfg); if (setting == NULL) return 0; } @@ -468,7 +490,7 @@ static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua int count, i, skip; struct img_type *image; - setting = find_node(p, cfg, "images", swcfg); + setting = find_node_group(p, cfg, "images", swcfg); if (setting == NULL) return 0; @@ -550,7 +572,7 @@ static int parse_files(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua_ int count, i, skip; struct img_type *file; - setting = find_node(p, cfg, "files", swcfg); + setting = find_node_group(p, cfg, "files", swcfg); if (setting == NULL) return 0; @@ -625,7 +647,7 @@ static int parser(parsertype p, void *cfg, struct swupdate_cfg *swcfg) int ret; swcfg->embscript = NULL; - scriptnode = find_node(p, cfg, "embedded-script", swcfg); + scriptnode = find_node_element(p, cfg, "embedded-script", swcfg); if (scriptnode) { TRACE("Getting script"); swcfg->embscript = get_field_string(p, scriptnode, NULL); @@ -672,11 +694,8 @@ static int parser(parsertype p, void *cfg, struct swupdate_cfg *swcfg) int parse_cfg (struct swupdate_cfg *swcfg, const char *filename) { config_t cfg; - const char *str; - char node[128]; parsertype p = LIBCFG_PARSER; int ret; - config_setting_t *setting; memset(&cfg, 0, sizeof(cfg)); config_init(&cfg); @@ -694,24 +713,8 @@ int parse_cfg (struct swupdate_cfg *swcfg, const char *filename) return -1; } - if((setting = find_node(p, &cfg, "version", swcfg)) == NULL) { - ERROR("Missing version in configuration file"); + if (!get_common_fields(p, &cfg, swcfg)) return -1; - } else { - GET_FIELD_STRING(p, setting, NULL, swcfg->version); - TRACE("Version %s", swcfg->version); - } - - if((setting = find_node(p, &cfg, "description", swcfg)) != NULL) { - GET_FIELD_STRING(p, setting, NULL, swcfg->description); - TRACE("Description %s", swcfg->description); - } - - snprintf(node, sizeof(node), "%s.embedded-script", - NODEROOT); - if (config_lookup_string(&cfg, node, &str)) { - TRACE("Found Lua Software:\n%s", str); - } ret = parser(p, &cfg, swcfg); @@ -734,7 +737,7 @@ int parse_json(struct swupdate_cfg *swcfg, const char *filename) struct stat stbuf; unsigned int size; char *string; - json_object *cfg, *setting; + json_object *cfg; parsertype p = JSON_PARSER; /* Read the file. If there is an error, report it and exit. */ @@ -764,18 +767,9 @@ int parse_json(struct swupdate_cfg *swcfg, const char *filename) return -1; } - if((setting = find_node(p, cfg, "version", swcfg)) == NULL) { - ERROR("Missing version in configuration file"); + if (!get_common_fields(p, cfg, swcfg)) { free(string); return -1; - } else { - GET_FIELD_STRING(p, setting, NULL, swcfg->version); - TRACE("Version %s", swcfg->version); - } - - if((setting = find_node(p, cfg, "description", swcfg)) != NULL) { - GET_FIELD_STRING(p, setting, NULL, swcfg->description); - TRACE("Description %s", swcfg->description); } ret = parser(p, cfg, swcfg); From patchwork Thu Nov 1 17:06:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 992019 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::440; helo=mail-wr1-x440.google.com; envelope-from=swupdate+bncbcxploxj6ikrbkxf5tpakgqe7hohati@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="B/rUn7wL"; dkim-atps=neutral Received: from mail-wr1-x440.google.com (mail-wr1-x440.google.com [IPv6:2a00:1450:4864:20::440]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42mBSr32vjz9sSj for ; Fri, 2 Nov 2018 04:06:52 +1100 (AEDT) Received: by mail-wr1-x440.google.com with SMTP id v2-v6sf16843675wrn.0 for ; Thu, 01 Nov 2018 10:06:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1541092010; cv=pass; d=google.com; s=arc-20160816; b=YV3vEF/gsCte4o3Qk0VrKK29lM6mY7avMTUDTN+Zs2LqaWr1OWAJev1mba0702M77K QH4BU7+A/F7IsoavnPzR/ILJIWoB5u2Yn1n+PREh2MHtPKMY3/cUg3HrZh5oO4BkxF7d AMxu+CXmwHLSwRrHLouKC5q+X5zETjUsxUKb5Fsbokoh2cBeMsYSjUrnJK/IAU35sAxB eLT4tOsaN0T7GF0HcYmby43qQmKpFGi/FlLjgHWqAXZ4uXpKv2XfusSSSHMJd4/6yajz I5/ePTpE2KAZqfaUQIdEmILR3xV8TUW5UN6z1+agmLHVQ5ttYx65gE8kjAuLvfNlY+RJ uWBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:sender:dkim-signature; bh=2EE0UoI/+Msi22kfRJeDUCeblpFbVNT4Xh/LaMW6+Ew=; b=DBjN7CmdqsGXz7GBq/cmnj2A7+pW9r3QPI9s2bYGk9gSsTzOfaDohC+HzYQBV5XijL WTtdQdIouhwtH5ukR47Swaq+6ZBOFN+5Aob6CLBK+slrnWP1pKQfPvRAxgPBG2VXGKAP NdeZ2IDNkBK7CUIPvWrYG3yaps4GdAcGh2RNwaEZmPZJi3Jm0f1t3SGYeUAQ7O+HBExd XRMFUI2Y2q7HkO7ypfPhTFjt9VWnLaZMLMWVc0EFvaD6HXhxSzeHt6K2qPcvYc47VnVD PFCn4GKuv+2NGznRjiOl0TO8FUn8zrxh8E15GRGOcFbm51tvEdZxrsbDAx0fAqK96Kyo DPTw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=2EE0UoI/+Msi22kfRJeDUCeblpFbVNT4Xh/LaMW6+Ew=; b=B/rUn7wL2CovOBRUcwDTTts3fid6XmA3wz8g+sruXFVcy0XJQuKFsvrF/gWOgZj/gV Wxs5FmCZFV318ihUpFDR/dUsvgLexCYdWQ7B49AmfOnnJgMtntYwb8d/cH2LpDctkMln B/bMEP3vBh5LNZwGvW/3id7X/ebjbv4KfSdd1r8S9iOJIFrLXvNgdZkOeiFh8TSRwPYb 2ag9cHt4gjAEsSrMXVmis9is7pt41K6az6+dcxTofod3qT7t65mFOXWIha4p4/Y+NYj7 p9ryB/qYloAdifMyjnK7aKIPC9O78+tZAQiqmI8usEDmYn0ZYZG2oHjKeygzZUPSysBA Zhhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=2EE0UoI/+Msi22kfRJeDUCeblpFbVNT4Xh/LaMW6+Ew=; b=ChVwMdn4U8WlquovxHgo+KGhCBCtO/8ByoKvy5s3EuHUN0OHTs3/Ssn8RJxkYe8BAD 1+E9MUURPwlfRZrF1ODaLDMz1BDRKaoLoHxo1UUM6x3oGPUAtZddLzBU+VthVR+kttTL 9LR4LiZCtmHOnc1k5pKwXxOunMxImUnmXLHF2+pfmYe0mMCL0XFOKnWd4sIn5yi05KC8 MGPS+hErOO1neBucmRr37PWCE5hIjz0OSh6fAQzRZCK9dTEY8b/ipJok1rHmbuqbkMi5 hHm8+VO5qNr8Lm7JcHZzrsQL+uQ5V+Edc6tQKTvb7K5AK6E1GxPSPJjT0fihNJih97Od Jn4w== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gKm+aaBZB9SczpHMBwXuHGlI0+6mxg+MezMoMOqfgrFzpuNR41F pXJn32jvTBAWi3lgjQNU/jc= X-Google-Smtp-Source: AJdET5egYIaYYws7nksJi/fBzcbqd5VRBiCrHlzyycb2k7RA6wfklbj8FyDUQG+h6MtAr691MYbXag== X-Received: by 2002:adf:b3d1:: with SMTP id x17-v6mr98893wrd.5.1541092010260; Thu, 01 Nov 2018 10:06:50 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a1c:9956:: with SMTP id b83-v6ls210367wme.20.canary-gmail; Thu, 01 Nov 2018 10:06:49 -0700 (PDT) X-Received: by 2002:a1c:6702:: with SMTP id b2-v6mr883139wmc.2.1541092009823; Thu, 01 Nov 2018 10:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541092009; cv=none; d=google.com; s=arc-20160816; b=ffPC4QZsTfNuYXzhgZHnXrfZdDAGSrHvYQ/4AZ4ZC5XuES4iSHf2wWYYnrfqSCOHMt 6Z4JnEPh/2Nu/Zl3Nyrkk6ZhiUWgY/VnLW0IQj+CM0f4rUPwn98Pme0OaPFG8PeuDIdm a1HJpDtY93wSaSIpBjoBuYJjlxgzG8lr38sALB5ADil9v9pr3wsr7gUv+qRADxptEzF/ P/1Ic8eWU8t+goUfC4NFODiu+mGCjerYktD17J8f9vOBSrcGb/Bj9qxeUJyPoMiYMMoZ nCzqo9Xoa/e7yZr1dKFX9x+VH5mjBY0XTUYGVaGoXaoTNpW489bXujmaybMWVGQ9DMy1 pfqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=U++LeMDBt8fcJ0NXXVBldmFQnNG/J2UzB2DygJC20u4=; b=wN3YmeRCGxRBKoVuK4Kl74BtfciaS7MMkE2l6+JJuWDGVFKGyh1rrRt93Ocgbqwgz+ bqbgBK1oyN3S5BC6NChbYx0fM8gWJfoHo2vRKDxzHUYDs0bb9ZFy/uxFluqFoNrrm2dn zovEnFWVJhP/SDuAvybPdTwothWmJIMiLVOXNMvY4WsWgYg8tJ+jYrlCfy4Cue33xW3P oxpZfjxbcS8WOKFo2FBIn7FG/l6iHbDCOcRaqNO58+QKqZgIUJk9nIOcjDBqdXWOJdsX DG+Rv6Yr9iIkY7njQ8uX0zfIPFBtTzXbX7mlVO2+edcSOUbQhemVDmNmReFtlhA1Zfwc VakA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id 191-v6si209660wmv.0.2018.11.01.10.06.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 10:06:49 -0700 (PDT) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42mBSn4MhDz1qxK6; Thu, 1 Nov 2018 18:06:49 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42mBSn3sNrz1qsJP; Thu, 1 Nov 2018 18:06:49 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id ZHwDDi_Vsi01; Thu, 1 Nov 2018 18:06:48 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Thu, 1 Nov 2018 18:06:48 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 48D234540360; Thu, 1 Nov 2018 18:06:48 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u4NutyVmlw1b; Thu, 1 Nov 2018 18:06:46 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 9299A4540483; Thu, 1 Nov 2018 18:06:41 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 5/5] doc: describes links in sw-description Date: Thu, 1 Nov 2018 18:06:35 +0100 Message-Id: <20181101170635.13493-5-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181101170635.13493-1-sbabic@denx.de> References: <20181101170635.13493-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Signed-off-by: Stefano Babic --- doc/source/sw-description.rst | 255 ++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index ec32e8e..cd28a38 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -251,6 +251,261 @@ other slot. The method of image selection is out of the scope of SWUpdate and user is responsible for calling `SWUpdate` passing proper settings. +Priority finding the elements in the file +----------------------------------------- + +SWUpdate search for entries in the sdw-description file according to the following priority: + +1. Try ... +2. Try .. +3. Try . +4. Try + +Take an example. The following sw-description describes the release for a set of boards. + +:: + + software = + { + version = "0.1.0"; + + myboard = { + stable = { + copy-1: { + images: ( + { + device = "/dev/mtd4" + ... + } + ); + } + copy-2: { + images: ( + { + device = "/dev/mtd5" + ... + } + ); + } + } + } + + stable = { + copy-1: { + images: ( + { + device = "/dev/mtd6" + ... + } + ); + } + copy-2: { + images: ( + { + device = "/dev/mtd7" + ... + } + ); + } + } + } + +On *myboard*, SWUpdate searches and find myboard.stable.copy1(2). When running on different +boards, SWUpdate does not find an enty corresponding to the boardname and it fallbacks to the +version without boardname. This lets relalize the same release for different boards having +a complete different hardware. `myboard` could have a eMMC and an ext4 filesystem, +while another device can have raw flash and install an UBI filesystem. Nevertheless, they are +both just a different format of the same release and they could be described together in sw-description. +It is important to understand the priorities how SWUpdate scans for entries during the parsing. + +Using links +----------- + +sw-description can become very complex. Let's think to have just one board, but in multiple +hw revision and they differ in Hardware. Some of them can be grouped together, some of them +require a dedicated section. A way (but not the only one !) could be to add *mode* and selects +the section with `-e stable,`. + +:: + + software = + { + version = "0.1.0"; + + myboard = { + stable = { + + hardware-compatibility: ["1.0", "1.2", "2.0", "1.ยง, "3.0", "3.1"]; + rev-1.0: { + images: ( + ... + ); + scripts: ( + ... + ); + } + rev-1.2: { + hardware-compatibility: ["1.2"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + rev-2.0: { + hardware-compatibility: ["2.0"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + rev-1.3: { + hardware-compatibility: ["1.3"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + + rev-3.0: + { + hardware-compatibility: ["3.0"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + rev-3.1: + { + hardware-compatibility: ["3.1"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + } + } + } + +If each of them requires an own section, it is the way to do. Anyway, it is more probable +than revisions can be grouped together, for example board with the same major revision +number could have the same installation instructions. This leads in the example to 3 groups +for rev1.X, rev2.X and rev3.X. Links allow to group section together. When a string is found +when SWUpdate searches for a group (images, files, script, bootenv), it replaces the current path +in the tree with the value of the string. In this way, the example above can be written in this way: + +:: + + software = + { + version = "0.1.0"; + + myboard = { + stable = { + + hardware-compatibility: ["1.0", "1.2", "2.0", "1.3, "3.0", "3.1"]; + rev-1x: { + images: ( + ... + ); + scripts: ( + ... + ); + } + rev1.0 = "rev-1x"; + rev1.2 = "rev-1x"; + rev1.3 = "rev-1x"; + rev-2x: { + images: ( + ... + ); + scripts: ( + ... + ); + } + rev2.0 = "rev-2x"; + + rev-3x: + { + images: ( + ... + ); + scripts: ( + ... + ); + } + rev3.0 = "rev-3x"; + rev3.1 = "rev-3x"; + } + } + } + +The link can be absolute or relative. A relative path has a number of +leading ".." to move the current cursor to the parent leaf of the tree. +In the following example, rev40 sets a link to a "common" section, where `images` +is found. This is sets via a link, too, to a section in the parent node. +The path `software.myboard.stable.common.images` is then replaced by +`software.myboard.stable.trythis` + +:: + + software = + { + version = "1.0"; /* Release Version */ + + hardware-compatibility =["rev10","rev11", "rev20"]; + + myboard:{ + stable:{ + + common: { + images = "..trythis"; + uboot:( + { + name = "bootpart"; value = "2:1"; + } + ); + }; + + trythis: ( + { + filename = "rootfs.ext5"; + device = "/dev/mmcblk0p8"; + } + ); + rev10: + { + images:( + { + filename = "rootfs.ext3"; + device = "/dev/mmcblk0p2"; + } + ); + uboot:( + { + name = "bootpart"; value = "0:2"; + } + ); + }; + rev11 = "rev10"; + rev20 = "rev10"; + rev40 = "common"; + }; + }; + } + + + + hardware-compatibility ----------------------