#include <rand.h>
#include <asm/byteorder.h>
#include <asm/cache.h>
+#include <dm/uclass.h>
#include <linux/ctype.h>
#include <linux/math64.h>
#include "fat.c"
return 0;
}
+/**
+ * dentry_set_time() - set change time
+ *
+ * @dentptr: directory entry
+ */
+static void dentry_set_time(dir_entry *dentptr)
+{
+ if (CONFIG_IS_ENABLED(DM_RTC)) {
+ struct udevice *dev;
+ struct rtc_time tm;
+ u16 date;
+ u16 time;
+
+ uclass_first_device(UCLASS_RTC, &dev);
+ if (!dev)
+ goto err;
+ if (dm_rtc_get(dev, &tm))
+ goto err;
+ if (tm.tm_year < 1980 || tm.tm_year > 2107)
+ goto err;
+ date = (tm.tm_mday & 0x1f) |
+ ((tm.tm_mon & 0xf) << 5) |
+ ((tm.tm_year - 1980) << 9);
+ time = (tm.tm_sec > 1) |
+ ((tm.tm_min & 0x3f) << 5) |
+ (tm.tm_hour << 11);
+ dentptr->date = date;
+ dentptr->time = time;
+ return;
+ }
+err:
+ dentptr->date = 0x2821; /* 2000-01-01 */
+ dentptr->time = 0;
+}
+
/**
* fill_dentry() - fill directory entry with shortname
*
dentptr->attr = attr;
+ /* Set change date */
+ dentry_set_time(dentptr);
+ /* Set creation date */
+ dentptr->cdate = dentptr->date;
+ dentptr->ctime = dentptr->time;
+
memcpy(&dentptr->nameext, shortname, SHORT_NAME_SIZE);
}
/* Update file size in a directory entry */
retdent->size = cpu_to_le32(pos + size);
+ /* Update change date */
+ dentry_set_time(retdent);
} else {
/* Create a new file */
char shortname[SHORT_NAME_SIZE];