From patchwork Sun Jan 14 16:24:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 860476 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:4010:c07::240; helo=mail-lf0-x240.google.com; envelope-from=swupdate+bncbcxploxj6ikrbpui53jakgqemundfla@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="i8ZxIMte"; dkim-atps=neutral Received: from mail-lf0-x240.google.com (mail-lf0-x240.google.com [IPv6:2a00:1450:4010:c07::240]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zKMJM2GTnz9t2c for ; Mon, 15 Jan 2018 03:24:34 +1100 (AEDT) Received: by mail-lf0-x240.google.com with SMTP id m195sf2725856lfg.2 for ; Sun, 14 Jan 2018 08:24:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1515947070; cv=pass; d=google.com; s=arc-20160816; b=zFENVyTcuK103vtL8DXs094Ij+mRkd6IEwXGO0SxFfxGbur0nmKXFmrhUiTGr3+3Rs jFZMBfgxVKgwz7lAvSgBlLKgLTg2U9d+5oTzzGnmlFnzKq2y6TWmp4TvD1deLWdQyDOZ 0p1H7/LobD6EZDLWZle2UPrSVCvvzElkC1fF4cHdsl4nITIhDg5kp3etnaFVPf1SZuu9 /bc5PfiULq3hAdIEYoadLcaTWm5SpM32X+40qdJJbZkSNRgiNrvCp6bEAJ6e75I7D5vn Wms6fb/w1uFGmINIDhJOqURaT4IFil6HinB4QmkfM7lsRymKRWvCQkHeQM/rEwbYjl5Y wfhg== 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=80MYIyOwlMHoiNph82Uq7hIEzKzI4Q2BxEjO0rLjBvo=; b=XBtXT8HbvVpukjz55ee2S9cFLyc1Ufo+8Ca9ivYS4RKh7P3wgA/vycZPgikU2QCLNX 8d17Jx3bo89koM7Nu+vPsC3WthnkFuWs3aaZrBJKM1z1evEdCE9kALtJR4E+ruD+g8Ng kQf0SYTlNoqUrETrL6Q7yCFLFR009egVDxX3d7yZ+ErLqklfrD6/mw+ZxUuKm0PUdOe0 WHol2P8TmP9ymmW/VlcUIHhsmf2ci6CeNHkScO1HC4CZdWmA7jiHVjklaW0rwBNGUoSy Upzz46FoTaICkwioyTcFM2dhl2OmUQiclLE1zQiPa2Ev4Po24tkZXqiBd3f3eOBxVVZO /q+Q== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 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=80MYIyOwlMHoiNph82Uq7hIEzKzI4Q2BxEjO0rLjBvo=; b=i8ZxIMteey52g3++CZUKoX/6WZGliH6fHExmx+Sxu6JWXQWIe82XeCa9WoumHu9OaF b+ioLRVxp5Hg3XvzXx3VOwge1RbTQtQLdydx9Ry2KZw/Ah0+DzUt/fb1or/F+JQQdykx m1B+LC7B3R90VrFT4MJCOePjNHQa2bXFGB+kjBs40qm4nN1Lt1ChTVfQiSh3kCdA6yjj zGQW0kRjdTlExU037tdAx8TDGjyKVNOYdyPqkGnzINVRaqN47AfZMahb+1W1GxmK2yQ7 Uhai2Bodm15BRbRncIX/kuinVDnKA/WFnJIY8KT269OjYfEYsCtyDeKUvaPuRfH/heNf V43A== 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=80MYIyOwlMHoiNph82Uq7hIEzKzI4Q2BxEjO0rLjBvo=; b=Eek+9WheC1vjazEPWVCAT6SyTWXFCzc7IHApOj4dCkxOSuY4b/CSVIb1i/Po0Gu6W4 w+IuWQ39wN0RFt5d0gENRq6iErTdYo1lOSDdY/pHn45PepXIXPmubhYZ1dj9TUmi6n1E 8xKBbrTvQ3FhM+9tz+Vf4WsmRw4C9cNMPj3HsR71WRV0JlJm/wm93b/66H2NeTzhtXoV J0JTSndIkyIei9oR2mMbaf7O5hdzZzx23dRp4qv2U6t5NRsUqADEQnQWlHYEtDb4KJ/8 yhoVQCjj/e3Ix0smJTiD2N3xDWtHAq9nkRzUarni/AQYUlcb/h8Qxu9O5wVY8zgPlcjB /UQg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytfuaQ3D2uz0HFFGcD7imor3Jkqy8lobsHmahRA4igXuzxLg+MIy W1ls/BQe2cbnFFnYgRo09qU= X-Google-Smtp-Source: ACJfBotaYbpXv8JoQbz0dMsb1q53Q4IopS5r3jEB7doW6V+PLFoD4VT6oTbo+T/PVROrxqsGC62fgA== X-Received: by 10.46.108.6 with SMTP id h6mr19720ljc.9.1515947070819; Sun, 14 Jan 2018 08:24:30 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.108.8 with SMTP id h8ls370379ljc.2.gmail; Sun, 14 Jan 2018 08:24:30 -0800 (PST) X-Received: by 10.46.115.3 with SMTP id o3mr1522433ljc.15.1515947070352; Sun, 14 Jan 2018 08:24:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515947070; cv=none; d=google.com; s=arc-20160816; b=sakSg8XS69+5HIPAWj+PdrKEa4DwiJIAkYTMMfpGulJ72r0CWhsXeEr2wfp080kAbq Y/Lq4p2tWzU+PxopHfY2pHTB0Ffx7+4GnHmL6ADwLMooC6Uzht7ZBF6G1btrW4NMSlAn WR2zRMJBRzIOHKG9AqKY6xO/m36uCT9LLUUatpOTr9awMXJErMYFGX86o2LA9XK7brPb 3aoN2BIsO4SqX7GJKIG44KEITe75QtPLNdw5Pr4T3zKt14QMcj+fBRbNFaNbrFDcina1 tce9sSU2V7J7i03HkA98nhzA8uo7qRCz7HHni1atAGtYDQO9w9YKi7uI7kJosRFOCq0y wdRA== 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=3E16p0XZKogqKfQZdr6oF+McGy9NtAZfNHYYTcJjrUs=; b=IP4HKfNlqoFE5aF4kB+0QyHBvjIxZTOUFhL4tuMWgGz+iOkKnKqXRZtD5d/cmBhtbu upulfx8OcDRpgthZR1nLLEwjIQd+soCm5Dqb87djq6JIr3izPPW+Ffy66oWWC/6K4LUZ 4ydcm7NW/hDKC6PkHdLBk3W8Cv/P+pb1wV1Mb/eTpzoXJy16RSutmt/tS4Bk2aBcKN+r n/lu/wRRRaHaaPINAuT7rMsq2+X3X7j8Q5IGize1zzYb3zy1KOs3opUxw5Ps0bHj8x/R U7R7YFvfWYvEar8CuXcAe5stewS5Q5FX6rRadGeihqqJQvtheDPpkgUutUdvFJPlQT0L Md3g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 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.10]) by gmr-mx.google.com with ESMTPS id v124si1080533lfa.2.2018.01.14.08.24.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Jan 2018 08:24:30 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3zKMJF5GLPz1qshs; Sun, 14 Jan 2018 17:24:29 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3zKMJF54SVz1sFWw; Sun, 14 Jan 2018 17:24:29 +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 DXmVWg6_yON0; Sun, 14 Jan 2018 17:24:28 +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; Sun, 14 Jan 2018 17:24:28 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 0D3E1454050F; Sun, 14 Jan 2018 17:24:28 +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 SxkL_yQZGVMv; Sun, 14 Jan 2018 17:24:24 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id A6A4C4540360; Sun, 14 Jan 2018 17:24:24 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH V3 1/2] Allow again bootloader scripts Date: Sun, 14 Jan 2018 17:24:21 +0100 Message-Id: <1515947062-7830-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: 212.18.0.10 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 --- Changes since V2: - use ARRAY_SIZE() macro Changes since V1: - replaces switch() with arrays core/parser.c | 2 + corelib/installer.c | 93 +++++++++++++++++++++++++++------------------- corelib/stream_interface.c | 25 +++++++------ include/installer.h | 1 - include/swupdate.h | 1 + parser/parser.c | 43 +++++++++++++++------ 6 files changed, 103 insertions(+), 62 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..f0b7720 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; -} + ret |= run_prepost_scripts(&sw->bootscripts, POSTINSTALL); -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; - } - } - - return 0; + return ret; } - static void remove_sw_file(char __attribute__ ((__unused__)) *fname) { #ifndef CONFIG_NOCLEANUP @@ -430,11 +432,32 @@ 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[] = { get_tmpdirscripts(), get_tmpdir() }; + + if (img->fname[0]) { + for (i = 0; i < ARRAY_SIZE(tmp); i++) { + if (asprintf(&fn, "%s%s", tmp[i], img->fname) == ENOMEM_ASPRINTF) { + ERROR("Path too long: %s%s", tmp[i], 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[] = {&software->scripts, &software->bootscripts}; LIST_FOREACH(img, &software->images, next) { if (img->fname[0]) { @@ -447,22 +470,14 @@ 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 < ARRAY_SIZE(list); count++) { + LIST_FOREACH(img, list[count], 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..35baf94 100644 --- a/corelib/stream_interface.c +++ b/corelib/stream_interface.c @@ -186,20 +186,23 @@ static int extract_files(int fd, struct swupdate_cfg *software) break; } - skip = check_if_required(&software->images, &fdh, - &software->installed_sw_list, + int i; + + struct imglist *list[] = {&software->images, + &software->scripts, + &software->bootscripts}; + + for (i = 0; i < ARRAY_SIZE(list); i++) { + skip = check_if_required(list[i], &fdh, + (list[i] == &software->images) ? + &software->installed_sw_list : NULL, get_tmpdir(), &img); - if (skip == SKIP_FILE) { - /* - * Check for script, but scripts are not checked - * for version - */ - skip = check_if_required(&software->scripts, &fdh, - NULL, - get_tmpdir(), - &img); + + 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 3a1d6a5..f0b3cb4 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -359,6 +359,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]; @@ -380,24 +381,44 @@ 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); + 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;