From 7ec285a966b87fcf7b5436e11a5e11cffe44ee29 Mon Sep 17 00:00:00 2001 From: nikto_b Date: Wed, 8 Apr 2026 23:27:50 +0300 Subject: [PATCH] add python manifest generation --- Makefile | 10 +++++++-- manifest_src/gen_manifest_json.py | 34 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 manifest_src/gen_manifest_json.py diff --git a/Makefile b/Makefile index 5c04933..958f96a 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ vpath %.h $(sort $(dir $(C_HEADERS))) rebuild: clean | build -all: +all: build manifest build: date Dir $(C_HEADERS) target @@ -60,12 +60,18 @@ $(BUILD_DIR)/$(TARGET).so: $(OBJECTS) @echo -e '\033[1;32mELF ('$(ARCH)')\t'$(OBJECTS)'\n\t\t\t->\t'$@'\033[0m' @$(CC) $(LFLAGS) $(OBJECTS) -o $(BUILD_DIR)/$(TARGET).so -manifest: $(MANIFEST_TARGETS) +manifest: $(MANIFEST_BUILD_DIR)/MANIFEST.json + +$(MANIFEST_BUILD_DIR)/MANIFEST.json: $(MANIFEST_TARGETS) @for elf in $(MANIFEST_TARGETS); do \ echo -e "\033[1;32mRUN\t$$elf\033[0m"; \ $$elf $(MANIFEST_BUILD_DIR) || { echo -e "\033[0;31merror running $$elf\033[0m"; exit 1; }; \ done + @echo -e "\033[1;32mPY\t$@\033[0m" + @python $(MANIFEST_SRC_DIR)/gen_manifest_json.py $(MANIFEST_BUILD_DIR) + + $(MANIFEST_BUILD_DIR)/%.elf: $(MANIFEST_SRC_DIR)/%.c Makefile | $(MANIFEST_BUILD_DIR) diff --git a/manifest_src/gen_manifest_json.py b/manifest_src/gen_manifest_json.py new file mode 100644 index 0000000..1eda334 --- /dev/null +++ b/manifest_src/gen_manifest_json.py @@ -0,0 +1,34 @@ +import sys +import csv +import json + +def main(): + if len(sys.argv) != 2: + print('provide manifest data directory') + return + manifest_dir = sys.argv[1] + + mem_segments = [] + out_manifest = { + 'mem_segments': mem_segments + } + + with open(manifest_dir + '/seg_data.csv', 'r', newline='') as csvfile: + reader = csv.DictReader(csvfile, delimiter=';') + for line in reader: + mem_segments.append( + { + 'seg_id': int(line['seg_id']), + 'name': line['name'], + 'word_len': int(line['word_len']), + 'default_size': int(line['default_size']), + 'default_addr': int(line['default_addr']), + 'is_executable': line['is_executable'] == '1' + } + ) + + with open(manifest_dir + '/MANIFEST.json', 'w') as f: + json.dump(out_manifest, f, indent=4) + +if __name__ == '__main__': + main() \ No newline at end of file