From patchwork Fri Jan 12 16:40:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 860043 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=2607:f8b0:4001:c06::23c; helo=mail-io0-x23c.google.com; envelope-from=swupdate+bncbcxploxj6ikrb36j4pjakgqeodihq2q@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="T6pd/WYK"; dkim-atps=neutral Received: from mail-io0-x23c.google.com (mail-io0-x23c.google.com [IPv6:2607:f8b0:4001:c06::23c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zJ7lQ0BClz9sPk for ; Sat, 13 Jan 2018 03:40:17 +1100 (AEDT) Received: by mail-io0-x23c.google.com with SMTP id m4sf5072245iob.16 for ; Fri, 12 Jan 2018 08:40:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1515775216; cv=pass; d=google.com; s=arc-20160816; b=zYK//AErsdM0db3nkmHFbNXhnWiwRIWxi1JQHCRBqek1sVvS6Fh1L4Nhr0bI5lT82h YdE4Ecz4rhd4qWGmsTnsSXgbdBeWf5WRZveg5KYyasFJfvHVWKZX8Ea+6qkJvVuIk8Go Yh7C0ovkVRrk2BGnAESrR6E4CSIBJImznlGG8C8ssGAIbGZcA+Wa0kIDkGBxyTRSN7vL BBBHUGrjPteSYSKBA5ueC1zxpIcjrPhJZ3hmL+M5s/AF0IT7PM36dXiNnRHUtTHF2vb2 wL4SLhLQbNgW781gDGrBBiDbsbCRzpJHL338t6PdWVIBMLGKVZXt0iogTSwG8SGuKNjp M88g== 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 :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=sUxdigPyCLG+WvnrhAyWhJ8voAnrjRaDK/y9vRFx/PA=; b=eQDV4HANO6U8TuVvHvJ7lJCNHbnVPO33V4O+vThgGcsvnrxM/1HdrFtCKywcCnFPNS pq3FdtyYe4JmrwhaiymZblcEn128ayNP8oS6MfCNLDL0eiyjrkEPIlS1PRM7BWaY/cWr BF7KxWH18IMqEEd3xqhxXy1Mo3WBiYHjhXoSwf2mInyKMK34+8nixfELE43LAeUTW0gK lKIkPpz9ztdw8sP1UOgT7M+lBtv1X92fexA9fNgU7ZAVmWDj4aryc1q9dyqlrGhtykps EnXxC57rfkWOof2Ss1s552I4udp44+D6tv//zpnfGLCBiP50syvXp0KgvgL0u7c7kuzK xwow== 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=sUxdigPyCLG+WvnrhAyWhJ8voAnrjRaDK/y9vRFx/PA=; b=T6pd/WYKXN06GLPQ4XruwWVmfdz04DqrXs7wC4CfqPV4yip6Nvy02O22j4qgoi8hni m+1ECATzMjx4KZeJr/v36hVVH63ViFBC41lUHIKMmPKdBAoPVf4P26L3PDn2D7gmzU+o o1lij7oHeBeXUAxFsjdUePv4LCczgNMlyuedWIA3l1ksTlESh9J63BziE8rwRik3+YGf VepkoLED4woyCi9sUlp7sJ+P1+8kTOAYIjoVnNN54N/CjVMykp2ReCasc3m7jWN1Qk4O Il+XDAIED34cxTN1U1xbG0z5mqvWJEtqnzqbn3G77mB08Bmev6/LrFeDvR8HWDhJVPuI 6BSw== 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=sUxdigPyCLG+WvnrhAyWhJ8voAnrjRaDK/y9vRFx/PA=; b=pvSmMfzV5is3PqWYoueZaiHSn7pBXSEvlVk5Kpu8kl4rsoEDPKD8zo2wD7M3iYIChi ggBdCUlfD1aO04D7bkdBHsNiN3xZMqeyQ/BY3fyPfUzpVP3enwfw4NpUlEcGl6GT5Fye cWul6872Xx6U4qAgBHgHV5RfvCh3CSsl8tKocF6A+yE+Fhpu/vXzEbaNahwCtkzh69JH YaIbPKCm+koOqB1Z3YAt60sEiYVCPOxNZ338JuQSllAz+ja4g3tjpwvMbEJhfb6wc8nQ /f+bdP0zDqyxGfnv1biCQqtnsabjrpUZpQPKSgKKmifPzWfqgGzFneuQmARrRC8pjG3F 0bdA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytc+6PUAAC8bMvwGUUnF67IeU0OKyja/4gT1f5RpDOT0NVVvprIY Y1f+31Jl4Ll9Fmg52AnnLhQ= X-Google-Smtp-Source: ACJfBovsA7Z3H1rJZj8DbgE/0Z3x7/EnbIlS6s8u+5KR3iasbbDcrrqZWleEF50JPgKf8to5x4/V9Q== X-Received: by 10.36.179.67 with SMTP id z3mr81311iti.7.1515775216027; Fri, 12 Jan 2018 08:40:16 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.98.156.195 with SMTP id u64ls486722pfk.2.gmail; Fri, 12 Jan 2018 08:40:15 -0800 (PST) X-Received: by 10.101.75.207 with SMTP id p15mr6589694pgr.175.1515775215255; Fri, 12 Jan 2018 08:40:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515775215; cv=none; d=google.com; s=arc-20160816; b=hZFF51OBSaWpjdItl3O5yYIp8bI83I4lKAIagK/L80I2nmGfoj+u8QXJKDQRX2fxDM UvR5bJROjYKK9B9xGSboWqssuucpuPsR6hVHC9N7dVOPe2IkixkBHZwM3l0kEDUAr3RJ 2gvzKXZCFuUu6cieSD8Hv+Tr44sfyZ87YRoAZ/9VKrEkD230lOgfIFGVTzYLpPD1JMrx 92CmQkMi1vhe7NIBGZ/jbScNMqVan32Qsjz/P+wQJeNCecchmSqZflm4ra3NjMPmmgWe mSrqLUetWgXRiaX8gXhGQSKH56SwJB0G+JnFfM/boI0ewpS7/hTZPe5zXyuG3PwmcGZH kBVQ== 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:arc-authentication-results; bh=zx4M+S0gGfhIpOA6gvt+XiysLz9HpDDcEBq7XkoHKM0=; b=yuEVtqS1S0O6yEHLn+pc0sYcIcfBxs2YbxaaajxQ8AImoeP4kd1ppBRqr0m8vcGbso inEJGVcXD7PKrFv2BJESV+fMF3FGsjMhKa3q+dSrXd2ChYyrTRhT/QMWBrUm0PaDEf4l HoLPGWNoB/Rx/H2KpjqwDLU7kf1Z3Mv1Gt6ttw1ezgp7GRUhZg3qxg7Nh+P89iNVgSOz AwQRHCAPoVY93bTzKXXfV21FvpHldQvZxVHUh2JfjCdjdbZyH2HoN63bJs/0ODvoaf/S 3fC7nYyJyL62hqt30ZiLQWX5HpNJA5Bd+PZJOT0UXRV7Lw/RKRuk88J+Tlb9Mu4JAwiv BSDg== 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 e92si110873pld.1.2018.01.12.08.40.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 08:40:15 -0800 (PST) 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 3zJ7lK1wbvz1qymb; Fri, 12 Jan 2018 17:40:13 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3zJ7lK1lmbz1qqkg; Fri, 12 Jan 2018 17:40:13 +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 eEXjA99Tla_X; Fri, 12 Jan 2018 17:40:12 +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; Fri, 12 Jan 2018 17:40:12 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id AAF754540360; Fri, 12 Jan 2018 17:40:11 +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 pT5tWEag4wsT; Fri, 12 Jan 2018 17:40:08 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 0D3084540100; Fri, 12 Jan 2018 17:40:07 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 1/2] Allow again bootloader scripts Date: Fri, 12 Jan 2018 17:40:05 +0100 Message-Id: <1515775206-9174-1-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 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: , commit ff12cd69445c0f49d44ad0b75dea6f6ec1b0e449 forbids to use a bootloader script in the "images" section of sw-description. This avoids to set bootloader's variables in the middle of an installation that can brick the device. However, having a script is often much more comfortable as a list of couple inside sw-description. This allows again to have bootloader scripts, but they must be inserted in the "bootenv" section of sw-description. Signed-off-by: Stefano Babic --- core/parser.c | 2 + corelib/installer.c | 108 +++++++++++++++++++++++++++++---------------- corelib/stream_interface.c | 24 ++++++++-- include/installer.h | 1 - include/swupdate.h | 1 + parser/parser.c | 44 +++++++++++++----- 6 files changed, 126 insertions(+), 54 deletions(-) diff --git a/core/parser.c b/core/parser.c index a1232bd..cdfbea8 100644 --- a/core/parser.c +++ b/core/parser.c @@ -147,6 +147,8 @@ int parse(struct swupdate_cfg *sw, const char *descfile) "images / files"); ret |= check_handler_list(&sw->partitions, PARTITION_HANDLER, "partitions"); + ret |= check_handler_list(&sw->bootscripts, BOOTLOADER_HANDLER, + "bootloader"); if (ret) return -EINVAL; diff --git a/corelib/installer.c b/corelib/installer.c index fc3011e..9a67399 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -233,6 +233,27 @@ static int prepare_boot_script(struct swupdate_cfg *cfg, const char *script) return ret; } +static int run_prepost_scripts(struct imglist *list, script_fn type) +{ + int ret; + struct img_type *img; + struct installer_handler *hnd; + + /* Scripts must be run before installing images */ + LIST_FOREACH(img, list, next) { + if (!img->is_script) + continue; + hnd = find_handler(img); + if (hnd) { + ret = hnd->installer(img, &type); + if (ret) + return ret; + } + } + + return 0; +} + static int update_bootloader_env(void) { int ret = 0; @@ -291,13 +312,14 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile) /* Extract all scripts, preinstall scripts must be run now */ const char* tmpdir_scripts = get_tmpdirscripts(); ret = extract_scripts(fdsw, &sw->scripts, fromfile); + ret |= extract_scripts(fdsw, &sw->bootscripts, fromfile); if (ret) { ERROR("extracting script to %s failed", tmpdir_scripts); return ret; } /* Scripts must be run before installing images */ - ret = run_prepost_scripts(sw, PREINSTALL); + ret = run_prepost_scripts(&sw->scripts, PREINSTALL); if (ret) { ERROR("execute preinstall scripts failed"); return ret; @@ -388,7 +410,7 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile) } - ret = run_prepost_scripts(sw, POSTINSTALL); + ret = run_prepost_scripts(&sw->scripts, POSTINSTALL); if (ret) { ERROR("execute postinstall scripts failed"); return ret; @@ -397,31 +419,11 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile) if (!LIST_EMPTY(&sw->bootloader)) ret = update_bootloader_env(); - return ret; -} - -int run_prepost_scripts(struct swupdate_cfg *sw, script_fn type) -{ - int ret; - struct img_type *img; - struct installer_handler *hnd; - - /* Scripts must be run before installing images */ - LIST_FOREACH(img, &sw->scripts, next) { - if (!img->is_script) - continue; - hnd = find_handler(img); - if (hnd) { - ret = hnd->installer(img, &type); - if (ret) - return ret; - } - } + ret |= run_prepost_scripts(&sw->bootscripts, POSTINSTALL); - return 0; + return ret; } - static void remove_sw_file(char __attribute__ ((__unused__)) *fname) { #ifndef CONFIG_NOCLEANUP @@ -430,11 +432,42 @@ static void remove_sw_file(char __attribute__ ((__unused__)) *fname) #endif } +static void cleaup_img_entry(struct img_type *img) +{ + char *fn; + int i; + const char *tmp; + + if (img->fname[0]) { + + for (i = 0; i < 2; i++) { + switch(i) { + case 0: + tmp = get_tmpdirscripts(); + break; + case 1: + tmp = get_tmpdir(); + break; + } + + if (asprintf(&fn, "%s%s", tmp, img->fname) == ENOMEM_ASPRINTF) { + ERROR("Path too long: %s%s", tmp, img->fname); + } else { + remove_sw_file(fn); + free(fn); + } + } + } + dict_drop_db(&img->properties); +} + void cleanup_files(struct swupdate_cfg *software) { char fn[64]; struct img_type *img; struct hw_type *hw; const char* TMPDIR = get_tmpdir(); + int count; + struct imglist *list; LIST_FOREACH(img, &software->images, next) { if (img->fname[0]) { @@ -447,22 +480,19 @@ void cleanup_files(struct swupdate_cfg *software) { LIST_REMOVE(img, next); free(img); } - LIST_FOREACH(img, &software->scripts, next) { - if (img->fname[0]) { - if (snprintf(fn, sizeof(fn), "%s%s", get_tmpdirscripts(), - img->fname) >= (int)sizeof(fn)) { - ERROR("Path too long: %s%s", get_tmpdirscripts(), img->fname); - } - remove_sw_file(fn); - if (snprintf(fn, sizeof(fn), "%s%s", get_tmpdir(), - img->fname) >= (int)sizeof(fn)) { - ERROR("Path too long: %s%s", TMPDIR, img->fname); - } - remove_sw_file(fn); + + for (count = 0; count < 2; count++) { + if (count == 0) + list = &software->scripts; + else + list = &software->bootscripts; + + LIST_FOREACH(img, list, next) { + cleaup_img_entry(img); + + LIST_REMOVE(img, next); + free(img); } - dict_drop_db(&img->properties); - LIST_REMOVE(img, next); - free(img); } dict_drop_db(&software->bootloader); diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c index a200d7e..99b8329 100644 --- a/corelib/stream_interface.c +++ b/corelib/stream_interface.c @@ -186,20 +186,38 @@ static int extract_files(int fd, struct swupdate_cfg *software) break; } - skip = check_if_required(&software->images, &fdh, + int i; + + for (i = 0; i < 3; i++) { + switch(i) { + case 0: + skip = check_if_required(&software->images, &fdh, &software->installed_sw_list, get_tmpdir(), &img); - if (skip == SKIP_FILE) { + break; /* * Check for script, but scripts are not checked * for version */ - skip = check_if_required(&software->scripts, &fdh, + case 1: + skip = check_if_required(&software->scripts, &fdh, + NULL, + get_tmpdir(), + &img); + break; + case 2: + skip = check_if_required(&software->bootscripts, &fdh, NULL, get_tmpdir(), &img); + break; + } + + if (skip != SKIP_FILE) + break; } + TRACE("Found file:\n\tfilename %s\n\tsize %u %s", fdh.filename, (unsigned int)fdh.size, diff --git a/include/installer.h b/include/installer.h index 658b064..c0fe5e5 100644 --- a/include/installer.h +++ b/include/installer.h @@ -31,7 +31,6 @@ int check_if_required(struct imglist *list, struct filehdr *pfdh, struct img_type **pimg); int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile); int install_single_image(struct img_type *img); -int run_prepost_scripts(struct swupdate_cfg *sw, script_fn type); int postupdate(struct swupdate_cfg *swcfg, const char *info); void cleanup_files(struct swupdate_cfg *software); diff --git a/include/swupdate.h b/include/swupdate.h index b065f7e..2cc824d 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -134,6 +134,7 @@ struct swupdate_cfg { struct imglist images; struct imglist partitions; struct imglist scripts; + struct imglist bootscripts; struct dictlist bootloader; struct proclist extprocs; void *dgst; /* Structure for signed images */ diff --git a/parser/parser.c b/parser/parser.c index 84b6576..9cd4204 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -351,6 +351,7 @@ static int parse_bootloader(parsertype p, void *cfg, struct swupdate_cfg *swcfg) { void *setting, *elem; int count, i; + struct img_type *script; char name[32]; char value[255]; @@ -372,24 +373,45 @@ static int parse_bootloader(parsertype p, void *cfg, struct swupdate_cfg *swcfg) /* * Check for mandatory field */ - if(!(exist_field_string(p, elem, "name"))) { - TRACE("bootloader entry without variable name field, skipping.."); + if(exist_field_string(p, elem, "name")) { + /* + * Call directly get_field_string with size 0 + * to let allocate the place for the strings + */ + GET_FIELD_STRING(p, elem, "name", name); + GET_FIELD_STRING(p, elem, "value", value); + dict_set_value(&swcfg->bootloader, name, value); + TRACE("Bootloader var: %s = %s\n", + name, + dict_get_value(&swcfg->bootloader, name)); continue; } - /* - * Call directly get_field_string with size 0 - * to let allocate the place for the strings + * Check if it is a bootloader script */ - GET_FIELD_STRING(p, elem, "name", name); - GET_FIELD_STRING(p, elem, "value", value); - dict_set_value(&swcfg->bootloader, name, value); + if(!(exist_field_string(p, elem, "filename"))) { + TRACE("bootloader entry is neither a script nor name/value."); + continue; + } + script = (struct img_type *)calloc(1, sizeof(struct img_type)); + if (!script) { + ERROR( "No memory: malloc failed\n"); + return -ENOMEM; + } + GET_FIELD_STRING(p, elem, "filename", script->fname); + GET_FIELD_STRING(p, elem, "type", script->type); + GET_FIELD_STRING(p, elem, "data", script->type_data); + get_hash_value(p, elem, script->sha256); + get_field(p, elem, "encrypted", &script->is_encrypted); + get_field(p, elem, "compressed", &script->compressed); + get_field(p, elem, "encrypted", &script->is_encrypted); + script->is_script = 1; - TRACE("Bootloader var: %s = %s\n", - name, - dict_get_value(&swcfg->bootloader, name)); + LIST_INSERT_HEAD(&swcfg->bootscripts, script, next); + TRACE("Found U-Boot Script: %s\n", + script->fname); } return 0;