From patchwork Tue Jan 26 20:54:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 1431944 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.a=rsa-sha256 header.s=google header.b=Dw1MiPLV; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQLk54LWpz9sVr for ; Wed, 27 Jan 2021 09:19:08 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9A38782642; Tue, 26 Jan 2021 23:18:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.b="Dw1MiPLV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1689D825F1; Tue, 26 Jan 2021 21:55:16 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 33D6E82540 for ; Tue, 26 Jan 2021 21:55:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roman.kovalivskyi@globallogic.com Received: by mail-lf1-x129.google.com with SMTP id a8so24596574lfi.8 for ; Tue, 26 Jan 2021 12:55:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=HkvUySe+iCRfdnNXa33nZSOcvUAQrVd3W3lZ4uwNQBE=; b=Dw1MiPLVo5GAaHRecvvarO5aROa+0Gka02kiJ4H6IWkqu38Re2jY5VX1ysE2L5yx+w NWHBVhb6kY9lzndNywSAllQYS6nHoABj2QbN7/fUqf1Smo48qLWELzKZd5O9pq20Xkqm Dff5bHRocXm265tzXbCYGaAXFoduZ60+eLEXbGwJSWt+tDrG5D6i/GC+hzD/s/0hPDI8 4A37TSZy6A4grJR4yiVc/tCAIAJ53vbGK6RJF//wHktLhuFzJiyDrmPeeSV5RofZIuLA oMfenOQT5Rc5yoHE5R3pV7f3N7SKLu/SvMT5Es6EKPWHL1VWeHw+9N/VcrXFbjlP3wIr 8OIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=HkvUySe+iCRfdnNXa33nZSOcvUAQrVd3W3lZ4uwNQBE=; b=DRPfcd/28awmyeXLaHH+CR9o2SC2M0ckqRakZfV9msSLPw6dh5iHnMQ+ipA/mI6fYW C2MzjBGG4fCMG3D5lq4jX65L19/m89P55nnymg1GYlqTTtVLz6BwHXh2J74UZJJ/LALh XR0ypNNXt+xfXT+zhVuqNJDc9mm1numwvGQs8SsgpyaOmHt2kERowBQwT5Hm/2tfKWvl PPrxx7n1cLtRPEoH/kKUjHfXOjjDjUFx4xVc/Jxy+5tocauseRAFr+/H+yPw9Wr1sMoo 73dPvZflHG3f33XRXpkIiklNsp6Ja0unXXc3D4kFg0MofAdSlOqfCDtFfRq3VBkCDglb br9A== X-Gm-Message-State: AOAM532vop8Gc/a4WxSq+571jtXPgE/pKXSoXZ3Tr34wjUc4N+8ZwFCv MmuP25ITdKmOOWT8X6Wm1AWMItkLN+l+JkE/LOE= X-Google-Smtp-Source: ABdhPJwfjIN55Uz4ApjorEKGyGqGVU0uP8XwcmZ0vhFgSXPGKH9FLPg7GiCdmr26wkRmr4kvWH+ZwQ== X-Received: by 2002:a19:ac0c:: with SMTP id g12mr3560436lfc.51.1611694512465; Tue, 26 Jan 2021 12:55:12 -0800 (PST) Received: from hrk1-lhp-F73989.synapse.com ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id o4sm6170lfo.231.2021.01.26.12.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 12:55:11 -0800 (PST) From: Roman Kovalivskyi To: u-boot@lists.denx.de Cc: Roman Stratiienko , Joe Hershberger , Roman Kovalivskyi , Simon Glass , Marek Vasut , Lukasz Majewski , Eugeniu Rosca , Alex Kiernan , Sam Protsenko , Neil Armstrong , Philipp Tomsich , Kever Yang , Paul Kocialkowski , Lokesh Vutla , Jagan Teki , Miquel Raynal , Boris Brezillon , Tom Rini , Igor Opaniuk , Aleksandr Bulyshchenko Subject: [PATCH v2 1/7] cmd: bcb: Extract '__bcb_load' from 'do_bcb_load' for internal needs Date: Tue, 26 Jan 2021 22:54:50 +0200 Message-Id: <52d66cc8c31b37497a92287ef2bb3583d54c48bb.1611688251.git.roman.kovalivskyi@globallogic.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Tue, 26 Jan 2021 23:18:47 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Eugeniu Rosca Enriching the functionality of U-Boot 'bcb' may assume using the existing sub-commands as building blocks for the next ones. A clean way to achive the above is to expose a number of static routines, each mapped to an existing user command (e.g. load/set/store), with a user/caller-friendly prototype (i.e. do not force the caller to wrap an integer into a string). This first patch makes '__bcb_load' available for internal needs. No functional change, except for a tiny update in error handling. Signed-off-by: Eugeniu Rosca Signed-off-by: Roman Kovalivskyi --- cmd/bcb.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/bcb.c b/cmd/bcb.c index e03218066bf2..2ed8b801a3e2 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -110,8 +110,7 @@ static int bcb_field_get(char *name, char **fieldp, int *sizep) return 0; } -static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) +static int __bcb_load(int devnum, const char *partp) { struct blk_desc *desc; struct disk_partition info; @@ -119,17 +118,19 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc, char *endp; int part, ret; - ret = blk_get_device_by_str("mmc", argv[1], &desc); - if (ret < 0) + desc = blk_get_devnum_by_type(IF_TYPE_MMC, devnum); + if (!desc) { + ret = -ENODEV; goto err_read_fail; + } - part = simple_strtoul(argv[2], &endp, 0); + part = simple_strtoul(partp, &endp, 0); if (*endp == '\0') { ret = part_get_info(desc, part, &info); if (ret) goto err_read_fail; } else { - part = part_get_info_by_name(desc, argv[2], &info); + part = part_get_info_by_name(desc, partp, &info); if (part < 0) { ret = part; goto err_read_fail; @@ -151,10 +152,10 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; err_read_fail: - printf("Error: mmc %s:%s read failed (%d)\n", argv[1], argv[2], ret); + printf("Error: mmc %d:%s read failed (%d)\n", devnum, partp, ret); goto err; err_too_small: - printf("Error: mmc %s:%s too small!", argv[1], argv[2]); + printf("Error: mmc %d:%s too small!", devnum, partp); goto err; err: bcb_dev = -1; @@ -163,6 +164,20 @@ err: return CMD_RET_FAILURE; } +static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc, + char * const argv[]) +{ + char *endp; + int devnum = simple_strtoul(argv[1], &endp, 0); + + if (*endp != '\0') { + printf("Error: Device id '%s' not a number\n", argv[1]); + return CMD_RET_FAILURE; + } + + return __bcb_load(devnum, argv[2]); +} + static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { From patchwork Tue Jan 26 20:54:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 1431946 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.a=rsa-sha256 header.s=google header.b=jvVYoXAH; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQLkG6yYQz9sVn for ; Wed, 27 Jan 2021 09:19:18 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 95DC882666; Tue, 26 Jan 2021 23:18:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.b="jvVYoXAH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E5EEB825C4; Tue, 26 Jan 2021 21:55:17 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1B79F825C4 for ; Tue, 26 Jan 2021 21:55:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roman.kovalivskyi@globallogic.com Received: by mail-lf1-x133.google.com with SMTP id i187so14321055lfd.4 for ; Tue, 26 Jan 2021 12:55:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=WUudbUgqZTxFfi9mrdvNvTJcZ8u4SLL6h6HtxkUa4Co=; b=jvVYoXAHFGBmRZbC/B/wXYo88NQJOELHIN19zFxaDwFCXzejKULlRXNW+awniJJkW8 LQ32X2TA+3/7p3vg87WY5ywQFH/t/DxAl+xHoNxvv8zWUCNpjBt6yJYF2p2gNdmA9ZLw /5Vw74xxXynZY8qc/1YaRqPPr/ifEATKf6dh4z5jOqLYIPhDE21Phnt4Lz6wkXko3TsM JQraEiR8I2KvVn5WtRdRNVVKcf2TucGBEv8KX+5tOAy+JeyOTxRipWR1CUOBK0v6yK0y yX5YNMz+JkkvS3mMG8rB3o7PrWUBjQkY9pdQRKHWYxhZrs1ARf7ES7QlAeBlT72DfTnr HDAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=WUudbUgqZTxFfi9mrdvNvTJcZ8u4SLL6h6HtxkUa4Co=; b=gOvJLN1IFPtJ7EtaqOEvBIP6C74qYYqbO3jGScabUVrtRL6Optrtvcmw2+pVyjyVwI lbZyPIEDcDK1BdPPehVfowq8ZSE0lQCRPJ3P1c01fqLXsy3AhsncYACvCGYIt0cbn2dD YujwqWHNuNxm1UiTF7zS/AOz3gVH2281T3ynB0994tVNW5bsZEfL88bDRHd0LLKmhR07 W5/xpesulpz7B/gxyXuOT9VVx+IO3kVxOlvtSWy1yLYvId818YnoCy1f3wlp7uAkaSKE 4XAa+NtAJk+Xo1dAR/UDXaYQB4aY4EcMk9qPpMPADw7DZjmk5qW9eQniD914JauyD6rG ALBQ== X-Gm-Message-State: AOAM532ZJk2ct3A45iWX2Ziyri3zK0KbQkrjdpwgw4Yyzz69Nv0AnC98 ryXTH+yE1yFVoWb1m/i3ioDbZfuqAOZneDkDoZM= X-Google-Smtp-Source: ABdhPJxq6z99rbq4mlPcit6uPTV9Bv1gxUClrFZnGzwTQYTEmIVPEhZPN20Qa5unIFKihgiUdNYyZg== X-Received: by 2002:a19:ac49:: with SMTP id r9mr3640613lfc.602.1611694514377; Tue, 26 Jan 2021 12:55:14 -0800 (PST) Received: from hrk1-lhp-F73989.synapse.com ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id o4sm6170lfo.231.2021.01.26.12.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 12:55:13 -0800 (PST) From: Roman Kovalivskyi To: u-boot@lists.denx.de Cc: Roman Stratiienko , Joe Hershberger , Roman Kovalivskyi , Simon Glass , Marek Vasut , Lukasz Majewski , Eugeniu Rosca , Alex Kiernan , Sam Protsenko , Neil Armstrong , Philipp Tomsich , Kever Yang , Paul Kocialkowski , Lokesh Vutla , Jagan Teki , Miquel Raynal , Boris Brezillon , Tom Rini , Igor Opaniuk , Aleksandr Bulyshchenko Subject: [PATCH v2 2/7] cmd: bcb: Extract '__bcb_set' from 'do_bcb_set' for internal needs Date: Tue, 26 Jan 2021 22:54:51 +0200 Message-Id: <654aeffabe8f128ca1e7e3fb4bb20ed1cdc7be7d.1611688251.git.roman.kovalivskyi@globallogic.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Tue, 26 Jan 2021 23:18:47 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Eugeniu Rosca Enriching the functionality of U-Boot 'bcb' may assume using the existing sub-commands as building blocks for the next ones. A clean way to achive the above is to expose a number of static routines, each mapped to an existing user command (e.g. load/set/store), with a user/caller-friendly prototype (i.e. do not force the caller to wrap an integer into a string). This second patch makes '__bcb_set' available for internal needs. No functional change intended. Signed-off-by: Eugeniu Rosca Signed-off-by: Roman Kovalivskyi --- cmd/bcb.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/bcb.c b/cmd/bcb.c index 2ed8b801a3e2..113f04ffe6b2 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -178,22 +178,21 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc, return __bcb_load(devnum, argv[2]); } -static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) +static int __bcb_set(char *fieldp, char *valp) { int size, len; char *field, *str, *found; - if (bcb_field_get(argv[1], &field, &size)) + if (bcb_field_get(fieldp, &field, &size)) return CMD_RET_FAILURE; - len = strlen(argv[2]); + len = strlen(valp); if (len >= size) { printf("Error: sizeof('%s') = %d >= %d = sizeof(bcb.%s)\n", - argv[2], len, size, argv[1]); + valp, len, size, fieldp); return CMD_RET_FAILURE; } - str = argv[2]; + str = valp; field[0] = '\0'; while ((found = strsep(&str, ":"))) { @@ -205,6 +204,12 @@ static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } +static int do_bcb_set(struct cmd_tbl *cmdtp, int flag, int argc, + char * const argv[]) +{ + return __bcb_set(argv[1], argv[2]); +} + static int do_bcb_clear(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { From patchwork Tue Jan 26 20:54:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 1431947 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.a=rsa-sha256 header.s=google header.b=aErSPXOA; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQLkb19nHz9sVr for ; Wed, 27 Jan 2021 09:19:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 18F038268A; Tue, 26 Jan 2021 23:18:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.b="aErSPXOA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AD2E982603; Tue, 26 Jan 2021 21:55:20 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 838D682540 for ; Tue, 26 Jan 2021 21:55:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roman.kovalivskyi@globallogic.com Received: by mail-lf1-x129.google.com with SMTP id p21so19527104lfu.11 for ; Tue, 26 Jan 2021 12:55:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=hxiltvW1+erURMOEpsPIng5+Fm2aTx8YH+2o9Q0wB3c=; b=aErSPXOANWoeMDJLtIF3KpLQtVwPdqA1+SCiUW0w+P3HZEuk3ZEel++lQi09XPaZP0 7w3S/MZtPuxZqEnl+k/vR4yuILx3K25y2Er7tpqusdCQqmf2HbB+3FjzFZjzY/fe+plf UNDxgx783tjVGUNEoAMJbny7bguq8S4fR8VvRnt93Sp/YUNjZwCkH6wSUY0c2c4oJeZj DGOXJuRZX49IVZpXJK9X40eKm2Pc2mQmtJCufHDKSDvN7xrr5M9Agzf81j9P8myWaPYv cS9b3dx42NeuHTu+eQjSsLPxbtqWK6lzlGoHKP9vyn4LRpnA4Oj6+t/RL8eZ6/6PZ2Ey t/7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=hxiltvW1+erURMOEpsPIng5+Fm2aTx8YH+2o9Q0wB3c=; b=bUcI6fT1OjoGk4ON3tTr66hN6YxywYIhgyCvg2TawdKk8beRZrr5lPiEnQCDI7PZwS O7MfwXNeJd7mR94GEkOz9Hwt0Lav2rqxKJ/ZmK7vM0zK7EUGb1c1cnjFAMwHyiz0jZBp cIF7xF+O12Ru7OlPVLYHHSNs6LF7aqeFrijtYf2BGeCdAFNeG/Ph+DMdW+7pLz1hbKa1 S0y3bS+IDezbSliQNe0ql+sLfrs7W4y1Kn/h/IQkqXca9ZScXAhKk7ImNLKlEbrY794x i9Jo13x0Daoad4BcDrzL6yMkXnNLm6TWI7xmE0pFbz0y80ae8kUXA304O2+yu4vUUd8Z 3iDA== X-Gm-Message-State: AOAM5318AxcLGOqzi4Ics1hFpwWtASEqS5Rw903p3lExaJGbBJ0lOz/t HOmlQ4vwJa6X6N9hHwDGL85xzGcfTnLyqzIqu/U= X-Google-Smtp-Source: ABdhPJz5kqW60szPuxmKykjbH5u/r/lEGWpytjbCQv8CKVHvGL7FFAAwlBgUmlQnnp2HQxWlSjmbbw== X-Received: by 2002:a05:6512:3182:: with SMTP id i2mr3437283lfe.553.1611694516681; Tue, 26 Jan 2021 12:55:16 -0800 (PST) Received: from hrk1-lhp-F73989.synapse.com ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id o4sm6170lfo.231.2021.01.26.12.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 12:55:15 -0800 (PST) From: Roman Kovalivskyi To: u-boot@lists.denx.de Cc: Roman Stratiienko , Joe Hershberger , Roman Kovalivskyi , Simon Glass , Marek Vasut , Lukasz Majewski , Eugeniu Rosca , Alex Kiernan , Sam Protsenko , Neil Armstrong , Philipp Tomsich , Kever Yang , Paul Kocialkowski , Lokesh Vutla , Jagan Teki , Miquel Raynal , Boris Brezillon , Tom Rini , Igor Opaniuk , Aleksandr Bulyshchenko Subject: [PATCH v2 3/7] cmd: bcb: Extract '__bcb_store' from 'do_bcb_store' for internal needs Date: Tue, 26 Jan 2021 22:54:52 +0200 Message-Id: <0b293b07716e8c96f1600f05673afc61a6fc40bb.1611688251.git.roman.kovalivskyi@globallogic.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Tue, 26 Jan 2021 23:18:47 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Eugeniu Rosca Enriching the functionality of U-Boot 'bcb' may assume using the existing sub-commands as building blocks for the next ones. A clean way to achive the above is to expose a number of static routines, each mapped to an existing user command (e.g. load/set/store), with a user/caller-friendly prototype (i.e. do not force the caller to wrap an integer into a string). This third patch makes '__bcb_store' available for internal needs. No functional change intended. Signed-off-by: Eugeniu Rosca Signed-off-by: Roman Kovalivskyi --- cmd/bcb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/bcb.c b/cmd/bcb.c index 113f04ffe6b2..b9cd20ea3d56 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -270,8 +270,7 @@ static int do_bcb_dump(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } -static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) +static int __bcb_store(void) { struct blk_desc *desc; struct disk_partition info; @@ -302,6 +301,12 @@ err: return CMD_RET_FAILURE; } +static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc, + char * const argv[]) +{ + return __bcb_store(); +} + static struct cmd_tbl cmd_bcb_sub[] = { U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_bcb_load, "", ""), U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 1, do_bcb_set, "", ""), From patchwork Tue Jan 26 20:54:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 1431948 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.a=rsa-sha256 header.s=google header.b=kWio3hpa; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQLkj10z8z9sVn for ; Wed, 27 Jan 2021 09:19:41 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4A81C826A5; Tue, 26 Jan 2021 23:18:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.b="kWio3hpa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 12F1F8263A; Tue, 26 Jan 2021 21:55:23 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A095282366 for ; Tue, 26 Jan 2021 21:55:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roman.kovalivskyi@globallogic.com Received: by mail-lf1-x144.google.com with SMTP id a8so24596829lfi.8 for ; Tue, 26 Jan 2021 12:55:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=K8OBoJeldtSm8o51SMH5ieRz3Y1ToItkxX7rxQXC0uk=; b=kWio3hpaR78Ql6KRhITEut8uhgd1XUHpbX4KNJAozLokq0H790lZWEyJASrWw9KWVT XbHNyYYhuWaE26DUwSjUagZ4IilTDKdKE+DhDMILc3f0PsEoR0AomoUEZ1TLwv/DYfO8 bID0nxIccO65dQNcutcmAhGVucNhbcM+sUjLXBtE2vB32VEXg1VbPcoiNlPQQUMV8qm+ MkQXj71jajwu/0sqWIa3P1PnXUk0RgxZ0h8DYu8UVdt+rjHVwSFu/MxM1Q65HesJMJGe 8uq14PcnduYjVqTpwcvbZppNR6QRfTYibDSozjsBJCE5gAU1bL9kZzxe7mMl3LENMYyl tPPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=K8OBoJeldtSm8o51SMH5ieRz3Y1ToItkxX7rxQXC0uk=; b=tM8FiODQWg+YtTAEYjrwWY3prF7+/MTdczY2X8kBdJHojR1y+RFM9tvZRCOc6nX3EL Fr7p2x70eSFhS9Z+PMw12uAtq2MHElx6GUyU9MZ3iGX8WTbE9LHXkzAVlUPdq4idmulV Fx/9xCXMXFaSQNA2tYtgPi/avkpVXNw6SYuQ/ATDM/S8ai1wAIy+cUdOj/uJehLbldRm 4e/JqTcvgasF9pj2yA/iM0RH3Lz/vprrg5+P4bPsXM4aSGhF5JtuZgPkwR29DPR6SfcS QWi9/PCQi4nkvSX0SWHnCuO6N4xZzgw7hZs2pZUERNrgx1LpAeF+5v9TbQv2HlsItPmN 350A== X-Gm-Message-State: AOAM530cYkElXx+hA+oSUUFtzVUvzqOy91maqxS+CpavtXsF03LnPc+D TDIAAwqOrqHvSCOjhotj/0XHfgWLiYPqsbnoysY= X-Google-Smtp-Source: ABdhPJwaSasOWAl6R3OixyI9PpI83iol7Y0lER80MWccHE30A6+aBRy36nbgOOC3PETCvy9/ETczKQ== X-Received: by 2002:ac2:5b1b:: with SMTP id v27mr3620116lfn.260.1611694518781; Tue, 26 Jan 2021 12:55:18 -0800 (PST) Received: from hrk1-lhp-F73989.synapse.com ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id o4sm6170lfo.231.2021.01.26.12.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 12:55:18 -0800 (PST) From: Roman Kovalivskyi To: u-boot@lists.denx.de Cc: Roman Stratiienko , Joe Hershberger , Roman Kovalivskyi , Simon Glass , Marek Vasut , Lukasz Majewski , Eugeniu Rosca , Alex Kiernan , Sam Protsenko , Neil Armstrong , Philipp Tomsich , Kever Yang , Paul Kocialkowski , Lokesh Vutla , Jagan Teki , Miquel Raynal , Boris Brezillon , Tom Rini , Igor Opaniuk , Aleksandr Bulyshchenko Subject: [PATCH v2 4/7] cmd: bcb: Expose 'bcb_write_reboot_reason' to external callers Date: Tue, 26 Jan 2021 22:54:53 +0200 Message-Id: <192ff474a82c9af7e70b754c33515e384be94fc5.1611688251.git.roman.kovalivskyi@globallogic.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Tue, 26 Jan 2021 23:18:47 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Eugeniu Rosca Fastboot is evolving and beginning with commit [1], the upstream implementation expects bootloaders to offer support for: - reboot-recovery - reboot-fastboot The most natural way to achieve the above is through a set of pre-defined "reboot reason" strings, written into / read from the BCB "command" field, e.g.: - bootonce-bootloader [2] - boot-fastboot [3] - boot-recovery [4] Expose the first 'bcb' API meant to be called by e.g. fastboot stack, to allow updating the BCB reboot reason via the BCB 'command' field. [1] https://android.googlesource.com/platform/system/core/+/dea91b4b5354af2 ("Add fastbootd.") [2] https://android.googlesource.com/platform/bootable/recovery/+/cba7fa88d8b9 ("Add 'reboot bootloader' to bootloader_message.") [3] https://android.googlesource.com/platform/bootable/recovery/+/eee4e260f9f6 ("recovery: Add "boot-fastboot" command to BCB.") [4] https://android.googlesource.com/platform/system/core/+/5e98b633a748695f ("init: Write the reason in BCB on "reboot recovery"") Signed-off-by: Eugeniu Rosca Signed-off-by: Roman Kovalivskyi --- cmd/bcb.c | 20 ++++++++++++++++++++ include/bcb.h | 22 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 include/bcb.h diff --git a/cmd/bcb.c b/cmd/bcb.c index b9cd20ea3d56..5da3526142ad 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -307,6 +308,25 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc, return __bcb_store(); } +int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp) +{ + int ret; + + ret = __bcb_load(devnum, partp); + if (ret != CMD_RET_SUCCESS) + return ret; + + ret = __bcb_set("command", reasonp); + if (ret != CMD_RET_SUCCESS) + return ret; + + ret = __bcb_store(); + if (ret != CMD_RET_SUCCESS) + return ret; + + return 0; +} + static struct cmd_tbl cmd_bcb_sub[] = { U_BOOT_CMD_MKENT(load, CONFIG_SYS_MAXARGS, 1, do_bcb_load, "", ""), U_BOOT_CMD_MKENT(set, CONFIG_SYS_MAXARGS, 1, do_bcb_set, "", ""), diff --git a/include/bcb.h b/include/bcb.h new file mode 100644 index 000000000000..05db5935e0e7 --- /dev/null +++ b/include/bcb.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Eugeniu Rosca + * + * Android Bootloader Control Block Header + */ + +#ifndef __BCB_H__ +#define __BCB_H__ + +#include + +#if CONFIG_IS_ENABLED(CMD_BCB) +int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp); +#else +static inline int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp) +{ + return -EOPNOTSUPP; +} +#endif + +#endif /* __BCB_H__ */ From patchwork Tue Jan 26 20:54:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 1431949 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.a=rsa-sha256 header.s=google header.b=H+QRavJI; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQLkv6bpBz9sVn for ; Wed, 27 Jan 2021 09:19:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9889F82687; Tue, 26 Jan 2021 23:19:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.b="H+QRavJI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E143F825C4; Tue, 26 Jan 2021 21:55:24 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CD371825F1 for ; Tue, 26 Jan 2021 21:55:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roman.kovalivskyi@globallogic.com Received: by mail-lj1-x244.google.com with SMTP id r14so2550496ljc.2 for ; Tue, 26 Jan 2021 12:55:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=gIm794aXkj6kHE4h6NuMA5WnVVz4m9W6GS8RsB7RY70=; b=H+QRavJI0c9JnHeUUd9E25n7i1NQBxnZY7Wp5r4zRUf45wpib8O5p/Jme926jvah6p eRlLSotBF/Y0Ewo0Vgx19Olt7eolDKKXdiiF5NfT9WlnmLhloglTfiGHfhHwinZ3IZ6g GH8KBZlHhWNHK1nBk7irmPiuc8tnmh5slrxMNu9EH4cuyvj17vegnIJGVaQhV8B9BqoC NTPihVLtu0dZI4rX8z55QhqQ4uSfRWcWCd6QOOyEmbgLGs4UFC8IZsqqZsgeSjF992Ud nnkeUUh+Np/kGQNg2IW0dtLQBZ8RnjYvce4WEIKEWeNddybwWOZ09P1nghI5ySouB7qP tHsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=gIm794aXkj6kHE4h6NuMA5WnVVz4m9W6GS8RsB7RY70=; b=aGxcN5vXJ4C5hmwCZpXVTIs46ih2U/+90DEpue5E5Az394bhgke9k+B3mZj9LdlUVr 88YxhmNjMaJL+mWEPLNdOhqtmLGtNkyS1vyFXpRj7Ko3qvH6ulxH6VPRPtC1xuwgttJ8 lwtEmb/FA0wa+Kz0Pii9g7PkTrN3GIiWjG039IJMrltsXb0sSyVAeUrujaOTKq8PLgx7 avLCr5f833HvDEdQjUtue3i79buiXoDE+2dAGdcjJtq9gdYCF7hDp0JZ6lbGKTVUTuOI 1c5n/hJGFKFE/sbhqjj0z1wPGkeT6QmLBAp+laBaGULDxDAUJrTyNSoduRbrP947hJPQ gc3g== X-Gm-Message-State: AOAM532XuB1sb8M2ecA7sSk+3gGRHSsmAvO+xkvJGDus/l1AUQt8etwc LVK47sTAAm0m/7bg74SBp6bMZ42P4RZ/HN2HkFc= X-Google-Smtp-Source: ABdhPJzSAOsKNuawPTs/3MqQVxUR17e/seLQBLbeuNFIFQ1PIHcQPGIi5AowXyTeeYTIvvRthbZ9fw== X-Received: by 2002:a05:651c:513:: with SMTP id o19mr4046729ljp.68.1611694521004; Tue, 26 Jan 2021 12:55:21 -0800 (PST) Received: from hrk1-lhp-F73989.synapse.com ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id o4sm6170lfo.231.2021.01.26.12.55.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 12:55:20 -0800 (PST) From: Roman Kovalivskyi To: u-boot@lists.denx.de Cc: Roman Stratiienko , Joe Hershberger , Roman Kovalivskyi , Simon Glass , Marek Vasut , Lukasz Majewski , Eugeniu Rosca , Alex Kiernan , Sam Protsenko , Neil Armstrong , Philipp Tomsich , Kever Yang , Paul Kocialkowski , Lokesh Vutla , Jagan Teki , Miquel Raynal , Boris Brezillon , Tom Rini , Igor Opaniuk , Aleksandr Bulyshchenko Subject: [PATCH v2 5/7] cmd: bcb: Add support for processing const string literals in bcb_set() Date: Tue, 26 Jan 2021 22:54:54 +0200 Message-Id: <2da216314c820fdf2fa00cb3614c349a27076b32.1611688251.git.roman.kovalivskyi@globallogic.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Tue, 26 Jan 2021 23:18:47 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Eugeniu Rosca On request/suggestion from Simon Glass back in May 22 2019 [1], the 'strsep' mechanism implemented in bcb_set() was set to work directly with user-provided argv strings, to avoid duplicating memory and for the sake of simpler implementation. However, since we recently exposed bcb_write_reboot_reason() API to be called by U-Boot fastboot, the idea is to be able to pass const string literals to this new BCB API, carrying the reboot reason. Since 'strsep' (just like its older/superseded sibling 'strtok') modifies the input string passed as parameter, BCB command in its current state would attempt to perform in-place modifications in a readonly string, which might lead to unexpected results. Fix the above with the cost of one dynamic memory allocation ('strdup'). This will also ensure no compiler warnings when passing string literals to bcb_write_reboot_reason(). [1] http://u-boot.10912.n7.nabble.com/PATCH-v2-0-2-Add-bcb-command-to-read-modify-write-Android-BCB-td369934i20.html#a370456 Cc: Simon Glass Signed-off-by: Eugeniu Rosca Signed-off-by: Roman Kovalivskyi --- cmd/bcb.c | 17 ++++++++++++----- include/bcb.h | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cmd/bcb.c b/cmd/bcb.c index 5da3526142ad..6b6f1e9a2f10 100644 --- a/cmd/bcb.c +++ b/cmd/bcb.c @@ -11,6 +11,7 @@ #include #include #include +#include enum bcb_cmd { BCB_CMD_LOAD, @@ -179,10 +180,10 @@ static int do_bcb_load(struct cmd_tbl *cmdtp, int flag, int argc, return __bcb_load(devnum, argv[2]); } -static int __bcb_set(char *fieldp, char *valp) +static int __bcb_set(char *fieldp, const char *valp) { int size, len; - char *field, *str, *found; + char *field, *str, *found, *tmp; if (bcb_field_get(fieldp, &field, &size)) return CMD_RET_FAILURE; @@ -193,14 +194,20 @@ static int __bcb_set(char *fieldp, char *valp) valp, len, size, fieldp); return CMD_RET_FAILURE; } - str = valp; + str = strdup(valp); + if (!str) { + printf("Error: Out of memory while strdup\n"); + return CMD_RET_FAILURE; + } + tmp = str; field[0] = '\0'; - while ((found = strsep(&str, ":"))) { + while ((found = strsep(&tmp, ":"))) { if (field[0] != '\0') strcat(field, "\n"); strcat(field, found); } + free(str); return CMD_RET_SUCCESS; } @@ -308,7 +315,7 @@ static int do_bcb_store(struct cmd_tbl *cmdtp, int flag, int argc, return __bcb_store(); } -int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp) +int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp) { int ret; diff --git a/include/bcb.h b/include/bcb.h index 05db5935e0e7..c91edb91265a 100644 --- a/include/bcb.h +++ b/include/bcb.h @@ -11,9 +11,9 @@ #include #if CONFIG_IS_ENABLED(CMD_BCB) -int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp); +int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp); #else -static inline int bcb_write_reboot_reason(int devnum, char *partp, char *reasonp) +static inline int bcb_write_reboot_reason(int devnum, char *partp, const char *reasonp) { return -EOPNOTSUPP; } From patchwork Tue Jan 26 20:54:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 1431950 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.a=rsa-sha256 header.s=google header.b=FrYoTh4G; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQLl60zSRz9sVn for ; Wed, 27 Jan 2021 09:20:02 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6B75826B2; Tue, 26 Jan 2021 23:19:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.b="FrYoTh4G"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 11462825F1; Tue, 26 Jan 2021 21:55:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D616782366 for ; Tue, 26 Jan 2021 21:55:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roman.kovalivskyi@globallogic.com Received: by mail-lj1-x22b.google.com with SMTP id t12so5864964ljc.6 for ; Tue, 26 Jan 2021 12:55:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=IgC1K/x6jCNX5cB9+RyRFuPxa99sx7mS80LYraeNOZ8=; b=FrYoTh4GZcVIqTBitndDptclkYmFqOn0dCwym9/p2jiVjbmf3nw2DiVo64XApMKCIw wiFYd/eH3kF6by1yfSXdYB3t29Y9uIZZb0ViBWKqEk1K+to3RM4k/e4mmZdsS2KjK4ll T/huKWfncBhC6u4aYK3cAnqd/p2WXH9wMJidpHroSW/nBu5PzfNkPBt+vlA0nUtoJ+FW xlxXxNXsPGR5vKMXoPdJHvaxIFMbdQWcn5jpSUvHOyb5vm1IBgenubZUTyCaRZYm8iNT UkTH8uNDhwXTbBkZRRAQD5LpWNirgW7bCUoJnnfB8ZcrWOmW/WocESEwq+LQ0lpI5ezy YFOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=IgC1K/x6jCNX5cB9+RyRFuPxa99sx7mS80LYraeNOZ8=; b=UT+TrjLwlOzp7O69htq+Bhs+9Ax5G/k3gVBjAPCW0RjKt42e6L5uKnIwKIg5y8Tgfl o7oe0mePB7xL6mSDzMkaziggchT80gIEAE9fvBNrL0SVYVfkZttHPdAlx0BYTV8j4ZFw otg16IPFKjcajwOUcN1kBfbgEslCCo3eU/VYuCFZ+99fNYni7BbinYFjgaLZ3zQ4Xy2c Lw/37ze47fqBxpfl+eEZa4dBvC4WgrZFnWSYLKbZbKpHb5JCjoyc7nXOBprCCauc35v3 cL8EWcr+5CK3lSaP5ennM6srRcSW1C8vFcNNDWUzSuhVxOv8zVnAa5DoW2b2jQYRHqtO vJ3g== X-Gm-Message-State: AOAM530D7fU0rSS6FcNWTufCFey8FUT3j/5xS02NsD8U8OuqX63jeKQc TElFAH4eKOlQOXF41NvHW1LHPwiZBO3GXmerTiE= X-Google-Smtp-Source: ABdhPJx2N2eI1yQdWkfG03sc+szSYVitG2Xbm+trxf5lJSRZDWDIE2l+AY8f8sfaS07twaizcIn9QA== X-Received: by 2002:a05:651c:151:: with SMTP id c17mr3869632ljd.246.1611694523084; Tue, 26 Jan 2021 12:55:23 -0800 (PST) Received: from hrk1-lhp-F73989.synapse.com ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id o4sm6170lfo.231.2021.01.26.12.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 12:55:22 -0800 (PST) From: Roman Kovalivskyi To: u-boot@lists.denx.de Cc: Roman Stratiienko , Joe Hershberger , Roman Kovalivskyi , Simon Glass , Marek Vasut , Lukasz Majewski , Eugeniu Rosca , Alex Kiernan , Sam Protsenko , Neil Armstrong , Philipp Tomsich , Kever Yang , Paul Kocialkowski , Lokesh Vutla , Jagan Teki , Miquel Raynal , Boris Brezillon , Tom Rini , Igor Opaniuk , Aleksandr Bulyshchenko Subject: [PATCH v2 6/7] Revert "fastboot: Add default fastboot_set_reboot_flag implementation" Date: Tue, 26 Jan 2021 22:54:55 +0200 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Tue, 26 Jan 2021 23:18:47 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean This reverts commit 0ebf9842e56c5b8cb7cb1f990bb452cc14af6225. Current generic implementation of fastboot_set_reboot_flag is somewhat messy and requires some additional configuration option to be enabled besides CMD_BCB, so it reverts that implementtion in order to bring a new cleaner one. Next commit introduces new generic implementation of fastboot_set_reboot_flag. Signed-off-by: Roman Kovalivskyi --- drivers/fastboot/Kconfig | 12 ---------- drivers/fastboot/Makefile | 1 - drivers/fastboot/fb_bcb_impl.c | 43 ---------------------------------- include/fastboot.h | 9 ------- 4 files changed, 65 deletions(-) delete mode 100644 drivers/fastboot/fb_bcb_impl.c diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 4352ba67a713..d4436dfc9173 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -165,18 +165,6 @@ config FASTBOOT_CMD_OEM_FORMAT relies on the env variable partitions to contain the list of partitions as required by the gpt command. -config FASTBOOT_USE_BCB_SET_REBOOT_FLAG - bool "Use BCB by fastboot to set boot reason" - depends on CMD_BCB && !ARCH_MESON && !ARCH_ROCKCHIP && !TARGET_KC1 && \ - !TARGET_SNIPER && !TARGET_AM57XX_EVM && !TARGET_DRA7XX_EVM - default y - help - Fastboot could implement setting of reboot reason in a generic fashion - via BCB commands. BCB commands are able to write reboot reason into - command field of boot control block. In general case it is sufficient - implementation if your platform supports BCB commands and doesn't - require any specific reboot reason handling. - endif # FASTBOOT endmenu diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile index 2b2c390fe4de..048af5aa8234 100644 --- a/drivers/fastboot/Makefile +++ b/drivers/fastboot/Makefile @@ -5,4 +5,3 @@ obj-y += fb_getvar.o obj-y += fb_command.o obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o -obj-$(CONFIG_FASTBOOT_USE_BCB_SET_REBOOT_FLAG) += fb_bcb_impl.o diff --git a/drivers/fastboot/fb_bcb_impl.c b/drivers/fastboot/fb_bcb_impl.c deleted file mode 100644 index 89ec3601b6f6..000000000000 --- a/drivers/fastboot/fb_bcb_impl.c +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright 2020 GlobalLogic. - * Roman Kovalivskyi - */ - -#include -#include - -/** - * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader - * - * Set flag which indicates that we should reboot into the bootloader - * following the reboot that fastboot executes after this function. - * - * This function should be overridden in your board file with one - * which sets whatever flag your board specific Android bootloader flow - * requires in order to re-enter the bootloader. - */ -int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) -{ - char cmd[64]; - - if (reason >= FASTBOOT_REBOOT_REASONS_COUNT) - return -EINVAL; - - snprintf(cmd, sizeof(cmd), "bcb load %d misc", - CONFIG_FASTBOOT_FLASH_MMC_DEV); - - if (run_command(cmd, 0)) - return -ENODEV; - - snprintf(cmd, sizeof(cmd), "bcb set command %s", - fastboot_boot_cmds[reason]); - - if (run_command(cmd, 0)) - return -ENOEXEC; - - if (run_command("bcb store", 0)) - return -EIO; - - return 0; -} diff --git a/include/fastboot.h b/include/fastboot.h index 8e9ee80907df..b86b508e69fd 100644 --- a/include/fastboot.h +++ b/include/fastboot.h @@ -52,15 +52,6 @@ enum fastboot_reboot_reason { FASTBOOT_REBOOT_REASONS_COUNT }; -/** - * BCB boot commands - */ -static const char * const fastboot_boot_cmds[] = { - [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader", - [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot", - [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery" -}; - /** * fastboot_response() - Writes a response of the form "$tag$reason". * From patchwork Tue Jan 26 20:54:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kovalivskyi X-Patchwork-Id: 1431951 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.a=rsa-sha256 header.s=google header.b=MbgyCgxc; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQLlJ347Tz9sVn for ; Wed, 27 Jan 2021 09:20:12 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 70555826D8; Tue, 26 Jan 2021 23:19:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=globallogic.com header.i=@globallogic.com header.b="MbgyCgxc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2AA558263A; Tue, 26 Jan 2021 21:55:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EEE3E82540 for ; Tue, 26 Jan 2021 21:55:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=globallogic.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roman.kovalivskyi@globallogic.com Received: by mail-lj1-x232.google.com with SMTP id c18so8484233ljd.9 for ; Tue, 26 Jan 2021 12:55:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=globallogic.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=NaBDZPPPtwRG0Xx6LJ7VNHNjVmsRBK+h7IksAq3F7fA=; b=MbgyCgxcYO1CAB6d09QT9sLG+xzzS/H3O0fm0p+PBCDRqtNZl5e2ZVsfV+y95PFfAp +pOe1K+gJvEpNiUFzMQTLrChCC86VZYWxt1sPP0KWSMsdDxANsNK5H/d8k5EvPu8vLV/ SchCqxScsZigm0ee5Af8gx/QpnYYztEP3QdOXNoxZjLQmATIYI7qr+UDKbEIU+oKTldw 2eLLDZCe2cF7GU3G4z1vou4yIgttzW5DJKqedU2Q48uvYuHHEsLgo2gApMxHYWN9q2c9 CnsBTJVudxAC15G7nyZLJEI579uwaL5vTbB7Ue3gRLbJlWH8q2Z2cqs1h08Ybc7JI1+Q 8afw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=NaBDZPPPtwRG0Xx6LJ7VNHNjVmsRBK+h7IksAq3F7fA=; b=uSaw0/iWEqWPvnCWPTv0r1riZiRkszhD4VJPAM/U73Ebv7lYeVLBtFCO0OhX8L7uSW K7Gid90JRodgSwib4M7H2OF0DZYv0f/+zk56XWBkkc6A6mydmM83ON87XfZh8CodNvCy G2+xcoPucEsTRzMYw9+jpa27Pw8Epvf020zy8lWaRRdrqxerwY8MP+jbo/EF8OA/1msK CUaIQOF+FHvwn8AERFDmdS1QPjIaeUgHQ6tBpW8+aM+BCN9s9GV+a9XHoerys27pGcnO 8ENIZ2zJF+vPTLRMD/VmRkuMHPy5tIeENaSMldOi23Wsl5gnDc/hhTFkAlCM2K46PX86 pXqQ== X-Gm-Message-State: AOAM532x92AGMjbkeEvCrCziFWvJBKlNfH0YgboWgsI5ML4snslOBlO7 IfGpwjQnd4tj2ciatuoTT9JcjnmnfU8RT0TKO3o= X-Google-Smtp-Source: ABdhPJxsXm5o66K2oNasY2GAfaOp+cIeS7E0CyhpSeKT1t+f+7TN6MF3lCH40BVf8UK7qWPBnCyBEA== X-Received: by 2002:a05:651c:1304:: with SMTP id u4mr3977501lja.146.1611694525148; Tue, 26 Jan 2021 12:55:25 -0800 (PST) Received: from hrk1-lhp-F73989.synapse.com ([159.224.5.60]) by smtp.googlemail.com with ESMTPSA id o4sm6170lfo.231.2021.01.26.12.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 12:55:24 -0800 (PST) From: Roman Kovalivskyi To: u-boot@lists.denx.de Cc: Roman Stratiienko , Joe Hershberger , Roman Kovalivskyi , Simon Glass , Marek Vasut , Lukasz Majewski , Eugeniu Rosca , Alex Kiernan , Sam Protsenko , Neil Armstrong , Philipp Tomsich , Kever Yang , Paul Kocialkowski , Lokesh Vutla , Jagan Teki , Miquel Raynal , Boris Brezillon , Tom Rini , Igor Opaniuk , Aleksandr Bulyshchenko Subject: [PATCH v2 7/7] fastboot: Implement generic fastboot_set_reboot_flag Date: Tue, 26 Jan 2021 22:54:56 +0200 Message-Id: <2c31a988c955a18d9c6a70879b956c5942ebc148.1611688251.git.roman.kovalivskyi@globallogic.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-Mailman-Approved-At: Tue, 26 Jan 2021 23:18:47 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean It is possible to implement fastboot_set_reboot_flag in a generic way if BCB commands are turned on for a target. Using bcb_set_reboot_reason allows to do this by simply passing string with correct reboot reason that should be handled during next boot process. If BCB are turned off, then bcb_set_reboot_reason would simply return error, so it won't introduce any new behaviour for such targets. Signed-off-by: Roman Kovalivskyi --- drivers/fastboot/fb_common.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c index 736ce1cd024f..cbcc3683c471 100644 --- a/drivers/fastboot/fb_common.c +++ b/drivers/fastboot/fb_common.c @@ -10,6 +10,7 @@ * Rob Herring */ +#include #include #include #include @@ -90,7 +91,20 @@ void fastboot_okay(const char *reason, char *response) */ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) { - return -ENOSYS; +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC_DEV) + static const char * const boot_cmds[] = { + [FASTBOOT_REBOOT_REASON_BOOTLOADER] = "bootonce-bootloader", + [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot", + [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery" + }; + + if (reason >= FASTBOOT_REBOOT_REASONS_COUNT) + return -EINVAL; + + return bcb_write_reboot_reason(CONFIG_FASTBOOT_FLASH_MMC_DEV, "misc", boot_cmds[reason]); +#else + return -EINVAL; +#endif } /**