All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/6] Convert fw_env.c to use a single environment image union
Date: Sun, 31 Aug 2008 20:57:37 +0200	[thread overview]
Message-ID: <20080831185737.3E115242FF@gemini.denx.de> (raw)
In-Reply-To: <Pine.LNX.4.64.0808311740070.3747@axis700.grange>

Dear Guennadi Liakhovetski,

In message <Pine.LNX.4.64.0808311740070.3747@axis700.grange> you wrote:
> 
> This union replaces the typedef env_t, which was also defined in fw_env.c. 
> Thus I was not fixing the issue you describe above, which I fully agree 
> with - the tool and u-boot should ideally use the same definition from a 
> common header. I just did not address this issue in this patch series.

This is not correct. You are creating this issue. So far, U-Boot and
fw_env used to use the same (or at least equivalent) definitions.

And I have to admit that I'm not a friend of using unions. They are a
great way to obfuscate code.

> > I think both sets of functions should use the same set of definitions
> > (yes, I am aware that  this  requires  chnages  to  "include/environ-
> > ment.h").
> 
> Would be good, yes, the question is - do we want to do this now and do we 
> want to do this in the scope of this patch series?

If there is no real need to change it now, then leave it unchanged?

> > Please stick with the typedef.
...
> and Linux explicitly discourages typedef. They also produce warnings by 
> checkpatch.sh. If this is also different in U-Boot, no problem, can change 
> back.

Ah! And why didn't you mention this in the patch?

For a reviewer it is very important to understand why you are
modifying code.


> > > -	/* Update CRC */
> > > -	environment.crc = crc32 (0, (uint8_t*) environment.data, ENV_SIZE);
> > > +	/*
> > > +	 * Update CRC: it is at the same location with and without the
> > > +	 * redundant environment
> > > +	 */
> > > +	environment.image->single.crc = crc32 (0, (uint8_t *) environment.data,
> > > +					       ENV_SIZE);
> > 
> > The comment is wrong. Without redundant environment, the CRC is at
> > offset 4 from the start of the environment storage, and with
> > redundancy it's at offset 5. This is definitely not the same location.
> 
> I think, CRC is always at offset 0, then follows the (optional) flag byte, 

Yes, you are right.

> and then comes the data. I also see this with binary dumps of the 
> environment. Otherwise what takes the first four bytes? Or did you mean 
> the data which CRC is calculated is at offset 4 or 5? I think, the comment 
> is correct.

And we see the obfuscation caused by using a union.

> > Also, the code does not match the commend, since you access
> > "single.crc" which has no relation to redundant environment
> > at all.
> 
> That's exactly the reason - the comment explains, that the crc is at the 
> same location, so, you can access it using single.crc in both cases.

This is ugly, plain ugly.

> > Looking at the rest of the code I see no  improvement  in  using  the
> > union  versus  what  we did before - the code is even longer now, and
> > (slightly) less readable to me.
> 
> I need it to be able to copy the whole environment image, including the 
> crc and the optional flag with one read / write / memcpy operation. And 

Hm... why do you need to do this in a single read operation?  Where's
the  difference  between reading it all at once or in several smaller
chunks?

> this is also an advantage even on NOR - no need for two or three syscalls, 
> the whole image is read / written with one syscall.

A big win, really ;-)

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
How long does it take a  DEC  field  service  engineer  to  change  a
lightbulb?       It depends on how many bad ones he brought with him.

  reply	other threads:[~2008-08-31 18:57 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-27 15:52 [U-Boot] [PATCH 0/6] Support NAND in fw_printenv/fw_setenv Guennadi Liakhovetski
2008-08-27 15:52 ` [U-Boot] [PATCH 1/6] Convert fw_env.c to use a single environment image union Guennadi Liakhovetski
2008-08-31 14:36   ` Wolfgang Denk
2008-08-31 15:57     ` Guennadi Liakhovetski
2008-08-31 18:57       ` Wolfgang Denk [this message]
2008-08-27 15:52 ` [U-Boot] [PATCH 2/6] Separate flash read and write operations Guennadi Liakhovetski
2008-08-31 14:58   ` Wolfgang Denk
2008-08-31 16:04     ` Guennadi Liakhovetski
2008-08-31 18:57       ` Wolfgang Denk
2008-08-31 19:45         ` Guennadi Liakhovetski
2008-08-31 19:56           ` Wolfgang Denk
2008-08-27 15:52 ` [U-Boot] [PATCH 3/6] "return" is not a function Guennadi Liakhovetski
2008-08-31 14:59   ` Wolfgang Denk
2008-08-31 16:10     ` Guennadi Liakhovetski
2008-08-31 18:57       ` Wolfgang Denk
2008-08-31 19:17         ` Guennadi Liakhovetski
2008-08-27 15:52 ` [U-Boot] [PATCH 4/6] Unify active vs. redundant environment variable naming Guennadi Liakhovetski
2008-08-31 15:04   ` Wolfgang Denk
2008-08-31 16:18     ` Guennadi Liakhovetski
2008-08-31 18:57       ` Wolfgang Denk
2008-08-31 19:27         ` Guennadi Liakhovetski
2008-08-31 19:44           ` Wolfgang Denk
2008-08-27 15:52 ` [U-Boot] [PATCH 5/6] Support environment anywhere within erase area Guennadi Liakhovetski
2008-08-31 18:57   ` Wolfgang Denk
2008-08-31 19:39     ` Guennadi Liakhovetski
2008-08-31 19:53       ` Wolfgang Denk
2008-08-27 15:52 ` [U-Boot] [PATCH 6/6] Support environment in NAND Guennadi Liakhovetski
2008-08-29  9:29   ` [U-Boot] [PATCH 6/6 v2] " Guennadi Liakhovetski
2008-08-31 18:57   ` [U-Boot] [PATCH 6/6] " Wolfgang Denk
2008-08-31 21:53     ` Guennadi Liakhovetski
2008-08-31 20:21 ` [U-Boot] [PATCH 0/6] Support NAND in fw_printenv/fw_setenv Wolfgang Denk
2008-08-31 20:37   ` Guennadi Liakhovetski
2008-08-31 20:55     ` Wolfgang Denk
2008-09-01  9:08       ` Guennadi Liakhovetski
2008-09-01  9:31         ` Guennadi Liakhovetski
2008-09-01 22:42           ` Wolfgang Denk
2008-09-01 22:41         ` Wolfgang Denk
2008-09-01 23:33           ` Guennadi Liakhovetski
2008-09-02  0:13             ` Wolfgang Denk
2008-09-02 16:00   ` Guennadi Liakhovetski

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=20080831185737.3E115242FF@gemini.denx.de \
    --to=wd@denx.de \
    --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.