From patchwork Fri Apr 19 06:33:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 1925404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=OlENslCP; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TsvaWLQ3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::339; helo=mail-wm1-x339.google.com; envelope-from=swupdate+bncbdnyr2ftvyebb5e5rcyqmgqezlw647q@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-wm1-x339.google.com (mail-wm1-x339.google.com [IPv6:2a00:1450:4864:20::339]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VLPpg3h1Sz1yP2 for ; Fri, 19 Apr 2024 16:28:10 +1000 (AEST) Received: by mail-wm1-x339.google.com with SMTP id 5b1f17b1804b1-41634d6c008sf8087095e9.1 for ; Thu, 18 Apr 2024 23:28:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713508086; cv=pass; d=google.com; s=arc-20160816; b=ZQwssXU5Y4QTSU1kRbxMdtXOjIpFQdQBMjG4c7CxumvzpM9w0RXEYRzru0vJuakKTH iOpm7luB3U4Bcmx1y8wff4QhyFFWwTLAqJYFS1Bb8rLHvYgnfOA0RM7fX/hpk/RKJdyG VjTGCKOQN1PU4/oTyuoWYfzIO+Igvv5KFYtorahMAWg/wmJBnYin2qxxPuNEhxtrlfoc 45JDD8YnPglSvCtTSAWS1stEvZk9O8g2PZ09h2pKGZP1axTSozUPXFRw36V7lV01Pxa/ dfMR3y6ml581JQf+k6dSRYx9rjpK8R9qgSsVBv1qSBkAlle9eOLU0YiPqswLSSYd8/7F Z73Q== 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:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature:dkim-signature; bh=E+oopvzp1ZRAI2VTQSHoMld4TGGyTCHmDZV22092u5M=; fh=ZFToYcKqbyZe11obVOpMMXlJ1PfID+9GSYejLoVdXe4=; b=MY56tftKkxuiHW9np8jK2IW46Ro7kk52OhEy5z03BuCz72aaFKZno1288x4tH6KoSK A32Mw7KW9lIK5LjA7FppyzPkUemxO96m5eJ7yLv5nhcatWEcNWaYp6iWJqFC3Rd7rDJ+ LFzgMV+KGVO6y0rciGRSdaDZtrgycFb6kiqkXGMCx1GTectX81u2mjsuhtREdMeb2bz0 7HE//IIi7cuddfUOS+RItJCkAJyFgFiPR0YGy/nIJGu4TQefVkV8Mc9D+qw7bfv99H9Q t4DEvyZov5wGQRYgAu4266D8ei+TjqDeMglY0piDKjW6CC9Rconxu97TUncavxYbInQx FdaA==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Tk3y1bse; spf=pass (google.com: domain of marcus.folkesson@gmail.com designates 2a00:1450:4864:20::135 as permitted sender) smtp.mailfrom=marcus.folkesson@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1713508086; x=1714112886; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=E+oopvzp1ZRAI2VTQSHoMld4TGGyTCHmDZV22092u5M=; b=OlENslCP5gUetWU5GTykVs9rrnxUn8XGViRQy8PZ+0EEw0i45dXtJHEh4KeQ2kXNGX OaHu+jWA9EXlrguraYeXQaAk1LAIFG+dC+nXsNH5d5WMsid1cfyqvry9/Wn3VilKT7cs g99+ZFwBqyhBmt8sSnWh+Wqtldw0/oJx8bUjiO+jRy/8PQeeU7JeRHJRl1w8Fyu6+93D YG1AZZMQDEIG18u6xbmu0r72rWouEj0TGRwL42LuPGayx6FbENOKvBT3m8OXfOKX/7pr QSVHM6uv+yxAZpa2zGBNIotFQdrLmKK1a1gtH2kR6ACxBfOPrSTQh7I+JBH8X8CSu9Rm s2RA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713508086; x=1714112886; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=E+oopvzp1ZRAI2VTQSHoMld4TGGyTCHmDZV22092u5M=; b=TsvaWLQ3xP5wtnw64RfHv672RxeLS99SzdmBnnQoLk8C7J/IYxpw7YsUiw8k8RAxe+ 0ikK80c6VHEJzTwg0koCpufwyKV0UdWDxY9TJ+/uWvIYN12zuhBLYXrlFyboxhvGgBYy DWwy5ycVB4VWBQm5vF5r/7ApA2QvprxNYC36Al2Vu/us4z9E5CmP7/yB6UZ8cebUexPU WpFjncN1pPwN9mNUFh0xq4U1km8j5DBJ3vmsKd0DIeHfFuYTMYi1jDLvV5b6+LuV5XRW T9dhX4fsEPDDDyR1lxVOr9OcyMPgHTV7S/VvNhHcBb/00rMll2Qh1RU08pbUAX02Il09 7RwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713508086; x=1714112886; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=E+oopvzp1ZRAI2VTQSHoMld4TGGyTCHmDZV22092u5M=; b=KZzkPi9oUzCW5NYrFnrfnATyhhCDCSKSsxC+fW+Tv5MneWx48pHN+EQxOT+sYI61oY nz5+AA6pXvzmP+dYE9Nv8wPxEt2rtTxIfsPazzP5kqotV9yogxqi6HtST4yP27h91eJW waJxtfrRSfDy7q2Q5DDC8Jw83bK1C5u0vRkcbJAzXzguaEuesnOCQ5wC8FV/OUqiX4tP BDgW5CswpH1vgmuMZL9ZwA8td+NAHv9ck49k41Xz82da/5Bptf7ehHIMDhpbre9fp0O9 jQZlr+VZad6WN2aImt6d8ijA2ghcGHVpmmkIF/xtD9DInSwqeMdwQYCO86MnkTWT2UvB OSeA== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCV0BdB2NOQbXw31sPu5SCsTW8N3YM3cMAQPpXDyIVEGe0PhPKnQyWegMIy5Z/tTiqU+bvnCKEJmw3eDLqY/YqpJzQ23N/ZEaBQ2TmE3lA== X-Gm-Message-State: AOJu0YxbGGYubCSGMKQUJKIT02ry/a/rKd2vZkYTBqxhXCq+YIM8R8Xi k/m0S3puh/AKYUIehhiejtJKZv/9FdXMNZ89enMlrIYCL7INZWpP X-Google-Smtp-Source: AGHT+IHjRUn4dv3bLtFs3eeVsupt/NCbugL1cO85I+q6XrqkwEOb2ecmZEhYvDMlp8uybbEc/fRFPA== X-Received: by 2002:a05:600c:35d0:b0:418:c424:e88a with SMTP id r16-20020a05600c35d000b00418c424e88amr974645wmq.26.1713508085583; Thu, 18 Apr 2024 23:28:05 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:600c:1c27:b0:416:8040:cca4 with SMTP id 5b1f17b1804b1-418ff34a0f0ls3109395e9.2.-pod-prod-08-eu; Thu, 18 Apr 2024 23:28:03 -0700 (PDT) X-Received: by 2002:a05:600c:1c06:b0:418:d68d:f21b with SMTP id j6-20020a05600c1c0600b00418d68df21bmr918016wms.32.1713508082650; Thu, 18 Apr 2024 23:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713508082; cv=none; d=google.com; s=arc-20160816; b=N3tWM8I9dHYccFQxlYNqIwWpDE88inyuOwSR8fLd80maBRm8CXXRLfY30hdi0dghdw bfzFYuRcBZo6ecNfqKwSHyxwj/hEvefMCUH6s2rck8i6u2ns3G0q/qThPRViVA8lH4jV lXbLAoJraiPW99OE1TDnaYow90yHl3IHAtQQdi++eX/LtM4KKzvF+etdQ+Uxgk02hkRd AHkIqhSNGLNGm2M7pP17K0fAwJLUr/rXXmzpA0AGtbSDgcDlzWGb27JJ/PpWT2OS8mcU c1O9B4ZXyyI3YX1EAHkCmX80EmaSfSZNzGMrOn8qNdtXmIy1IBIv1UUQrLVlg66eH2mh VpyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=6wzUrV1DcKdle96oSsI0OzAWSW+C5Hwh1ZuiRH5WeF8=; fh=byqoZYyGIF5nyUrxbqMCSaBgugTQ0N3rC9IbdDbCkgM=; b=zaZcaw41txfr8XYgmd8kjFExon34eAg3V8oWCCt021+xwdTygC6ESVV8IwrGkjiQWh Hs6/N653G8nG+awzK2ZrlTPpV0i42cWBtS9ibLjHJalDlTM4L0PQMdaH7TcIqm1ACIKx q+gh8RO0hzlhwNcaOgXlFMeD6CGkNQ9OW5auBuyRWzQewbQ0PeXZj/77kpPJUQ8bDLBi 0L/fvd8u7OiPejA4GnjIsBhJJ+8KZs1Vvq7+s5pGhnrf6nRH4xiZwQh5jHm+82nT+SJE Ni0PQdKCPLMzFUDgqyiuCeII1Tn3FaX6bB+CsXdZ52eoLaiEe0mB5qsYqdi8ZfD2VG1M fNtQ==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Tk3y1bse; spf=pass (google.com: domain of marcus.folkesson@gmail.com designates 2a00:1450:4864:20::135 as permitted sender) smtp.mailfrom=marcus.folkesson@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com. [2a00:1450:4864:20::135]) by gmr-mx.google.com with ESMTPS id j26-20020a05600c1c1a00b00418de43ed00si344672wms.0.2024.04.18.23.28.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Apr 2024 23:28:02 -0700 (PDT) Received-SPF: pass (google.com: domain of marcus.folkesson@gmail.com designates 2a00:1450:4864:20::135 as permitted sender) client-ip=2a00:1450:4864:20::135; Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-51acb95b892so51809e87.2 for ; Thu, 18 Apr 2024 23:28:02 -0700 (PDT) X-Received: by 2002:ac2:483b:0:b0:518:d6ea:9f5d with SMTP id 27-20020ac2483b000000b00518d6ea9f5dmr947878lft.42.1713508081351; Thu, 18 Apr 2024 23:28:01 -0700 (PDT) Received: from localhost.localdomain (83-233-6-197.cust.bredband2.com. [83.233.6.197]) by smtp.gmail.com with ESMTPSA id s5-20020ac24645000000b0051886ba808bsm561978lfo.186.2024.04.18.23.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 23:28:00 -0700 (PDT) From: Marcus Folkesson To: swupdate@googlegroups.com Cc: marcus.folkesson@gmail.com Subject: [swupdate] [PATCH 1/2] Introduce --gen-swversions parameter Date: Fri, 19 Apr 2024 08:33:10 +0200 Message-ID: <20240419063311.601172-1-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Original-Sender: Marcus.Folkesson@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Tk3y1bse; spf=pass (google.com: domain of marcus.folkesson@gmail.com designates 2a00:1450:4864:20::135 as permitted sender) smtp.mailfrom=marcus.folkesson@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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: , After a successful update, --gen-swversions generates a file with the installed software and their versions. The file is compatible with CONFIG_SW_VERSIONS_FILE and could replace that file if the end user want swupdate to maintain that file entirely. Signed-off-by: Marcus Folkesson --- core/installer.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ core/swupdate.c | 7 ++++- include/swupdate.h | 1 + 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/core/installer.c b/core/installer.c index 48c7fe5e..83122388 100644 --- a/core/installer.c +++ b/core/installer.c @@ -187,6 +187,24 @@ static int prepare_var_script(struct dict *dict, const char *script) return 0; } +static int generate_swversions(struct swupdate_cfg *cfg) +{ + FILE *fp; + struct sw_version *swver; + struct swver *sw_ver_list = &cfg->installed_sw_list; + + fp = fopen(cfg->output_swversions, "w"); + if (!fp) + return -EACCES; + + LIST_FOREACH(swver, sw_ver_list, next) { + fprintf(fp, "%s\t\t%s\n", swver->name, swver->version); + } + fclose(fp); + + return 0; +} + static int update_bootloader_env(struct swupdate_cfg *cfg, const char *script) { int ret = 0; @@ -279,6 +297,41 @@ int install_single_image(struct img_type *img, bool dry_run) return ret; } +static int update_installed_image_version(struct swver *sw_ver_list, + struct img_type *img) +{ + struct sw_version *swver; + struct sw_version *swcomp; + + if (!sw_ver_list) + return false; + + LIST_FOREACH(swver, sw_ver_list, next) { + /* + * If component is already installed, update the version + */ + if (!strncmp(img->id.name, swver->name, sizeof(img->id.name))) { + strncpy(swver->version, img->id.version, sizeof(img->id.version)); + return true; + } + } + + /* + * No previous version of this component is installed. Create a new entry. + */ + swcomp = (struct sw_version *)calloc(1, sizeof(struct sw_version)); + if (!swcomp) { + ERROR("Could not create new version entry."); + return false; + } + + strlcpy(swcomp->name, img->id.name, sizeof(swcomp->name)); + strlcpy(swcomp->version, img->id.version, sizeof(swcomp->version)); + LIST_INSERT_HEAD(sw_ver_list, swcomp, next); + + return true; +} + /* * streamfd: file descriptor if it is required to extract * images from the stream (update from file) @@ -370,6 +423,8 @@ int install_images(struct swupdate_cfg *sw) close(img->fdin); + update_installed_image_version(&sw->installed_sw_list, img); + if (dropimg) free_image(img); @@ -409,6 +464,15 @@ int install_images(struct swupdate_cfg *sw) ret |= run_prepost_scripts(&sw->bootscripts, POSTINSTALL); + /* + * Should we generate a list with installed software? + */ + if (strlen(sw->output_swversions)) { + if (!generate_swversions(sw)) { + ERROR("%s cannot be opened", sw->output_swversions); + } + } + return ret; } diff --git a/core/swupdate.c b/core/swupdate.c index a421e888..5cfec3d6 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -111,6 +111,7 @@ static struct option long_options[] = { {"no-state-marker", no_argument, NULL, 'm'}, {"no-transaction-marker", no_argument, NULL, 'M'}, {"output", required_argument, NULL, 'o'}, + {"gen-swversions", required_argument, NULL, 's'}, {"preupdate", required_argument, NULL, 'P'}, {"postupdate", required_argument, NULL, 'p'}, {"select", required_argument, NULL, 'e'}, @@ -173,6 +174,7 @@ static void usage(char *programname) " -M, --no-transaction-marker : disable setting bootloader transaction marker\n" " -m, --no-state-marker : disable setting update state in bootloader\n" " -o, --output : saves the incoming stream\n" + " -s, --gen-swversions : generate sw-versions file after successful installation\n" " -v, --verbose : be verbose, set maximum loglevel\n" " --version : print SWUpdate version and exit\n" #ifdef CONFIG_HW_COMPATIBILITY @@ -475,7 +477,7 @@ int main(int argc, char **argv) #endif memset(main_options, 0, sizeof(main_options)); memset(image_url, 0, sizeof(image_url)); - strcpy(main_options, "vhni:e:gq:l:Lcf:p:P:o:N:R:MmB:"); + strcpy(main_options, "vhni:e:gq:l:Lcf:p:P:o:s:N:R:MmB:"); #ifdef CONFIG_MTD strcat(main_options, "b:"); #endif @@ -623,6 +625,9 @@ int main(int argc, char **argv) case 'o': strlcpy(swcfg.output, optarg, sizeof(swcfg.output)); break; + case 's': + strlcpy(swcfg.output_swversions, optarg, sizeof(swcfg.output_swversions)); + break; case 'B': if (set_bootloader(optarg) != 0) { ERROR("Bootloader interface '%s' could not be initialized.", optarg); diff --git a/include/swupdate.h b/include/swupdate.h index e18de8d3..ecad2d82 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -49,6 +49,7 @@ struct swupdate_cfg { bool bootloader_transaction_marker; bool bootloader_state_marker; char output[SWUPDATE_GENERAL_STRING_SIZE]; + char output_swversions[SWUPDATE_GENERAL_STRING_SIZE]; char publickeyfname[SWUPDATE_GENERAL_STRING_SIZE]; char aeskeyfname[SWUPDATE_GENERAL_STRING_SIZE]; char postupdatecmd[SWUPDATE_GENERAL_STRING_SIZE];