Skip to content

Commit 045d6ef

Browse files
committed
[fw-isoldr] Fixed get_fattime() and remove fstime.c
1 parent 69db392 commit 045d6ef

File tree

3 files changed

+71
-82
lines changed

3 files changed

+71
-82
lines changed

firmware/isoldr/loader/Makefile.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
TARGET = 0x8ce00000
88
BUILD = build
9-
VERSION = "0.8.2.Beta"
9+
VERSION = "0.8.2.Beta.2"
1010
INSTALL_PATH = ../../../build/firmware/isoldr
1111
# INSTALL_PATH = /Volumes/DREAMSHELL/DS/firmware/isoldr
1212

@@ -127,6 +127,7 @@ endif
127127

128128
ifdef ENABLE_WRITE
129129
TARGETCFLAGS += -D_FS_READONLY=0
130+
LOBJECTS += $(KOS_DIR)/src/rtc.o $(KOS_DIR)/src/g2bus.o
130131
else
131132
TARGETCFLAGS += -D_FS_READONLY=1
132133
endif
@@ -204,7 +205,7 @@ endif
204205
TARGETCFLAGS += -DMAX_OPEN_FILES=$(MAX_OPEN_FILES)
205206

206207
%.bin: %.elf
207-
$(TARGETOBJCOPY) -O binary $< $@
208+
$(TARGETOBJCOPY) -O binary -R .stack $< $@
208209
#%.elf: $(LOBJECTS)
209210
# $(TARGETCC) $(TARGETCFLAGS) $(TARGETLDFLAGS) -o $@ $(LOBJECTS) $(LIBS)
210211
%.on: %.c

firmware/isoldr/loader/fs/fat/src/diskio.c

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/**
22
* DreamShell ISO Loader
33
* disk I/O for FatFs
4-
* (c)2009-2017 SWAT <http://www.dc-swat.ru>
4+
* (c)2009-2017, 2025 SWAT <http://www.dc-swat.ru>
55
*/
6+
#include <arch/rtc.h>
7+
#include <time.h>
68
#include <main.h>
79
#include "diskio.h"
810

@@ -14,6 +16,55 @@
1416
#include <ide/ide.h>
1517
#endif
1618

19+
#if _FS_READONLY == 0
20+
21+
/* gmtime() implementation */
22+
#define YEAR0 1900 /* the first year */
23+
#define EPOCH_YR 1970 /* EPOCH = Jan 1 1970 00:00:00 */
24+
#define SECS_DAY (24L * 60L * 60L)
25+
#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
26+
#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
27+
#define FIRSTSUNDAY(timp) (((timp)->tm_yday - (timp)->tm_wday + 420) % 7)
28+
#define FIRSTDAYOF(timp) (((timp)->tm_wday - (timp)->tm_yday + 420) % 7)
29+
#define TIME_MAX ULONG_MAX
30+
#define ABB_LEN 3
31+
32+
const int _ytab[2][12] = {
33+
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
34+
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
35+
};
36+
37+
struct tm *gmtime(const time_t *timer)
38+
{
39+
static struct tm br_time;
40+
struct tm *timep = &br_time;
41+
time_t time = *timer;
42+
unsigned long dayclock, dayno;
43+
int year = EPOCH_YR;
44+
45+
dayclock = (unsigned long)time % SECS_DAY;
46+
dayno = (unsigned long)time / SECS_DAY;
47+
48+
timep->tm_sec = dayclock % 60;
49+
timep->tm_min = (dayclock % 3600) / 60;
50+
timep->tm_hour = dayclock / 3600;
51+
timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */
52+
while (dayno >= (unsigned long)YEARSIZE(year)) {
53+
dayno -= YEARSIZE(year);
54+
year++;
55+
}
56+
timep->tm_year = year - YEAR0;
57+
timep->tm_yday = dayno;
58+
timep->tm_mon = 0;
59+
while (dayno >= (unsigned long)_ytab[LEAPYEAR(year)][timep->tm_mon]) {
60+
dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
61+
timep->tm_mon++;
62+
}
63+
timep->tm_mday = dayno + 1;
64+
timep->tm_isdst = 0;
65+
66+
return timep;
67+
}
1768

1869
/*--------------------------------------------------------------------------
1970
@@ -23,25 +74,25 @@
2374

2475
DWORD get_fattime ()
2576
{
26-
#if 0
27-
ulong now;
28-
struct _time_block *tm;
29-
DWORD tmr;
30-
31-
now = rtc_secs();
32-
tm = conv_gmtime(now);
33-
tmr = (((DWORD)tm->year - 60) << 25)
34-
| ((DWORD)tm->mon << 21)
35-
| ((DWORD)tm->day << 16)
36-
| (WORD)(tm->hour << 11)
37-
| (WORD)(tm->min << 5)
38-
| (WORD)(tm->sec >> 1);
77+
struct tm *time;
78+
time_t unix_time;
79+
DWORD tmr = 0;
80+
81+
unix_time = rtc_unix_secs();
82+
time = gmtime(&unix_time);
83+
84+
if (time != NULL) {
85+
tmr = (((DWORD)(time->tm_year - 80)) << 25) /* tm_year is years since 1900; FAT starts from 1980 */
86+
| ((DWORD)(time->tm_mon + 1) << 21) /* tm_mon ranges from 0 to 11; add 1 for FAT */
87+
| ((DWORD)(time->tm_mday) << 16) /* tm_mday ranges from 1 to 31 */
88+
| ((DWORD)(time->tm_hour) << 11) /* tm_hour ranges from 0 to 23 */
89+
| ((DWORD)(time->tm_min) << 5) /* tm_min ranges from 0 to 59 */
90+
| ((DWORD)(time->tm_sec / 2)); /* tm_sec ranges from 0 to 59; FAT stores seconds in 2-second steps */
91+
}
3992
return tmr;
40-
#else
41-
return 0;
42-
#endif
4393
}
4494

95+
#endif /* _FS_READONLY == 0 */
4596

4697
/*-----------------------------------------------------------------------*/
4798
/* Inidialize a Drive */

firmware/isoldr/loader/fs/fat/src/fstime.c

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)