[U-Boot] cmd_date.c error or itention?

Wolfgang Denk wd at denx.de
Mon Jul 5 14:55:53 CEST 2010


Dear "Reinhard Meyer (-VC)",

In message <4C31C596.5020905 at emk-elektronik.de> you wrote:
> 
> cmd_data.c codes the following:
...
> 			rcode = rtc_get (&tm);
> 
> 			if(!rcode) {
> 				/* insert new date & time */
> 				if (mk_date (argv[1], &tm) != 0) {
> 					puts ("## Bad date format\n");
> 					break;
> 				}
> 				/* and write to RTC */
> 				rcode = rtc_set (&tm);
> 				if(rcode)
> 					puts("## Set date failed\n");
> 			} else {
> 				puts("## Get date failed\n");
> 			}
...
> Now I have implemented rtc_get() such that it returns an error code
> when the time is corrupt/has never been set.

It is considered kind of "normal" that a RTC may return "corrupt"
data. This is not an error, as it will be fixed when setting the date.
An error condition is something that really makes the RTC unusable,
like non-functioning communication on the I2C bus (if your RTC is
connected to that), or reading a Low Voltage error status from the RTC
status register, etc.

> However the "if(!rcode)" then prevents the time to be set!

Well, if you cannot eliably communicate with the RTC when reading,
there is little sense trying to write to it - on contrary, this might
even be dangerous.

> Is that intentional and rtc_get() should never return an error ??
> Or is it an oversight, and a patch would be welcome ?

The behaviour is intentional, but rtc_get() can of course return
error codes - only your expectation when this is the case is
different from mine.

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
Misquotation is, in fact, the pride and privilege of the  learned.  A
widely-read  man  never  quotes  accurately,  for  the rather obvious
reason that he has read too widely.
                - Hesketh Pearson _Common Misquotations_ introduction


More information about the U-Boot mailing list