-$(OBJDIR)/osimage.elf: $(OBJDIR)/fullimage.elf
- $(OBJCOPY) -F elf32-littlearm --remove-section .fpgaimage $^ $@
+$(OBJDIR)/fullimage.data.bin.z: $(OBJDIR)/fullimage.data.bin $(FPGA_COMPRESSOR)
+ $(FPGA_COMPRESSOR) $(filter %.bin,$^) $@
+
+$(OBJDIR)/fullimage.data.o: $(OBJDIR)/fullimage.data.bin.z
+ $(OBJCOPY) -O elf32-littlearm -I binary -B arm --rename-section .data=compressed_data $^ $@
+
+$(OBJDIR)/fullimage.elf: $(OBJDIR)/fullimage.nodata.o $(OBJDIR)/fullimage.data.o
+ $(CC) $(LDFLAGS) -Wl,-T,ldscript,-e,_osimage_entry,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^