Skip to contentSkip to conversation

add rtc support

RFC Superseded Antony Pavlov 3 participants 18 messages Jul 14, 2014 – Jul 25, 2014

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover add rtc support

Chages since RFC v2:

* rtc/Kconfig: fix formatting, dependencies and help sections;
* hwclock: read time into environment variable.

Chages since RFC v1:

* rebase over latest 'next';
* fix copy'n'paste side effects;
* add hwclock set time function;
* make hwclock options more close to util-linux hwclock;
* rtc-ds1307: add ds1338 chip support (used in versatile);
* use qemu-versatile for testing.

Antony Pavlov (5):
lib: import 'bcd' from linux-3.15
add rtc support
rtc: import ds1307 driver from linux-3.15
commands: add hwclock
ARM: versatilepb_defconfig: enable RTC support

 arch/arm/configs/versatilepb_defconfig |   2 +
 commands/Kconfig                       |   8 +
 commands/Makefile                      |   1 +
 commands/hwclock.c                     | 151 +++++++++++++++
 drivers/Kconfig                        |   1 +
 drivers/Makefile                       |   1 +
 drivers/rtc/Kconfig                    |  37 ++++
 drivers/rtc/Makefile                   |  10 +
 drivers/rtc/class.c                    |  53 +++++
 drivers/rtc/rtc-ds1307.c               | 345 +++++++++++++++++++++++++++++++++
 drivers/rtc/rtc-lib.c                  |  66 +++++++
 include/linux/bcd.h                    |  22 +++
 include/linux/rtc.h                    |  46 +++++
 include/rtc.h                          |   2 +
 lib/Makefile                           |   1 +
 lib/bcd.c                              |  14 ++
 16 files changed, 760 insertions(+)
 create mode 100644 commands/hwclock.c
 create mode 100644 drivers/rtc/Kconfig
 create mode 100644 drivers/rtc/Makefile
 create mode 100644 drivers/rtc/class.c
 create mode 100644 drivers/rtc/rtc-ds1307.c
 create mode 100644 drivers/rtc/rtc-lib.c
 create mode 100644 include/linux/bcd.h
 create mode 100644 include/linux/rtc.h
 create mode 100644 lib/bcd.c
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

RFC v3 1/5 lib: import 'bcd' from linux-3.15

---
 include/linux/bcd.h | 22 ++++++++++++++++++++++
 lib/Makefile        |  1 +
 lib/bcd.c           | 14 ++++++++++++++
 3 files changed, 37 insertions(+)
include/linux/bcd.h new file +22 -0
new file mode 100644
index 0000000..18fff11
@@ -0,0 +1,22 @@
+#ifndef _BCD_H
+#define _BCD_H
+
+#include <linux/compiler.h>
+
+#define bcd2bin(x)					\
+		(__builtin_constant_p((u8 )(x)) ?	\
+		const_bcd2bin(x) :			\
+		_bcd2bin(x))
+
+#define bin2bcd(x)					\
+		(__builtin_constant_p((u8 )(x)) ?	\
+		const_bin2bcd(x) :			\
+		_bin2bcd(x))
+
+#define const_bcd2bin(x)	(((x) & 0x0f) + ((x) >> 4) * 10)
+#define const_bin2bcd(x)	((((x) / 10) << 4) + (x) % 10)
+
+unsigned _bcd2bin(unsigned char val) __attribute_const__;
+unsigned char _bin2bcd(unsigned val) __attribute_const__;
+
+#endif /* _BCD_H */
lib/Makefile +1 -0
index 48c953d..18a99a7 100644
@@ -1,3 +1,4 @@
+obj-y			+= bcd.o
 obj-$(CONFIG_BOOTSTRAP)	+= bootstrap/
 obj-y			+= ctype.o
 obj-y			+= rbtree.o
lib/bcd.c new file +14 -0
new file mode 100644
index 0000000..b072d50
@@ -0,0 +1,14 @@
+#include <linux/bcd.h>
+#include <module.h>
+
+unsigned _bcd2bin(unsigned char val)
+{
+	return (val & 0x0f) + (val >> 4) * 10;
+}
+EXPORT_SYMBOL(_bcd2bin);
+
+unsigned char _bin2bcd(unsigned val)
+{
+	return ((val / 10) << 4) + val % 10;
+}
+EXPORT_SYMBOL(_bin2bcd);
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

RFC v3 2/5 add rtc support

In reply to Antony Pavlov
---
 drivers/Kconfig       |  1 +
 drivers/Makefile      |  1 +
 drivers/rtc/Kconfig   | 15 ++++++++++++
 drivers/rtc/Makefile  |  6 +++++
 drivers/rtc/class.c   | 53 +++++++++++++++++++++++++++++++++++++++++
 drivers/rtc/rtc-lib.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/rtc.h   | 46 +++++++++++++++++++++++++++++++++++
 include/rtc.h         |  2 ++
 8 files changed, 190 insertions(+)
drivers/Kconfig +1 -0
index 12a9d8c..d38032c 100644
@@ -28,5 +28,6 @@ source "drivers/bus/Kconfig"
 source "drivers/regulator/Kconfig"
 source "drivers/reset/Kconfig"
 source "drivers/pci/Kconfig"
+source "drivers/rtc/Kconfig"
 
 endmenu
drivers/Makefile +1 -0
index 1990e86..4591f9a 100644
@@ -27,3 +27,4 @@ obj-y += bus/
 obj-$(CONFIG_REGULATOR) += regulator/
 obj-$(CONFIG_RESET_CONTROLLER) += reset/
 obj-$(CONFIG_PCI) += pci/
+obj-y += rtc/
drivers/rtc/Kconfig new file +15 -0
new file mode 100644
index 0000000..5401503
@@ -0,0 +1,15 @@
+#
+# RTC class/drivers configuration
+#
+
+config RTC_LIB
+	bool
+
+menuconfig RTC_CLASS
+	bool "Real Time Clock"
+	default n
+	select RTC_LIB
+	help
+	  Generic RTC class support. If you say yes here, you will
+	  be allowed to plug one or more RTCs to your system. You will
+	  probably want to enable one or more of the interfaces below.
drivers/rtc/Makefile new file +6 -0
new file mode 100644
index 0000000..7d1b5bc
@@ -0,0 +1,6 @@
+#
+# Makefile for RTC class/drivers.
+#
+
+obj-$(CONFIG_RTC_LIB)           += rtc-lib.o
+obj-$(CONFIG_RTC_CLASS)         += class.o
drivers/rtc/class.c new file +53 -0

53 lines not on this page · raw message

drivers/rtc/rtc-lib.c new file +66 -0

66 lines not on this page · raw message

include/linux/rtc.h new file +46 -0

46 lines not on this page · raw message

include/rtc.h +2 -0
index c2d8bce..e2414fb 100644
@@ -53,4 +53,6 @@ void to_tm (int, struct rtc_time *);
 unsigned long mktime (unsigned int, unsigned int, unsigned int,
 		      unsigned int, unsigned int, unsigned int);
 
+extern struct rtc_device *rtc_lookup(const char *name);
+
 #endif	/* _RTC_H_ */
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

RFC v3 3/5 rtc: import ds1307 driver from linux-3.15

In reply to Antony Pavlov

Current ds1307 rtc driver supports only ds1307 and ds1338 chips; it has no nvram support at the moment.

---
 drivers/rtc/Kconfig      |  22 +++
 drivers/rtc/Makefile     |   4 +
 drivers/rtc/rtc-ds1307.c | 345 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 371 insertions(+)
drivers/rtc/Kconfig +22 -0
index 5401503..c2b3764 100644
@@ -13,3 +13,25 @@ menuconfig RTC_CLASS
 	  Generic RTC class support. If you say yes here, you will
 	  be allowed to plug one or more RTCs to your system. You will
 	  probably want to enable one or more of the interfaces below.
+
+if RTC_CLASS
+
+comment "I2C RTC drivers"
+	depends on I2C
+
+if I2C
+
+config RTC_DRV_DS1307
+	tristate "Dallas/Maxim DS1307/38"
+	help
+	  If you say yes here you get support for various compatible RTC
+	  chips (often with battery backup) connected with I2C. This driver
+	  should handle DS1307, DS1338 and probably other chips.
+
+	  The first seven registers on these chips hold an RTC, and other
+	  registers may add features such as NVRAM, a trickle charger for
+	  the RTC/NVRAM backup power, and alarms.
+
+endif # I2C
+
+endif # RTC_CLASS
drivers/rtc/Makefile +4 -0
index 7d1b5bc..2c5a50e 100644
@@ -4,3 +4,7 @@
 
 obj-$(CONFIG_RTC_LIB)           += rtc-lib.o
 obj-$(CONFIG_RTC_CLASS)         += class.o
+
+# Keep the list ordered.
+
+obj-$(CONFIG_RTC_DRV_DS1307)    += rtc-ds1307.o
drivers/rtc/rtc-ds1307.c new file +345 -0

345 lines not on this page · raw message

Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

RFC v3 4/5 commands: add hwclock

In reply to Antony Pavlov

The hwclock command allows to query or set the hardware clock (RTC).

---
 commands/Kconfig   |   8 +++
 commands/Makefile  |   1 +
 commands/hwclock.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+)
commands/Kconfig +8 -0
index 61816f5..6a75f85 100644
@@ -1691,6 +1691,14 @@ config CMD_GPIO
 
 	  Usage: gpio_set_value GPIO VALUE
 
+config CMD_HWCLOCK
+	bool
+	depends on RTC_CLASS
+	prompt "hwclock command"
+	default y
+	help
+	  The hwclock command allows to query or set the hardware clock (RTC).
+
 config CMD_I2C
 	bool
 	depends on I2C
commands/Makefile +1 -0
index d42aca5..44dd9d4 100644
@@ -100,3 +100,4 @@ obj-$(CONFIG_CMD_MENUTREE)	+= menutree.o
 obj-$(CONFIG_CMD_2048)		+= 2048.o
 obj-$(CONFIG_CMD_REGULATOR)	+= regulator.o
 obj-$(CONFIG_CMD_LSPCI)		+= lspci.o
+obj-$(CONFIG_CMD_HWCLOCK)	+= hwclock.o
commands/hwclock.c new file +151 -0

151 lines not on this page · raw message

Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

Re: [RFC v3 4/5] commands: add hwclock

Quoted 162 lines · Antony Pavlov

The hwclock command allows to query or set the hardware clock (RTC).

---
 commands/Kconfig   |   8 +++
 commands/Makefile  |   1 +
 commands/hwclock.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+)
commands/Kconfig +8 -0
index 61816f5..6a75f85 100644
@@ -1691,6 +1691,14 @@ config CMD_GPIO
 
 	  Usage: gpio_set_value GPIO VALUE
 
+config CMD_HWCLOCK
+	bool
+	depends on RTC_CLASS
+	prompt "hwclock command"
+	default y
+	help
+	  The hwclock command allows to query or set the hardware clock (RTC).
+
 config CMD_I2C
 	bool
 	depends on I2C
commands/Makefile +1 -0
index d42aca5..44dd9d4 100644
@@ -100,3 +100,4 @@ obj-$(CONFIG_CMD_MENUTREE)	+= menutree.o
 obj-$(CONFIG_CMD_2048)		+= 2048.o
 obj-$(CONFIG_CMD_REGULATOR)	+= regulator.o
 obj-$(CONFIG_CMD_LSPCI)		+= lspci.o
+obj-$(CONFIG_CMD_HWCLOCK)	+= hwclock.o
commands/hwclock.c new file +119 -0
new file mode 100644
index 0000000..511973a
@@ -0,0 +1,151 @@
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+#include <rtc.h>
+#include <linux/rtc.h>
+#include <string.h>
+#include <environment.h>
+
+static char *strchrnul(const char *s, int c)
+{
+	while (*s != '\0' && *s != c)
+		s++;
+
+	return (char *)s;
+}
+
+static int sscanf_two_digits(char *s, int *res)
+{
+	char buf[3];
+	unsigned long t;
+
+	if (!isdigit(s[0]) || !isdigit(s[1])) {
+		return -EINVAL;
+	}
+
+	buf[0] = s[0];
+	buf[1] = s[1];
+	buf[2] = '\0';
+
+	t = simple_strtoul(buf, NULL, 10);
+	*res = t;
+
+	return 0;
+}
+
+static int parse_datestr(char *date_str, struct rtc_time *ptm)
+{
+	char end = '\0';
+	int len = strchrnul(date_str, '.') - date_str;
+	int year;
+
+	/* ccyymmddHHMM[.SS] */
+	if (len != 12) {
+		return -EINVAL;
+	}
+
+	if (sscanf_two_digits(date_str, &year) ||
+		sscanf_two_digits(&date_str[2], &ptm->tm_year)) {
+		return -EINVAL;
+	}
+
+	ptm->tm_year = year * 100 + ptm->tm_year;
+
+	/* Adjust years */
+	ptm->tm_year -= 1900;
+
+	if (sscanf_two_digits(&date_str[4], &ptm->tm_mon) ||
+		sscanf_two_digits(&date_str[6], &ptm->tm_mday) ||
+		sscanf_two_digits(&date_str[8], &ptm->tm_hour) ||
+		sscanf_two_digits(&date_str[10], &ptm->tm_min)) {
+		return -EINVAL;
+	}
+
+	/* Adjust month from 1-12 to 0-11 */
+	ptm->tm_mon -= 1;
+
+	end = date_str[12];
+
+	if (end == '.') {
+		/* xxx.SS */
+		if (!sscanf_two_digits(&date_str[13], &ptm->tm_sec)) {
+			end = '\0';
+		}
+		/* else end != NUL and we error out */
+	}
+
+	if (end != '\0') {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int do_hwclock(int argc, char *argv[])
+{
+	struct rtc_device *r;
+	struct rtc_time tm;
+	struct rtc_time stm;
+	char rtc_name[16] = "rtc0";
+	char *env_name = NULL;
+	int opt;
+	int set = 0;
+
+	while ((opt = getopt(argc, argv, "f:s:e:")) > 0) {
+		switch (opt) {
+		case 'f':
+			strncpy(rtc_name, optarg, 16);
+			break;
+		case 's':
+			memset(&stm, 0, sizeof(stm));
+			parse_datestr(optarg, &stm);
+			set = 1;
+			break;
+		case 'e':
+			env_name = optarg;
+			break;
+		}
+	}
+
+	r = rtc_lookup(rtc_name);
+	if (IS_ERR(r))
+		return PTR_ERR(r);
+
+	if (set) {
+		rtc_set_time(r, &stm);
+		return 0;
+	}

commands/hwclock.c line 129

Quoted 10 lines
commands/hwclock.c new file +10 -0
+
+	rtc_read_time(r, &tm);
+
+	if (env_name) {
+		unsigned long time;
+		char t[12];
+
+		rtc_tm_to_time(&tm, &time);
+		snprintf(t, 12, "%lu", time);
+		setenv(env_name, t);

I thought more about a globalvar_add(), like globalvar.date, so that no command has to be executed to get the date. But then again maybe it's better to have it in a command since it allows us to add different formats without much hassle.

Quoted 4 lines
commands/hwclock.c new file +4 -0
+	} else {
+		printf("%02d:%02d:%02d %02d-%02d-%04d\n",
+			tm.tm_hour, tm.tm_min, tm.tm_sec,
+			tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);

commands/hwclock.c line 143

Quoted 10 lines
commands/hwclock.c new file +10 -0
+	}
+
+	return 0;
+}
+
+BAREBOX_CMD_HELP_START(hwclock)
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-f NAME\t\t\t", "RTC device name (default rtc0)")
+BAREBOX_CMD_HELP_OPT ("-e VARNAME\t\t", "store RTC readout into variable VARNAME")
+BAREBOX_CMD_HELP_OPT ("-s ccyymmddHHMM[.SS]\t", "set time")

It's much more logical to have the year first, but the format documented in 'man date' is MMDDhhmm[[CC]YY][.ss]. Of course we are free to choose another format, but maybe we should rather use a format someone other uses aswell?

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

Re: [RFC v3 4/5] commands: add hwclock

Quoted 190 lines · On Fri, 18 Jul 2014 07:44:13 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 162 lines · Antony Pavlov

The hwclock command allows to query or set the hardware clock (RTC).

---
 commands/Kconfig   |   8 +++
 commands/Makefile  |   1 +
 commands/hwclock.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+)
commands/Kconfig +8 -0
index 61816f5..6a75f85 100644
@@ -1691,6 +1691,14 @@ config CMD_GPIO
 
 	  Usage: gpio_set_value GPIO VALUE
 
+config CMD_HWCLOCK
+	bool
+	depends on RTC_CLASS
+	prompt "hwclock command"
+	default y
+	help
+	  The hwclock command allows to query or set the hardware clock (RTC).
+
 config CMD_I2C
 	bool
 	depends on I2C
commands/Makefile +1 -0
index d42aca5..44dd9d4 100644
@@ -100,3 +100,4 @@ obj-$(CONFIG_CMD_MENUTREE)	+= menutree.o
 obj-$(CONFIG_CMD_2048)		+= 2048.o
 obj-$(CONFIG_CMD_REGULATOR)	+= regulator.o
 obj-$(CONFIG_CMD_LSPCI)		+= lspci.o
+obj-$(CONFIG_CMD_HWCLOCK)	+= hwclock.o
commands/hwclock.c new file +119 -0
new file mode 100644
index 0000000..511973a
@@ -0,0 +1,151 @@
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+#include <rtc.h>
+#include <linux/rtc.h>
+#include <string.h>
+#include <environment.h>
+
+static char *strchrnul(const char *s, int c)
+{
+	while (*s != '\0' && *s != c)
+		s++;
+
+	return (char *)s;
+}
+
+static int sscanf_two_digits(char *s, int *res)
+{
+	char buf[3];
+	unsigned long t;
+
+	if (!isdigit(s[0]) || !isdigit(s[1])) {
+		return -EINVAL;
+	}
+
+	buf[0] = s[0];
+	buf[1] = s[1];
+	buf[2] = '\0';
+
+	t = simple_strtoul(buf, NULL, 10);
+	*res = t;
+
+	return 0;
+}
+
+static int parse_datestr(char *date_str, struct rtc_time *ptm)
+{
+	char end = '\0';
+	int len = strchrnul(date_str, '.') - date_str;
+	int year;
+
+	/* ccyymmddHHMM[.SS] */
+	if (len != 12) {
+		return -EINVAL;
+	}
+
+	if (sscanf_two_digits(date_str, &year) ||
+		sscanf_two_digits(&date_str[2], &ptm->tm_year)) {
+		return -EINVAL;
+	}
+
+	ptm->tm_year = year * 100 + ptm->tm_year;
+
+	/* Adjust years */
+	ptm->tm_year -= 1900;
+
+	if (sscanf_two_digits(&date_str[4], &ptm->tm_mon) ||
+		sscanf_two_digits(&date_str[6], &ptm->tm_mday) ||
+		sscanf_two_digits(&date_str[8], &ptm->tm_hour) ||
+		sscanf_two_digits(&date_str[10], &ptm->tm_min)) {
+		return -EINVAL;
+	}
+
+	/* Adjust month from 1-12 to 0-11 */
+	ptm->tm_mon -= 1;
+
+	end = date_str[12];
+
+	if (end == '.') {
+		/* xxx.SS */
+		if (!sscanf_two_digits(&date_str[13], &ptm->tm_sec)) {
+			end = '\0';
+		}
+		/* else end != NUL and we error out */
+	}
+
+	if (end != '\0') {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int do_hwclock(int argc, char *argv[])
+{
+	struct rtc_device *r;
+	struct rtc_time tm;
+	struct rtc_time stm;
+	char rtc_name[16] = "rtc0";
+	char *env_name = NULL;
+	int opt;
+	int set = 0;
+
+	while ((opt = getopt(argc, argv, "f:s:e:")) > 0) {
+		switch (opt) {
+		case 'f':
+			strncpy(rtc_name, optarg, 16);
+			break;
+		case 's':
+			memset(&stm, 0, sizeof(stm));
+			parse_datestr(optarg, &stm);
+			set = 1;
+			break;
+		case 'e':
+			env_name = optarg;
+			break;
+		}
+	}
+
+	r = rtc_lookup(rtc_name);
+	if (IS_ERR(r))
+		return PTR_ERR(r);
+
+	if (set) {
+		rtc_set_time(r, &stm);
+		return 0;
+	}

commands/hwclock.c line 129

Quoted 10 lines
commands/hwclock.c new file +10 -0
+
+	rtc_read_time(r, &tm);
+
+	if (env_name) {
+		unsigned long time;
+		char t[12];
+
+		rtc_tm_to_time(&tm, &time);
+		snprintf(t, 12, "%lu", time);
+		setenv(env_name, t);

I thought more about a globalvar_add(), like globalvar.date, so that no command has to be executed to get the date. But then again maybe it's better to have it in a command since it allows us to add different formats without much hassle.

Quoted 11 lines
commands/hwclock.c new file +11 -0
+	} else {
+		printf("%02d:%02d:%02d %02d-%02d-%04d\n",
+			tm.tm_hour, tm.tm_min, tm.tm_sec,
+			tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
+	}
+
+	return 0;
+}
+
+BAREBOX_CMD_HELP_START(hwclock)
+BAREBOX_CMD_HELP_TEXT("Options:")
Quoted 8 lines

commands/hwclock.c line 143

Quoted 3 lines
commands/hwclock.c new file +3 -0
+BAREBOX_CMD_HELP_OPT ("-f NAME\t\t\t", "RTC device name (default rtc0)")
+BAREBOX_CMD_HELP_OPT ("-e VARNAME\t\t", "store RTC readout into variable VARNAME")
+BAREBOX_CMD_HELP_OPT ("-s ccyymmddHHMM[.SS]\t", "set time")

It's much more logical to have the year first, but the format documented in 'man date' is MMDDhhmm[[CC]YY][.ss]. Of course we are free to choose another format, but maybe we should rather use a format someone other uses aswell?

The format MMDDhhmm[[CC]YY][.ss] forces me to add additional logic. It the command hwclock is invoked with MMDDhhmm argument (without CCYY) then i have to read RTC to get current year and only after that set RTC new time.

If you insist on MMDDhhmm[[CC]YY][.ss] then I can steal appropriate ready-to-use code from busybox for handling "weird format with completely unnatural placement of year between minutes and seconds" (quote from busybox code :).

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#8 lore raw

Re: [RFC v3 4/5] commands: add hwclock

Quoted 3 lines · On Sat, 19 Jul 2014 21:02:22 +0200 Holger Schurig <[email protected]>…

I'd prefer a more logical format (and that is also in the help). However, in this case I wouldn't name the command "hwclock", but maybe "setclock".

hwclock allows to use a logical format!

e.g. here is a quote from hwclock manpage:

--date=date_string
You need this option if you specify the --set or --predict functions, otherwise it is ignored. It specifies the time to which to set the Hardware Clock, or the time for which to predict the Hardware Clock reading. The value of this option is an argument to the date(1) program. For example:

hwclock --set --date="2011-08-14 16:45:05"

The problem is that date(1) program allows to use TOO MANY formats (both logical and illogical). We have to select only one format!

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#9 lore raw

Re: [RFC v3 4/5] commands: add hwclock

Quoted 11 lines · Antony Pavlov
Quoted 3 lines · On Sat, 19 Jul 2014 21:02:22 +0200 Holger Schurig <[email protected]>…

I'd prefer a more logical format (and that is also in the help). However, in this case I wouldn't name the command "hwclock", but maybe "setclock".

hwclock allows to use a logical format!

e.g. here is a quote from hwclock manpage:

Quoted 7 lines

--date=date_string
You need this option if you specify the --set or --predict functions, otherwise it is ignored. It specifies the time to which to set the Hardware Clock, or the time for which to predict the Hardware Clock reading. The value of this option is an argument to the date(1) program. For example:

hwclock --set --date="2011-08-14 16:45:05"

Is this format easy enough to parse? If yes, that sounds like a good format.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

Re: [RFC v3 4/5] commands: add hwclock

Quoted 18 lines · On Mon, 21 Jul 2014 08:41:06 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 17 lines · Antony Pavlov
Quoted 3 lines · On Sat, 19 Jul 2014 21:02:22 +0200 Holger Schurig <[email protected]>…

I'd prefer a more logical format (and that is also in the help). However, in this case I wouldn't name the command "hwclock", but maybe "setclock".

hwclock allows to use a logical format!

e.g. here is a quote from hwclock manpage:

--date=date_string
You need this option if you specify the --set or --predict functions, otherwise it is ignored. It specifies the time to which to set the Hardware Clock, or the time for which to predict the Hardware Clock reading. The value of this option is an argument to the date(1) program. For example:

Quoted 4 lines
Quoted 1 line
                  hwclock --set --date="2011-08-14 16:45:05"

Is this format easy enough to parse? If yes, that sounds like a good format.

So you have no objections on using a logical format :)

I can make a small review on conventional date_string formats so we can discuss most appropriate one.

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#11 lore raw

Re: [RFC v3 4/5] commands: add hwclock

Quoted 21 lines · Antony Pavlov
Quoted 18 lines · On Mon, 21 Jul 2014 08:41:06 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 17 lines · Antony Pavlov
Quoted 3 lines · On Sat, 19 Jul 2014 21:02:22 +0200 Holger Schurig <[email protected]>…

I'd prefer a more logical format (and that is also in the help). However, in this case I wouldn't name the command "hwclock", but maybe "setclock".

hwclock allows to use a logical format!

e.g. here is a quote from hwclock manpage:

--date=date_string
You need this option if you specify the --set or --predict functions, otherwise it is ignored. It specifies the time to which to set the Hardware Clock, or the time for which to predict the Hardware Clock reading. The value of this option is an argument to the date(1) program. For example:

Quoted 6 lines
Quoted 4 lines
Quoted 1 line
                  hwclock --set --date="2011-08-14 16:45:05"

Is this format easy enough to parse? If yes, that sounds like a good format.

So you have no objections on using a logical format :)

No, not at all ;)

Quoted 2 lines

I can make a small review on conventional date_string formats so we can discuss most appropriate one.

Nice, thanks.

I think we can always add additional formats using different command line switches, but the better we chose our default format the lesser need we'll have to add additional formats.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#12 lore raw

Re: [RFC v3 4/5] commands: add hwclock

Quoted 32 lines · On Mon, 21 Jul 2014 10:11:50 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 21 lines · Antony Pavlov
Quoted 18 lines · On Mon, 21 Jul 2014 08:41:06 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 17 lines · Antony Pavlov
Quoted 3 lines · On Sat, 19 Jul 2014 21:02:22 +0200 Holger Schurig <[email protected]>…

I'd prefer a more logical format (and that is also in the help). However, in this case I wouldn't name the command "hwclock", but maybe "setclock".

hwclock allows to use a logical format!

e.g. here is a quote from hwclock manpage:

--date=date_string
You need this option if you specify the --set or --predict functions, otherwise it is ignored. It specifies the time to which to set the Hardware Clock, or the time for which to predict the Hardware Clock reading. The value of this option is an argument to the date(1) program. For example:

Quoted 6 lines
Quoted 4 lines
Quoted 1 line
                  hwclock --set --date="2011-08-14 16:45:05"

Is this format easy enough to parse? If yes, that sounds like a good format.

So you have no objections on using a logical format :)

No, not at all ;)

Quoted 1 line
Quoted 7 lines
Quoted 1 line

I can make a small review on conventional date_string formats so we can discuss most appropriate one.

Nice, thanks.

I think we can always add additional formats using different command line switches, but the better we chose our default format the lesser need we'll have to add additional formats.

I know about at least two widespread date command realizations used with linux:

* coreutils realization;
* busybox realization.

coreutils realization
=====================

I have looked inside parse_datetime() from coreutils-8.21/lib/parse-datetime.c.

It uses yyparse() for date string parsing! The corresponding yacc description
is inside the lib/parse-datetime.y file. Can I easely steal this code for barebox? I suppose NO!

busybox realization
===================

Here is parse_datestr() (barebox.git/libbb/time.c) date format list:

#if ENABLE_FEATURE_DATE_COMPAT
/* MMDDhhmm[[CC]YY][.ss] */ --- weird 'date' format #endif

/* HH:MM[:SS] */
/* mm.dd-HH:MM[:SS] */
/* yyyy.mm.dd-HH:MM[:SS] */
/* yyyy-mm-dd HH:MM[:SS] */

/* month_name d HH:MM:SS YYYY */ --- I suppose we don't want to mess with mount_name :) /* yyyy-mm-dd HH */
/* yyyy-mm-dd */

/* MM[.SS] */
/* HHMM[.SS] */
/* ddHHMM[.SS] */
/* mmddHHMM[.SS] */
/* yymmddHHMM[.SS] */
/* ccyymmddHHMM[.SS] */ --- this format is used in RFCv3 patchseries.

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#13 lore raw

Re: [RFC v3 4/5] commands: add hwclock

Quoted 54 lines · On Mon, 21 Jul 2014 19:41:50 +0400 Antony Pavlov <[email protected]>…
Quoted 32 lines · On Mon, 21 Jul 2014 10:11:50 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 21 lines · Antony Pavlov
Quoted 18 lines · On Mon, 21 Jul 2014 08:41:06 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 17 lines · Antony Pavlov
Quoted 3 lines · On Sat, 19 Jul 2014 21:02:22 +0200 Holger Schurig <[email protected]>…

I'd prefer a more logical format (and that is also in the help). However, in this case I wouldn't name the command "hwclock", but maybe "setclock".

hwclock allows to use a logical format!

e.g. here is a quote from hwclock manpage:

--date=date_string
You need this option if you specify the --set or --predict functions, otherwise it is ignored. It specifies the time to which to set the Hardware Clock, or the time for which to predict the Hardware Clock reading. The value of this option is an argument to the date(1) program. For example:

Quoted 6 lines
Quoted 4 lines
Quoted 1 line
                  hwclock --set --date="2011-08-14 16:45:05"

Is this format easy enough to parse? If yes, that sounds like a good format.

So you have no objections on using a logical format :)

No, not at all ;)

Quoted 1 line
Quoted 7 lines
Quoted 1 line

I can make a small review on conventional date_string formats so we can discuss most appropriate one.

Nice, thanks.

I think we can always add additional formats using different command line switches, but the better we chose our default format the lesser need we'll have to add additional formats.

I know about at least two widespread date command realizations used with linux:

* coreutils realization;
* busybox realization.

coreutils realization
=====================

I have looked inside parse_datetime() from coreutils-8.21/lib/parse-datetime.c.

Quoted 8 lines

It uses yyparse() for date string parsing! The corresponding yacc description
is inside the lib/parse-datetime.y file. Can I easely steal this code for barebox? I suppose NO!

busybox realization
===================

Here is parse_datestr() (barebox.git/libbb/time.c) date format list:

^^^^^^^^^^^
Sorry! I meant busybox.git.

--
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#14 lore raw

Re: [RFC v3 4/5] commands: add hwclock

In reply to Antony Pavlov

On Mon, 21 Jul 2014 19:41:50 +0400
Antony Pavlov <[email protected]> wrote:

ping!

Quoted 86 lines
Quoted 32 lines · On Mon, 21 Jul 2014 10:11:50 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 21 lines · Antony Pavlov
Quoted 18 lines · On Mon, 21 Jul 2014 08:41:06 +0200 Sascha Hauer <[email protected]> wrote:
Quoted 17 lines · Antony Pavlov
Quoted 3 lines · On Sat, 19 Jul 2014 21:02:22 +0200 Holger Schurig <[email protected]>…

I'd prefer a more logical format (and that is also in the help). However, in this case I wouldn't name the command "hwclock", but maybe "setclock".

hwclock allows to use a logical format!

e.g. here is a quote from hwclock manpage:

--date=date_string
You need this option if you specify the --set or --predict functions, otherwise it is ignored. It specifies the time to which to set the Hardware Clock, or the time for which to predict the Hardware Clock reading. The value of this option is an argument to the date(1) program. For example:

Quoted 6 lines
Quoted 4 lines
Quoted 1 line
                  hwclock --set --date="2011-08-14 16:45:05"

Is this format easy enough to parse? If yes, that sounds like a good format.

So you have no objections on using a logical format :)

No, not at all ;)

Quoted 1 line
Quoted 7 lines
Quoted 1 line

I can make a small review on conventional date_string formats so we can discuss most appropriate one.

Nice, thanks.

I think we can always add additional formats using different command line switches, but the better we chose our default format the lesser need we'll have to add additional formats.

I know about at least two widespread date command realizations used with linux:

* coreutils realization;
* busybox realization.

coreutils realization
=====================

I have looked inside parse_datetime() from coreutils-8.21/lib/parse-datetime.c.

It uses yyparse() for date string parsing! The corresponding yacc description
is inside the lib/parse-datetime.y file. Can I easely steal this code for barebox? I suppose NO!

busybox realization
===================

Here is parse_datestr() (barebox.git/libbb/time.c) date format list:

#if ENABLE_FEATURE_DATE_COMPAT
/* MMDDhhmm[[CC]YY][.ss] */ --- weird 'date' format #endif

/* HH:MM[:SS] */
/* mm.dd-HH:MM[:SS] */
/* yyyy.mm.dd-HH:MM[:SS] */
/* yyyy-mm-dd HH:MM[:SS] */

/* month_name d HH:MM:SS YYYY */ --- I suppose we don't want to mess with mount_name :) /* yyyy-mm-dd HH */
/* yyyy-mm-dd */

/* MM[.SS] */
/* HHMM[.SS] */
/* ddHHMM[.SS] */
/* mmddHHMM[.SS] */
/* yymmddHHMM[.SS] */
/* ccyymmddHHMM[.SS] */ --- this format is used in RFCv3 patchseries.

--
Best regards,
  Antony Pavlov

Signature · 8 lines
-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#15 lore raw

Re: [RFC v3 4/5] commands: add hwclock

In reply to Antony Pavlov
Quoted 22 lines · Antony Pavlov

On Mon, 21 Jul 2014 10:11:50 +0200
Sascha Hauer <[email protected]> wrote:

busybox realization
===================

Here is parse_datestr() (barebox.git/libbb/time.c) date format list:

#if ENABLE_FEATURE_DATE_COMPAT
/* MMDDhhmm[[CC]YY][.ss] */ --- weird 'date' format #endif

/* HH:MM[:SS] */
/* mm.dd-HH:MM[:SS] */
/* yyyy.mm.dd-HH:MM[:SS] */
/* yyyy-mm-dd HH:MM[:SS] */

/* month_name d HH:MM:SS YYYY */ --- I suppose we don't want to mess with mount_name :) /* yyyy-mm-dd HH */
/* yyyy-mm-dd */

Quoted 6 lines

/* MM[.SS] */
/* HHMM[.SS] */
/* ddHHMM[.SS] */
/* mmddHHMM[.SS] */
/* yymmddHHMM[.SS] */
/* ccyymmddHHMM[.SS] */ --- this format is used in RFCv3 patchseries.

I am happy with this format. This is just what I would have typed if I had guessed the correct format.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#16 lore raw

Re: [RFC v3 4/5] commands: add hwclock

In reply to Sascha Hauer
Quoted 10 lines · Sascha Hauer
Quoted 9 lines · Antony Pavlov
commands/hwclock.c new file +9 -0
+{
+	struct rtc_device *r;
+	struct rtc_time tm;
+	struct rtc_time stm;
+	char rtc_name[16] = "rtc0";
+	char *env_name = NULL;
+	int opt;
+	int set = 0;
+
Quoted 8 lines

commands/hwclock.c line 103

Quoted 8 lines
commands/hwclock.c new file +8 -0
+	while ((opt = getopt(argc, argv, "f:s:e:")) > 0) {
+		switch (opt) {
+		case 'f':
+			strncpy(rtc_name, optarg, 16);
+			break;
+		case 's':
+			memset(&stm, 0, sizeof(stm));
+			parse_datestr(optarg, &stm);

The result value should really be checked.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#17 lore raw

RFC v3 5/5 ARM: versatilepb_defconfig: enable RTC support

In reply to Antony Pavlov

Use this qemu cmdline to test hwclock

  $ qemu-system-arm -M versatilepb -nographic \
      -monitor null -kernel barebox -serial stdio
---
 arch/arm/configs/versatilepb_defconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/configs/versatilepb_defconfig +2 -0
index 58dfb8b..a447f93 100644
@@ -51,6 +51,8 @@ CONFIG_DRIVER_NET_SMC91111=y
 CONFIG_I2C=y
 CONFIG_I2C_VERSATILE=y
 CONFIG_GPIO_PL061=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_DS1307=y
 CONFIG_FS_CRAMFS=y
 CONFIG_FS_TFTP=y
 CONFIG_SHA1=y
Signature · 7 lines
2.0.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox