From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7E5A4ECAAD2 for ; Mon, 29 Aug 2022 14:54:41 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 988DF845F8; Mon, 29 Aug 2022 16:54:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="Djz1nOFk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8B56384925; Mon, 29 Aug 2022 16:54:37 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 31F3683AD1 for ; Mon, 29 Aug 2022 16:54:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1661784873; bh=oardJSNiKo9sLK+NyuEbdH17FPQUr9Ygx6ZmlJoKY3c=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=Djz1nOFkZxzPQk5l3HuMzr74ddjfhFQzCv11awFF9XxVEL872iFX1NdW5ooJzKj9Z moWM24A6uVLCFSs0QbBIz8jDUY0s6xOzEPHBDm0KF4T2Vv9+3rWzFOnIxGnIBncTfb WzEA36BVF86antIKwb+L5M8146mVXPVnoPkOgmhg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.67] ([84.118.157.2]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N3siG-1pS6Uz1VIG-00zrJ3; Mon, 29 Aug 2022 16:54:33 +0200 Message-ID: Date: Mon, 29 Aug 2022 16:54:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH v2] xyz-modem: Allow to configure initial timeout for loadx and loady Content-Language: en-US To: =?UTF-8?Q?Pali_Roh=c3=a1r?= Cc: u-boot@lists.denx.de, Wolfgang Denk , Simon Glass , Tom Rini References: <20210910204653.3066-1-pali@kernel.org> <20220827114835.22584-1-pali@kernel.org> From: Heinrich Schuchardt In-Reply-To: <20220827114835.22584-1-pali@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Gh1T2z2xFjWVyANphubpiMTfpoV7QYj+y5upwulIlB08wb9yP6Z ZFtSw0LM1MH//e9gx5HeYdRzCFQ7t6W0bJBWtXanY/yhBVG1+OAcKC53bSlAhG0xh6mq+Tq yT9CeKVUX6/8TKKCOymtgz+9SMy+fsmuEcFKqsuCBuH4+0DhX+WE7OCYepa3SxRXErUf50e m0wVkFegES/uVNGNzbcOQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:z4fCKWlY8JE=:1PubTmuFCYmVS8ehOLnU6G AAN4FDdmHjvKxzvweyOfe+4b4Os6Qi71w5YG8BrzfkaoEOiA7g5e/A0uakV7yZuvN3py50Rq8 PFLHJ4EvpD8nzQc4Myg1W5LVkz5nzmOwGeLI2v8r9fjydDH61eW7G6NDbWpxFqRZ5CyvPj9LE qGerG05M0YTxBnBwc+v6ap8ntZeXhKYw2ogJoILouOQHO0yV34KRO172lMnD6Pcef5eebBbi8 gouF6IccqtVAm3tDouIMz83Y7qTLpkyDyw7CW7cg164WlFv5GJPW0I6B1S3KrGXy5RAmGD7HD /b8Z8MxGgYBPpQWtr4Qj+ch8D6tb+JboHiTIgTgwDfIGdqsoj4yrpB5JC/BnE1KtDqbLPn68K doCLA+6xlO2Iust+0q0tFEtN8Dxp53mgvB19zifDm/blS8SjiaGvtXYCP/3JgO/YQop9mVcs/ FNoP0UCQmfUCu7DN8FvA5jUl232MBbNfobM+XcedJeGB2eENnX7W4zP0rvHKPML444tPM6EV0 0C0G6mC5qZQKom3EWdFt1vBzAjhv4AIY8/O9IS+KQ+hd+ZjR8SVx7WnD8m7zC7/466YcyQvMa P9gIfBJUfVEbutNy/VeSLvtGE+qZc2xlaazXsoFsZay0Y+H8VT560Pck0t0MOkiZXgQ9H6BH8 dmOWjlN3WAnZJS4V8aIxN/rU+A8xZ655B+vWQIoJBk2yX+pvf//zs7aTR/PziEQrGfXROtQTV fqC0XMiVb3dxy3UJHMSF4UNEvDU4aRecCv3kmgKqXJQCh6aW4EdeaoGzvpX+2Nwggw3aD3lFZ rlFXRfBvzNaKFxzMISamGYUiq2WWeWnvlc3GLy1uxgn6+iJaWndFFxO2vSRxx59s0YJx2aoRT wzCfsmHcnMg+p8QUczLui4x8M8saJnLOYEkuZJHipTLmO6Ad+meIEpomgwg0r5c9IQGFZBNjN tDYdxbHiUeufFp3zYEaOlftIbkJrp01fw95T8b9/rvLlaXipKeXAi0X6BHgrzPG1aijJKXqSf ZinECtWrWf7/gLTVKMW5ne+iBPo8TYc9eW+Nlv5w4D6VQOAQvDiE/H4X4a5JgmepfUveFmybJ 2S6FP3OZ8bRwj90pTUSN+Zyu+ppAIBh9EARPRo6/BcL4VldiHeOG2WCuA== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean On 8/27/22 13:48, Pali Roh=C3=A1r wrote: > Now when loadx and loady commands could be aborted / cancelled by CTRL+C= , > allow to configure timeout for initial x/y-modem packet via env variable > $loadxy_timeout and by default use value from new compile-time config > option CONFIG_CMD_LOADXY_TIMEOUT. Value is in seconds and zero value mea= ns > infinite timeout. Default value is 90s which is the measured value used > before this change for loadx and loady commands. > > Other load commands loadb and loads already waits infinitely. Same behav= ior > for loadx and loady commands can be achieved by setting $loadxy_timeout = or > CONFIG_CMD_LOADXY_TIMEOUT to 0. > > Signed-off-by: Pali Roh=C3=A1r > --- > Changes in v2: > * Allow to set timeout via env instead of permanent infinite timeout > --- > cmd/Kconfig | 7 +++++++ > common/xyzModem.c | 39 +++++++++++++++++++++++++++++++++++++-- The environment variable should be described in doc/usage/cmd/loady.rst Best regards Heinrich > 2 files changed, 44 insertions(+), 2 deletions(-) > > diff --git a/cmd/Kconfig b/cmd/Kconfig > index 211ebe9c8783..54af3769a673 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -1194,6 +1194,13 @@ config CMD_LOADS > help > Load an S-Record file over serial line > > +config CMD_LOADXY_TIMEOUT > + int "loadxy_timeout" > + range 0 2000 > + default 90 > + help > + Initial timeout for loadx and loady commands. Zero means infinity. > + > config CMD_LSBLK > depends on BLK > bool "lsblk - list block drivers and devices" > diff --git a/common/xyzModem.c b/common/xyzModem.c > index ece25acb183b..700df8edd14a 100644 > --- a/common/xyzModem.c > +++ b/common/xyzModem.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > > /* Assumption - run xyzModem protocol over the console port */ > > @@ -50,6 +51,8 @@ static struct > int len, mode, total_retries; > int total_SOH, total_STX, total_CAN; > bool crc_mode, at_eof, tx_ack; > + bool first_xmodem_packet; > + ulong initial_time, timeout; > unsigned long file_length, read_length; > } xyz; > > @@ -409,6 +412,18 @@ xyzModem_get_hdr (void) > return 0; > } > > +static > +ulong > +xyzModem_get_initial_timeout (void) > +{ > + /* timeout is in seconds, non-positive timeout value is infinity */ > + const char *timeout_str =3D env_get("loadxy_timeout"); > + if (timeout_str) > + return 1000 * simple_strtol(timeout_str, NULL, 10); > + else > + return 1000 * CONFIG_CMD_LOADXY_TIMEOUT; > +} > + > int > xyzModem_stream_open (connection_info_t * info, int *err) > { > @@ -439,18 +454,28 @@ xyzModem_stream_open (connection_info_t * info, in= t *err) > xyz.total_CAN =3D 0; > xyz.read_length =3D 0; > xyz.file_length =3D 0; > + xyz.first_xmodem_packet =3D false; > + xyz.initial_time =3D get_timer(0); > + xyz.timeout =3D xyzModem_get_initial_timeout(); > > CYGACC_COMM_IF_PUTC (*xyz.__chan, (xyz.crc_mode ? 'C' : NAK)); > > if (xyz.mode =3D=3D xyzModem_xmodem) > { > /* X-modem doesn't have an information header - exit here */ > + xyz.first_xmodem_packet =3D true; > xyz.next_blk =3D 1; > return 0; > } > > - while (retries-- > 0) > + while (!(xyz.timeout && get_timer(xyz.initial_time) > xyz.timeout)) > { > + if (--retries <=3D 0) > + { > + retries =3D xyzModem_MAX_RETRIES; > + crc_retries =3D xyzModem_MAX_RETRIES_WITH_CRC; > + xyz.crc_mode =3D true; > + } > stat =3D xyzModem_get_hdr (); > if (stat =3D=3D 0) > { > @@ -503,9 +528,19 @@ xyzModem_stream_read (char *buf, int size, int *err= ) > retries =3D xyzModem_MAX_RETRIES; > while (retries-- > 0) > { > + if (xyz.first_xmodem_packet && xyz.timeout && > + get_timer(xyz.initial_time) > xyz.timeout) > + { > + *err =3D xyzModem_timeout; > + xyz.len =3D -1; > + return total; > + } > + > stat =3D xyzModem_get_hdr (); > if (stat =3D=3D 0) > { > + if (xyz.mode =3D=3D xyzModem_xmodem && xyz.first_xmodem_packet) > + xyz.first_xmodem_packet =3D false; > if (xyz.blk =3D=3D xyz.next_blk) > { > xyz.tx_ack =3D true; > @@ -583,7 +618,7 @@ xyzModem_stream_read (char *buf, int size, int *err) > xyz.total_retries++; > ZM_DEBUG (zm_dprintf ("NAK (%d)\n", __LINE__)); > } > - if (stat < 0) > + if (stat < 0 && (!xyz.first_xmodem_packet || stat !=3D xyzModem_time= out)) > { > *err =3D stat; > xyz.len =3D -1;