-$(OBJDIR)/fpgaimage.elf: $(OBJDIR)/fullimage.elf
- $(OBJCOPY) -F elf32-littlearm --only-section .fpgaimage $^ $@
+$(OBJDIR)/fullimage.nodata.bin: $(OBJDIR)/fullimage.stage1.elf
+ $(OBJCOPY) -O binary -I elf32-littlearm --remove-section .data $^ $@
+
+$(OBJDIR)/fullimage.nodata.o: $(OBJDIR)/fullimage.nodata.bin
+ $(OBJCOPY) -O elf32-littlearm -I binary -B arm --rename-section .data=stage1_image $^ $@
+
+$(OBJDIR)/fullimage.data.bin: $(OBJDIR)/fullimage.stage1.elf
+ $(OBJCOPY) -O binary -I elf32-littlearm --only-section .data $^ $@
+
+$(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 $@ $^