Get number of seconds since beginning of epoch

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get number of seconds since beginning of epoch

Jonas Mark (ST-FIR/ENG1)
Hi,

I am wondering whether U-Boot already has the functionality to retrieve the number of seconds since beginning of the 1970-01-01 epoch. I would like to use this value in a Hush script.

For a product I have the requirement to detect if the current booting happens within x seconds of the last boot. I already have access to the system’s RTC and can read it with U-Boot’s date command. This returns the current date and time in a nice human readable format. I am now looking for something which would return a timestamp in seconds. I could then fulfill the afore mentioned requirement by calculating the difference between two timestamps using Hush and the let command.

Alternative proposals how to fulfill the requirement within U-Boot are welcome, too. ☺

Best regards,
Mark

Building Technologies, Panel Software Fire (BT-FIR/ENG1)
Bosch Sicherheitssysteme GmbH | Postfach 11 11 | 85626 Grasbrunn | GERMANY | www.boschsecurity.com

Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart HRB 23118
Aufsichtsratsvorsitzender: Stefan Hartung; Geschäftsführung: Tanja Rückert, Andreas Bartz, Thomas Quante, Bernhard Schuster



_______________________________________________
U-Boot mailing list
[hidden email]
https://lists.denx.de/listinfo/u-boot
Reply | Threaded
Open this post in threaded view
|

Re: Get number of seconds since beginning of epoch

Wolfgang Denk
Hallo Mark,

In message <[hidden email]> you wrote:
>
> I am wondering whether U-Boot already has the functionality to
> retrieve the number of seconds since beginning of the 1970-01-01
> epoch. I would like to use this value in a Hush script.

There is no such feature in U-Boot (yet).

> Alternative proposals how to fulfill the requirement within U-Boot are welcome, too. ☺

There is no trivial way, as such information is not stored in typich
RTCs; it has to be computed from the information we have.  The
algorithm could be copied from existing code (GNU or BusyBox date
command for example) and added as an (optional, i. e. configurable)
extension to the U-Boot date command.

Note that such an extension would have to store the result in an
environment variable, as we don't have command substituation or
such in U-Boot's shells.

You know where you can ask for help :-)

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [hidden email]
A failure will not appear until a unit has passed final inspection.
_______________________________________________
U-Boot mailing list
[hidden email]
https://lists.denx.de/listinfo/u-boot