diff --git a/litex/soc/software/libbase/Makefile b/litex/soc/software/libbase/Makefile index b7f7d4cbe..bf8762046 100644 --- a/litex/soc/software/libbase/Makefile +++ b/litex/soc/software/libbase/Makefile @@ -4,7 +4,7 @@ include $(SOC_DIRECTORY)/software/common.mak OBJECTS=exception.o libc.o errno.o crc16.o crc32.o console.o \ system.o id.o uart.o time.o qsort.o strtod.o spiflash.o strcasecmp.o -all: crt0-$(CPU).o libbase.a libbase-nofloat.a +all: crt0-$(CPU).o crt0-$(CPU)-flash.o libbase.a libbase-nofloat.a libbase.a: $(OBJECTS) vsnprintf.o $(AR) crs libbase.a $(OBJECTS) vsnprintf.o @@ -24,8 +24,11 @@ vsnprintf-nofloat.o: $(LIBBASE_DIRECTORY)/vsnprintf.c %.o: $(LIBBASE_DIRECTORY)/%.S $(assemble) +crt0-$(CPU)-flash.o: $(LIBBASE_DIRECTORY)/crt0-$(CPU).S + $(CC) -c -DFLASH_DATA_SECTION $(CFLAGS) -o $@ $< + .PHONY: all clean clean: - $(RM) $(OBJECTS) crt0-$(CPU).o vsnprintf.o vsnprintf-nofloat.o + $(RM) $(OBJECTS) crt0-$(CPU).o crt0-$(CPU)-flash.o vsnprintf.o vsnprintf-nofloat.o $(RM) libbase.a libbase-nofloat.a .*~ *~ diff --git a/litex/soc/software/libbase/crt0-lm32.S b/litex/soc/software/libbase/crt0-lm32.S index e0cd71537..3b65ba9f5 100644 --- a/litex/soc/software/libbase/crt0-lm32.S +++ b/litex/soc/software/libbase/crt0-lm32.S @@ -112,6 +112,25 @@ _crt0: mvhi sp, hi(_fstack) ori sp, sp, lo(_fstack) +#ifdef FLASH_DATA_SECTION + /* Load DATA */ + mvhi r1, hi(_erodata) + ori r1, r1, lo(_erodata) + mvhi r2, hi(_fdata) + ori r2, r2, lo(_fdata) + mvhi r3, hi(_edata) + ori r3, r3, lo(_edata) +.moveDATA: + be r2, r3, .doBSS + lw r4, (r1+0) + sw (r2+0), r4 + /* _edata is aligned to 16 bytes. Use word-xfers. */ + addi r1, r1, 4 + addi r2, r2, 4 + bi .moveDATA +#endif + +.doBSS: /* Clear BSS */ mvhi r1, hi(_fbss) ori r1, r1, lo(_fbss)