All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: u-boot@lists.denx.de
Subject: [PATCH v2 06/10] rtc: add rtc command
Date: Tue, 2 Jun 2020 11:13:18 +0200	[thread overview]
Message-ID: <3d3529b8-e018-07e8-cbd1-39946d61b2f0@prevas.dk> (raw)
In-Reply-To: <CAPnjgZ2t7-itT7q+ZEqfXVJYkwDL9=FXOqBvcpUBWVfxkzayEQ@mail.gmail.com>

On 31/05/2020 16.07, Simon Glass wrote:
> Hi Rasmus,
> 
> On Tue, 19 May 2020 at 16:01, Rasmus Villemoes
> <rasmus.villemoes@prevas.dk> wrote:
>>

>> +static int do_rtc_read(struct udevice *dev, int argc, char * const argv[])
>> +{
>> +       u8 buf[MAX_RTC_BYTES];
>> +       int reg, len, ret;
>> +       u8 *addr;
>> +
>> +       if (argc < 2 || argc > 3)
>> +               return CMD_RET_USAGE;
>> +
>> +       reg = simple_strtoul(argv[0], NULL, 0);
> 
> I think these should be hex (i.e. 16), since that is the norm in U-Boot.

OK.

>> +       len = simple_strtoul(argv[1], NULL, 0);
>> +       if (argc == 3) {
>> +               addr = map_sysmem(simple_strtoul(argv[2], NULL, 16), len);
>> +       } else {
>> +               if (len > sizeof(buf)) {
>> +                       printf("can read at most %d registers at a time\n", MAX_RTC_BYTES);
> 
> It would be better to loop like print_buffer() does.

Both read and write have been rewritten to avoid that arbitrary limit.

>> +
>> +       if (argc == 2) {
>> +               while (len--)
>> +                       printf("%d: 0x%02x\n", reg++, *addr++);
> 
> Perhaps use print_buffer()?

Done.

>> +               const char *s = argv[1];
>> +
>> +               /* Convert hexstring, bail out if too long. */
>> +               addr = buf;
>> +               len = strlen(s);
>> +               if (len > 2*MAX_RTC_BYTES) {
> 
> Spaces around *
> 
>> +                       printf("hex string too long, can write at most %d bytes\n", MAX_RTC_BYTES);
> 
> Please can you try checkpatch or patman? This lines seems too long

The rewrite to avoid the 32 byte limit made me handle the "argc==3" case
separately (it wasn't worth the complexity trying to stick to just one
rtc_{read,write} call, which also automatically dealt with this one.

>> +
>> +int do_rtc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>> +{
>> +       static int curr_rtc = 0;
>> +       struct udevice *dev;
>> +       int ret, idx;
>> +
>> +       if (argc < 2)
>> +               return CMD_RET_USAGE;
>> +
>> +       argc--;
>> +       argv++;
>> +
>> +       if (!strcmp(argv[0], "list")) {
> 
> It is comment in U-Boot to just check the letters that are needed. So
> here you could do (*argv[0] == 'l')

Yes, and I consider that an anti-pattern. It makes it impossible to
later introduce another (sub)command which starts with a
previously-unique prefix. Now, if that "just type a unique prefix"
wasn't official, so scripts were always supposed to use the full names,
it wouldn't be that big a problem (scripts written for later versions of
U-Boot, or U-Boots configured with more (sub)commands, could still fail
silently if used on an earlier U-Boot or one with fewer (sub)commands
instead of producing a "usage" error message), but
https://www.denx.de/wiki/view/DULG/UBootCommandLineInterface explicitly
mentions that as a feature (and says h can be used for help, which it
can't when the hash command is built in, perfectly exemplifying what I'm
talking about).

Thanks,
Rasmus

  reply	other threads:[~2020-06-02  9:13 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-04 21:20 [PATCH 0/6] rtc: add rtc_{read,write}8_array and rtc command Rasmus Villemoes
2020-05-04 21:20 ` [PATCH 1/6] rtc: add rtc_read8_array helper and ->read8_array method Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-06  8:13     ` Rasmus Villemoes
2020-05-04 21:20 ` [PATCH 2/6] rtc: add rtc_write8_array() helper Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-04 21:20 ` [PATCH 3/6] rtc: fall back to ->{read, write}8_array if ->{read, write}8 are not provided Rasmus Villemoes
2020-05-06  3:42   ` [PATCH 3/6] rtc: fall back to ->{read,write}8_array if ->{read,write}8 " Simon Glass
2020-05-04 21:20 ` [PATCH 4/6] rtc: pcf2127: provide ->read8_array method Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-04 21:20 ` [PATCH 5/6] rtc: pcf2127: provide ->write8_array method Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-04 21:20 ` [PATCH 6/6] rtc: add rtc command Rasmus Villemoes
2020-05-06  3:42   ` Simon Glass
2020-05-19 22:01 ` [PATCH v2 00/10] new rtc methods, rtc command, and tests Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 01/10] rtc: add rtc_read helper and ->read method Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 02/10] rtc: add rtc_write() helper Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 03/10] rtc: fall back to ->{read, write} if ->{read, write}8 are not provided Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 04/10] rtc: pcf2127: provide ->read method Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 05/10] rtc: pcf2127: provide ->write method Rasmus Villemoes
2020-05-19 22:01   ` [PATCH v2 06/10] rtc: add rtc command Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-06-02  9:13       ` Rasmus Villemoes [this message]
2020-06-02 13:22         ` Simon Glass
2020-06-02 14:36           ` Rasmus Villemoes
2020-06-02 19:29             ` Simon Glass
2020-05-19 22:01   ` [PATCH v2 07/10] rtc: sandbox-rtc: fix set method Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-05-19 22:01   ` [PATCH v2 08/10] rtc: i2c_rtc_emul: catch any write to the "reset" register Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-05-19 22:01   ` [PATCH v2 09/10] test: dm: rtc: add test of rtc_read, rtc_write Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-05-19 22:01   ` [PATCH v2 10/10] test: dm: rtc: add tests of rtc shell command Rasmus Villemoes
2020-05-31 14:07     ` Simon Glass
2020-06-02  9:15       ` Rasmus Villemoes
2020-06-02 18:40   ` [PATCH v2 00/10] new rtc methods, rtc command, and tests Rasmus Villemoes
2020-06-02 19:29     ` Simon Glass
2020-06-02 19:44       ` Rasmus Villemoes
2020-06-02 20:56         ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3d3529b8-e018-07e8-cbd1-39946d61b2f0@prevas.dk \
    --to=rasmus.villemoes@prevas.dk \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.