update: userprog (tee, tsh, sleep, hex2bin)
This commit is contained in:
@@ -10,12 +10,10 @@ BUILD_DIR = build
|
||||
USER_OUT_DIR = $(BUILD_DIR)/userprog
|
||||
INIT_OUT_DIR = $(BUILD_DIR)/init
|
||||
|
||||
# [AUTOMATION]
|
||||
USER_DIRS = $(wildcard $(USERPROG_DIR)/*)
|
||||
USER_NAMES = $(notdir $(USER_DIRS))
|
||||
USER_BINS = $(addprefix $(USER_OUT_DIR)/, $(USER_NAMES))
|
||||
|
||||
# Config & Tools
|
||||
DISK_SIZE_MB = 512
|
||||
|
||||
ROOT_SIZE_MB = 256
|
||||
@@ -30,10 +28,11 @@ GRUB_LIB = /usr/lib/grub/i386-pc
|
||||
DD = dd status=none
|
||||
DEBUGFS = debugfs
|
||||
|
||||
# Sources & Artifacts
|
||||
# --
|
||||
KERNEL_SRC_BIN = $(KERNEL_DIR)/arch/x86/boot/bzImage
|
||||
INIT_SRC = $(INIT_DIR)/init.c
|
||||
GRUB_CFG_SRC = $(GRUB_DIR)/grub.cfg
|
||||
# --
|
||||
|
||||
INIT_BIN = $(INIT_OUT_DIR)/init
|
||||
|
||||
@@ -45,7 +44,7 @@ CORE_IMG = $(BUILD_DIR)/core.img
|
||||
# ==============================================================================
|
||||
# 2. Main Targets
|
||||
# ==============================================================================
|
||||
.PHONY: all clean run dirs help force_look
|
||||
.PHONY: all clean run dirs help
|
||||
|
||||
all: dirs $(DISK_IMG)
|
||||
@echo " [DONE] Image ready: $(DISK_IMG)"
|
||||
@@ -53,17 +52,21 @@ all: dirs $(DISK_IMG)
|
||||
run: $(DISK_IMG)
|
||||
qemu-system-x86_64 -drive file=$(DISK_IMG),format=raw -nographic \
|
||||
-net nic,model=e1000 -net user
|
||||
@echo " [SYNC] Saving session data to homefs.img..."
|
||||
@$(DD) if=$(DISK_IMG) of=$(HOME_IMG) bs=512 skip=$(HOME_OFFSET) count=$(HOME_SECTORS) status=none
|
||||
@echo " -> Data saved successfully."
|
||||
|
||||
dirs:
|
||||
@mkdir -p $(BUILD_DIR) $(USER_OUT_DIR) $(INIT_OUT_DIR)
|
||||
# @mkdir -p $(USER_OUT_DIR)
|
||||
# @mkdir -p $(INIT_OUT_DIR)
|
||||
|
||||
clean:
|
||||
@echo " [CLEAN] Cleaning root build dir..."
|
||||
@rm -rf $(BUILD_DIR)
|
||||
# @rm -rf $(BUILD_DIR)
|
||||
@if [ -d $(BUILD_DIR) ]; then \
|
||||
find $(BUILD_DIR) -type f ! -name "homefs.img" -delete; \
|
||||
fi
|
||||
|
||||
@echo " [CLEAN] Cleaning user programs..."
|
||||
@# 각 유저 프로그램 폴더 들어가서 make clean 실행
|
||||
@for dir in $(USER_DIRS); do \
|
||||
if [ -f $$dir/Makefile ]; then $(MAKE) -C $$dir clean; fi; \
|
||||
done
|
||||
@@ -108,6 +111,7 @@ $(ROOT_IMG): $(INIT_BIN) $(USER_BINS) $(KERNEL_SRC_BIN) $(GRUB_CFG_SRC) | dirs
|
||||
@$(DEBUGFS) -w -R "mkdir /sys" $@ > /dev/null 2>&1
|
||||
@$(DEBUGFS) -w -R "mkdir /tmp" $@ > /dev/null 2>&1
|
||||
@$(DEBUGFS) -w -R "mkdir /home" $@ > /dev/null 2>&1
|
||||
@$(DEBUGFS) -w -R "mkdir /ext" $@ > /dev/null 2>&1
|
||||
|
||||
@echo " -> Injecting System Binaries..."
|
||||
@$(DEBUGFS) -w -R "write $(INIT_BIN) /init" $@ > /dev/null 2>&1
|
||||
@@ -118,20 +122,24 @@ $(ROOT_IMG): $(INIT_BIN) $(USER_BINS) $(KERNEL_SRC_BIN) $(GRUB_CFG_SRC) | dirs
|
||||
$(DEBUGFS) -w -R "write $(USER_OUT_DIR)/$$prog /bin/$$prog" $@ > /dev/null 2>&1; \
|
||||
done
|
||||
|
||||
$(HOME_IMG): | dirs
|
||||
@echo " [HOME] Checking Home Filesystem..."
|
||||
|
||||
@if [ -f $(DISK_IMG) ]; then \
|
||||
echo " -> Extracting HomeFS from disk.img (Preserving Data)..."; \
|
||||
$(DD) if=$(DISK_IMG) of=$@ bs=512 skip=$(HOME_OFFSET) count=$(HOME_SECTORS); \
|
||||
elif [ ! -f $@ ]; then \
|
||||
echo " -> Creating new HomeFS (Format)..."; \
|
||||
$(DD) if=/dev/zero of=$@ bs=1M count=$(HOME_SIZE_MB); \
|
||||
mkfs.ext4 -q -O ^64bit,^metadata_csum $@; \
|
||||
else \
|
||||
echo " -> Using existing homefs.img"; \
|
||||
@if [ -d ext ]; then \
|
||||
echo " -> Injecting external files from ./ext..."; \
|
||||
for file in ext/*; do \
|
||||
if [ -f "$$file" ]; then \
|
||||
fname=$$(basename "$$file"); \
|
||||
$(DEBUGFS) -w -R "write $$file /ext/$$fname" $@ > /dev/null 2>&1; \
|
||||
fi; \
|
||||
done; \
|
||||
fi
|
||||
|
||||
$(HOME_IMG): | dirs
|
||||
@if [ ! -f $@ ]; then \
|
||||
echo " [HOME] Creating NEW Home Filesystem..."; \
|
||||
$(DD) if=/dev/zero of=$@ bs=1M count=$(HOME_SIZE_MB) status=none; \
|
||||
mkfs.ext4 -q -O ^64bit,^metadata_csum $@; \
|
||||
else \
|
||||
echo " [HOME] Using existing homefs.img."; \
|
||||
fi
|
||||
|
||||
$(DISK_IMG): $(ROOT_IMG) $(HOME_IMG) $(CORE_IMG)
|
||||
@echo " [ASM] Assembling disk with partitions..."
|
||||
@@ -150,12 +158,4 @@ $(DISK_IMG): $(ROOT_IMG) $(HOME_IMG) $(CORE_IMG)
|
||||
|
||||
@echo " -> Installing GRUB..."
|
||||
@$(DD) if=$(GRUB_LIB)/boot.img of=$@ bs=446 count=1 conv=notrunc
|
||||
@$(DD) if=$(CORE_IMG) of=$@ bs=512 seek=1 conv=notrunc
|
||||
|
||||
# $(DISK_IMG): $(PART_IMG) $(CORE_IMG)
|
||||
# @echo " [ASM] Assembling disk..."
|
||||
# @$(DD) if=/dev/zero of=$@ bs=1M count=$(DISK_SIZE_MB)
|
||||
# @echo "2048,,83,*" | sfdisk $@ > /dev/null 2>&1
|
||||
# @$(DD) if=$(PART_IMG) of=$@ bs=512 seek=$(SECTOR_OFF) conv=notrunc
|
||||
# @$(DD) if=$(GRUB_LIB)/boot.img of=$@ bs=446 count=1 conv=notrunc
|
||||
# @$(DD) if=$(CORE_IMG) of=$@ bs=512 seek=1 conv=notrunc
|
||||
@$(DD) if=$(CORE_IMG) of=$@ bs=512 seek=1 conv=notrunc
|
||||
Reference in New Issue
Block a user