@@ -146,9 +146,37 @@ static char *strptime(const char *s, const char *format, struct tm *tm_time)
146146 }
147147}
148148
149+ /* Look up a device by some human-readable string identifier. We
150+ * always search among device names. If the feature is available, we
151+ * search by node label as well.
152+ */
153+ static const struct device * get_rtc_device (char * id )
154+ {
155+ const struct device * dev ;
156+
157+ dev = device_get_binding (id );
158+ if (dev != NULL ) {
159+ return dev ;
160+ }
161+
162+ #ifdef CONFIG_DEVICE_DT_METADATA
163+ dev = device_get_by_dt_nodelabel (id );
164+ if (dev != NULL ) {
165+ return dev ;
166+ }
167+ #endif /* CONFIG_DEVICE_DT_METADATA */
168+
169+ return NULL ;
170+ }
171+
149172static int cmd_set (const struct shell * sh , size_t argc , char * * argv )
150173{
151- const struct device * dev = device_get_binding (argv [1 ]);
174+ const struct device * dev = get_rtc_device (argv [1 ]);
175+
176+ if (dev == NULL ) {
177+ shell_error (sh , "unknown RTC device %s" , argv [1 ]);
178+ return - EINVAL ;
179+ }
152180
153181 if (!device_is_ready (dev )) {
154182 shell_error (sh , "device %s not ready" , argv [1 ]);
@@ -191,7 +219,12 @@ static int cmd_set(const struct shell *sh, size_t argc, char **argv)
191219
192220static int cmd_get (const struct shell * sh , size_t argc , char * * argv )
193221{
194- const struct device * dev = device_get_binding (argv [1 ]);
222+ const struct device * dev = get_rtc_device (argv [1 ]);
223+
224+ if (dev == NULL ) {
225+ shell_error (sh , "unknown RTC device %s" , argv [1 ]);
226+ return - EINVAL ;
227+ }
195228
196229 if (!device_is_ready (dev )) {
197230 shell_error (sh , "device %s not ready" , argv [1 ]);
0 commit comments