diff --git a/.gitignore b/.gitignore index 647c8dec..fa1da108 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ build/linux-x86-softfp/ build/riscv32/ build/sail_cSim/ build/sha1sum-* +build/minimal.dtb *.a *.o *.o.d @@ -29,3 +30,4 @@ tests/arch-test-target/sail_cSim/riscv_sim_RV32 tests/scimark2/ __pycache__/ src/rv32_jit.c +src/minimal_dtb.h diff --git a/.gitmodules b/.gitmodules index 24acaf30..5eff7163 100644 --- a/.gitmodules +++ b/.gitmodules @@ -31,3 +31,6 @@ path = tests/quake url = https://github.com/sysprog21/quake-embedded shallow = true +[submodule "tools/bin_to_c"] + path = tools/bin_to_c + url = https://github.com/bitbank2/bin_to_c.git diff --git a/Makefile b/Makefile index 799c9e7e..86e2b95b 100644 --- a/Makefile +++ b/Makefile @@ -241,7 +241,7 @@ include mk/artifact.mk include mk/wasm.mk include mk/system.mk -all: config $(BUILD_DTB) $(BIN) +all: config $(BUILD_DTB) $(BUILD_DTB2C) $(BIN) OBJS := \ map.o \ @@ -369,7 +369,7 @@ endif endif clean: - $(RM) $(BIN) $(OBJS) $(DEV_OBJS) $(BUILD_DTB) $(HIST_BIN) $(HIST_OBJS) $(deps) $(WEB_FILES) $(CACHE_OUT) src/rv32_jit.c + $(RM) $(BIN) $(OBJS) $(DEV_OBJS) $(BUILD_DTB) $(BUILD_DTB2C) $(HIST_BIN) $(HIST_OBJS) $(deps) $(WEB_FILES) $(CACHE_OUT) src/rv32_jit.c distclean: clean -$(RM) $(DOOM_DATA) $(QUAKE_DATA) $(BUILDROOT_DATA) $(LINUX_DATA) $(RM) -r $(OUT)/linux-image diff --git a/README.md b/README.md index 9d66a5c8..1eb08b28 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ $ make ENABLE_SYSTEM=1 system Build using run using specified images: ```shell $ make ENABLE_SYSTEM=1 -$ build/rv32emu -k -i -b +$ build/rv32emu -k -i ``` #### Build Linux image diff --git a/mk/system.mk b/mk/system.mk index 4f696064..3c32ea80 100644 --- a/mk/system.mk +++ b/mk/system.mk @@ -4,10 +4,23 @@ ifeq ($(call has, SYSTEM), 1) DEV_SRC := src/devices DTC ?= dtc -$(OUT)/minimal.dtb: $(DEV_SRC)/minimal.dts +BUILD_DTB := $(OUT)/minimal.dtb +$(BUILD_DTB): $(DEV_SRC)/minimal.dts $(VECHO) " DTC\t$@\n" $(Q)$(DTC) $^ -o $@ -BUILD_DTB := $(OUT)/minimal.dtb + +BIN_TO_C_DIR := tools/bin_to_c +$(BIN_TO_C_DIR)/makefile: + git submodule update --init $(BIN_TO_C_DIR) + +BIN_TO_C := $(BIN_TO_C_DIR)/bin_to_c +$(BIN_TO_C): $(BIN_TO_C_DIR)/makefile + $(MAKE) -C $(dir $<) + +BUILD_DTB2C := src/minimal_dtb.h +$(BUILD_DTB2C): $(BIN_TO_C) $(BUILD_DTB) + $(BIN_TO_C) $(BUILD_DTB) > $(BUILD_DTB2C) + sed -i 's/PROGMEM//g' $(BUILD_DTB2C) $(DEV_OUT)/%.o: $(DEV_SRC)/%.c $(deps_emcc) $(Q)mkdir -p $(DEV_OUT) @@ -20,8 +33,8 @@ OBJS_EXT += system.o # system target execution by using default dependencies LINUX_IMAGE_DIR := linux-image -system_action := ($(BIN) -k $(OUT)/$(LINUX_IMAGE_DIR)/Image -i $(OUT)/$(LINUX_IMAGE_DIR)/rootfs.cpio -b $(OUT)/minimal.dtb) -system_deps += artifact $(BUILD_DTB) $(BIN) +system_action := ($(BIN) -k $(OUT)/$(LINUX_IMAGE_DIR)/Image -i $(OUT)/$(LINUX_IMAGE_DIR)/rootfs.cpio) +system_deps += artifact $(BUILD_DTB) $(BUILD_DTB2C) $(BIN) system: $(system_deps) $(system_action) diff --git a/src/dtc b/src/dtc new file mode 160000 index 00000000..039a9941 --- /dev/null +++ b/src/dtc @@ -0,0 +1 @@ +Subproject commit 039a99414e778332d8f9c04cbd3072e1dcc62798 diff --git a/src/main.c b/src/main.c index bf1c5fbb..56734b63 100644 --- a/src/main.c +++ b/src/main.c @@ -42,7 +42,7 @@ static char *opt_prog_name; /* target argc and argv */ static int prog_argc; static char **prog_args; -static const char *optstr = "tgqmhpd:a:k:i:b:"; +static const char *optstr = "tgqmhpd:a:k:i:"; /* enable misaligned memory access */ static bool opt_misaligned = false; @@ -55,7 +55,6 @@ static char *prof_out_file; /* Linux kernel data */ static char *opt_kernel_img; static char *opt_rootfs_img; -static char *opt_dtb; #endif static void print_usage(const char *filename) @@ -73,7 +72,6 @@ static void print_usage(const char *filename) #if RV32_HAS(SYSTEM) && !RV32_HAS(ELF_LOADER) " -k : use as kernel image\n" " -i : use as rootfs\n" - " -b : use as device tree blob\n" #endif " -d [filename]: dump registers as JSON to the " "given file or `-` (STDOUT)\n" @@ -114,10 +112,6 @@ static bool parse_args(int argc, char **args) opt_rootfs_img = optarg; emu_argc++; break; - case 'b': - opt_dtb = optarg; - emu_argc++; - break; #endif case 'q': opt_quiet_outputs = true; @@ -263,7 +257,6 @@ int main(int argc, char **args) #if RV32_HAS(SYSTEM) && !RV32_HAS(ELF_LOADER) attr.data.system.kernel = opt_kernel_img; attr.data.system.initrd = opt_rootfs_img; - attr.data.system.dtb = opt_dtb; #else attr.data.user.elf_program = opt_prog_name; #endif diff --git a/src/riscv.c b/src/riscv.c index 1dc05b0c..72a25ece 100644 --- a/src/riscv.c +++ b/src/riscv.c @@ -259,6 +259,14 @@ static void map_file(char **ram_loc, const char *name) exit(EXIT_FAILURE); } +static void load_dtb(char **ram_loc) +{ +#include "minimal_dtb.h" + memcpy(*ram_loc, minimal, sizeof(minimal)); + *ram_loc += sizeof(minimal); + return; +} + /* * The control mode flag for keyboard. * @@ -294,6 +302,7 @@ static void capture_keyboard_input() term.c_lflag &= ~TERMIOS_C_CFLAG; tcsetattr(0, TCSANOW, &term); } + #endif /* @@ -409,7 +418,7 @@ riscv_t *rv_create(riscv_user_t rv_attr) uint32_t dtb_addr = attr->mem->mem_size - (1 * 1024 * 1024); ram_loc = ((char *) attr->mem->mem_base) + dtb_addr; - map_file(&ram_loc, attr->data.system.dtb); + load_dtb(&ram_loc); /* * Load optional initrd image at last 8 MiB before the dtb region to * prevent kernel from overwritting it @@ -517,8 +526,7 @@ void rv_run(riscv_t *rv) vm_attr_t *attr = PRIV(rv); assert(attr && #if RV32_HAS(SYSTEM) && !RV32_HAS(ELF_LOADER) - attr->data.system.kernel && attr->data.system.initrd && - attr->data.system.dtb + attr->data.system.kernel && attr->data.system.initrd #else attr->data.user.elf_program #endif diff --git a/src/riscv.h b/src/riscv.h index 500ade3a..46aa7598 100644 --- a/src/riscv.h +++ b/src/riscv.h @@ -551,7 +551,6 @@ typedef struct { typedef struct { char *kernel; char *initrd; - char *dtb; } vm_system_t; #endif /* RV32_HAS(SYSTEM) */ diff --git a/tools/bin_to_c b/tools/bin_to_c new file mode 160000 index 00000000..f389e7b7 --- /dev/null +++ b/tools/bin_to_c @@ -0,0 +1 @@ +Subproject commit f389e7b701e873498d9371511a2bd2dfd48fbff9