From 7de49d2021154fc6e60472df820a93405473d152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Th=C3=B6rnblad?= Date: Wed, 19 Mar 2025 15:44:37 +0100 Subject: [PATCH] ch552: Reorganize file directory structure - Move source files to separate directory. - Move include files to separate directory. - Add specific output direcory for intermediate files. --- hw/usb_interface/ch552_fw/Makefile | 40 +++++++++---------- .../ch552_fw/encode_usb_strings.py | 2 +- .../ch552_fw/{include => inc}/ch554.h | 0 .../ch552_fw/{include => inc}/ch554_usb.h | 0 .../ch552_fw/{include => inc}/debug.h | 0 .../ch552_fw/{include => inc}/mem.h | 0 .../ch552_fw/{include => inc}/print.h | 0 .../ch552_fw/{include => inc}/usb_strings.h | 0 .../ch552_fw/{include => src}/debug.c | 0 hw/usb_interface/ch552_fw/{ => src}/main.c | 0 .../ch552_fw/{include => src}/print.c | 0 11 files changed, 19 insertions(+), 23 deletions(-) rename hw/usb_interface/ch552_fw/{include => inc}/ch554.h (100%) rename hw/usb_interface/ch552_fw/{include => inc}/ch554_usb.h (100%) rename hw/usb_interface/ch552_fw/{include => inc}/debug.h (100%) rename hw/usb_interface/ch552_fw/{include => inc}/mem.h (100%) rename hw/usb_interface/ch552_fw/{include => inc}/print.h (100%) rename hw/usb_interface/ch552_fw/{include => inc}/usb_strings.h (100%) rename hw/usb_interface/ch552_fw/{include => src}/debug.c (100%) rename hw/usb_interface/ch552_fw/{ => src}/main.c (100%) rename hw/usb_interface/ch552_fw/{include => src}/print.c (100%) diff --git a/hw/usb_interface/ch552_fw/Makefile b/hw/usb_interface/ch552_fw/Makefile index 619b4a8..b278fff 100644 --- a/hw/usb_interface/ch552_fw/Makefile +++ b/hw/usb_interface/ch552_fw/Makefile @@ -10,7 +10,7 @@ CHPROG = chprog TARGET = usb_device -ROOT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +OUT_DIR = _out XRAM_SIZE = 0x0400 # 1 KB on-chip xRAM XRAM_LOC = 0x0000 # xRAM area starts at address 0 in the External Data Address Space @@ -26,7 +26,7 @@ CFLAGS = \ --xram-size $(XRAM_SIZE) \ --xram-loc $(XRAM_LOC) \ --code-size $(CODE_SIZE) \ - -I$(ROOT_DIR)include \ + -Iinc \ -DFREQ_SYS=$(FREQ_SYS) \ $(EXTRA_FLAGS) @@ -34,25 +34,28 @@ LFLAGS = \ $(CFLAGS) C_FILES = \ - main.c \ - include/debug.c \ - include/print.c + src/main.c \ + src/debug.c \ + src/print.c -# Create a .rel file for each .c file -RELS = $(C_FILES:.c=.rel) +# Create a .rel file for each .c file in $(OUT_DIR)/ +RELS = $(patsubst %.c,$(OUT_DIR)/%.rel,$(C_FILES)) -%.rel : %.c - $(CC) -c $(CFLAGS) $< +OUT_SUBDIRS = $(sort $(dir $(RELS))) + +# Ensure out directory exists +$(OUT_DIR): + mkdir -p $(OUT_SUBDIRS) + +$(OUT_DIR)/%.rel: %.c | $(OUT_DIR) + $(CC) -c $(CFLAGS) $< -o $@ usb_strings.h: encode_usb_strings.py ./encode_usb_strings.py -# Note: SDCC will dump all of the temporary files into this one, -# so strip the paths from RELS -# For now, get around this by stripping the paths off of the RELS list. - +# Compile the final ihx file $(TARGET).ihx: $(RELS) - $(CC) $(notdir $(RELS)) $(LFLAGS) -o $(TARGET).ihx + $(CC) $(RELS) $(LFLAGS) -o $(TARGET).ihx $(TARGET).hex: $(TARGET).ihx $(PACK_HEX) $(TARGET).ihx > $(TARGET).hex @@ -72,14 +75,7 @@ flash_patched: $(TARGET).bin all: $(TARGET).bin $(TARGET).hex clean: - rm -f \ - $(notdir $(RELS:.rel=.asm)) \ - $(notdir $(RELS:.rel=.lst)) \ - $(notdir $(RELS:.rel=.mem)) \ - $(notdir $(RELS:.rel=.rel)) \ - $(notdir $(RELS:.rel=.rst)) \ - $(notdir $(RELS:.rel=.sym)) \ - $(notdir $(RELS:.rel=.adb)) \ + rm -rf $(OUT_DIR) \ $(TARGET).lk \ $(TARGET).map \ $(TARGET).mem \ diff --git a/hw/usb_interface/ch552_fw/encode_usb_strings.py b/hw/usb_interface/ch552_fw/encode_usb_strings.py index 697514e..98c4feb 100755 --- a/hw/usb_interface/ch552_fw/encode_usb_strings.py +++ b/hw/usb_interface/ch552_fw/encode_usb_strings.py @@ -57,7 +57,7 @@ if __name__ == "__main__": "TkeyCtrlInterfaceDesc": "TKEY-Ctrl" } - with open('include/usb_strings.h', 'w') as f: + with open('inc/usb_strings.h', 'w') as f: f.write('#ifndef __USB_STRINGS_H__\n') f.write('#define __USB_STRINGS_H__\n') f.write('\n') diff --git a/hw/usb_interface/ch552_fw/include/ch554.h b/hw/usb_interface/ch552_fw/inc/ch554.h similarity index 100% rename from hw/usb_interface/ch552_fw/include/ch554.h rename to hw/usb_interface/ch552_fw/inc/ch554.h diff --git a/hw/usb_interface/ch552_fw/include/ch554_usb.h b/hw/usb_interface/ch552_fw/inc/ch554_usb.h similarity index 100% rename from hw/usb_interface/ch552_fw/include/ch554_usb.h rename to hw/usb_interface/ch552_fw/inc/ch554_usb.h diff --git a/hw/usb_interface/ch552_fw/include/debug.h b/hw/usb_interface/ch552_fw/inc/debug.h similarity index 100% rename from hw/usb_interface/ch552_fw/include/debug.h rename to hw/usb_interface/ch552_fw/inc/debug.h diff --git a/hw/usb_interface/ch552_fw/include/mem.h b/hw/usb_interface/ch552_fw/inc/mem.h similarity index 100% rename from hw/usb_interface/ch552_fw/include/mem.h rename to hw/usb_interface/ch552_fw/inc/mem.h diff --git a/hw/usb_interface/ch552_fw/include/print.h b/hw/usb_interface/ch552_fw/inc/print.h similarity index 100% rename from hw/usb_interface/ch552_fw/include/print.h rename to hw/usb_interface/ch552_fw/inc/print.h diff --git a/hw/usb_interface/ch552_fw/include/usb_strings.h b/hw/usb_interface/ch552_fw/inc/usb_strings.h similarity index 100% rename from hw/usb_interface/ch552_fw/include/usb_strings.h rename to hw/usb_interface/ch552_fw/inc/usb_strings.h diff --git a/hw/usb_interface/ch552_fw/include/debug.c b/hw/usb_interface/ch552_fw/src/debug.c similarity index 100% rename from hw/usb_interface/ch552_fw/include/debug.c rename to hw/usb_interface/ch552_fw/src/debug.c diff --git a/hw/usb_interface/ch552_fw/main.c b/hw/usb_interface/ch552_fw/src/main.c similarity index 100% rename from hw/usb_interface/ch552_fw/main.c rename to hw/usb_interface/ch552_fw/src/main.c diff --git a/hw/usb_interface/ch552_fw/include/print.c b/hw/usb_interface/ch552_fw/src/print.c similarity index 100% rename from hw/usb_interface/ch552_fw/include/print.c rename to hw/usb_interface/ch552_fw/src/print.c