-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (121 loc) · 5.05 KB
/
Copy pathMakefile
File metadata and controls
147 lines (121 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
BOARD ?= qemu-virt
CROSS ?= aarch64-elf-
CC := $(CROSS)gcc
OBJCOPY := $(CROSS)objcopy
SRC := src
BUILD := build/$(BOARD)
DISK_IMG := build/disk.img
CFLAGS := -ffreestanding -nostdlib -nostartfiles \
-mcpu=cortex-a72 -mgeneral-regs-only \
-fno-pic -fno-stack-protector \
-O2 -Wall -Wextra -Wpedantic -std=c11 \
-I$(SRC) -include $(SRC)/board/$(BOARD).h
ASFLAGS := -ffreestanding -nostdlib -nostartfiles -mcpu=cortex-a72 \
-include $(SRC)/board/$(BOARD).h
LDFLAGS := -nostdlib -nostartfiles -Wl,-T,linker/$(BOARD).ld -Wl,--build-id=none
CORE_C := $(SRC)/kernel.c $(SRC)/uart.c $(SRC)/str.c $(SRC)/console.c \
$(SRC)/shell.c $(SRC)/fs.c $(SRC)/sysinfo.c $(SRC)/psci.c \
$(SRC)/heap.c $(SRC)/accounts.c $(SRC)/pkgmgr.c $(SRC)/elf.c \
$(SRC)/sha256.c $(SRC)/panic.c
ifeq ($(BOARD),qemu-virt)
C_SRCS := $(CORE_C) $(SRC)/exceptions.c $(SRC)/gic.c $(SRC)/timer.c \
$(SRC)/virtio.c $(SRC)/virtio_input.c $(SRC)/virtio_mouse.c \
$(SRC)/virtio_blk.c $(SRC)/virtio_net.c $(SRC)/net.c \
$(SRC)/tcp.c $(SRC)/http.c $(SRC)/pkgstore.c $(SRC)/dns.c \
$(SRC)/mmu.c \
$(SRC)/task.c $(SRC)/syscall.c $(SRC)/user_program.c \
$(SRC)/fb.c $(SRC)/fb_console.c $(SRC)/window.c \
$(SRC)/desktop.c $(SRC)/login.c $(SRC)/boot_splash.c \
$(SRC)/wallpaper.c $(SRC)/browser.c $(SRC)/maker.c \
$(SRC)/fw_cfg.c $(SRC)/font.c
S_SRCS := $(SRC)/boot.S $(SRC)/vectors.S $(SRC)/switch.S
else
C_SRCS := $(CORE_C) $(SRC)/user_program.c
S_SRCS := $(SRC)/boot.S
endif
OBJS := $(patsubst $(SRC)/%.c,$(BUILD)/%.o,$(C_SRCS)) \
$(patsubst $(SRC)/%.S,$(BUILD)/%.o,$(S_SRCS))
ELF := $(BUILD)/kernel.elf
IMG := $(BUILD)/kernel.img
ifeq ($(BOARD),raspi5)
PI_IMG := $(BUILD)/kernel_2712.img
ALL := $(ELF) $(IMG) $(PI_IMG)
else
ALL := $(ELF) $(IMG)
endif
.PHONY: all run clean pkg-build pkg-build-all repo-rebuild mkt-rebuild
all: $(ALL) $(DISK_IMG)
$(DISK_IMG):
@mkdir -p $(@D)
dd if=/dev/zero of=$@ bs=1m count=4 2>/dev/null
$(BUILD):
@mkdir -p $(BUILD)
$(BUILD)/%.o: $(SRC)/%.c | $(BUILD)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD)/%.o: $(SRC)/%.S | $(BUILD)
$(CC) $(ASFLAGS) -c $< -o $@
$(ELF): $(OBJS)
$(CC) $(LDFLAGS) $^ -o $@
$(IMG): $(ELF)
$(OBJCOPY) -O binary $< $@
$(PI_IMG): $(IMG)
cp $< $@
QEMU_BASE := -M virt,gic-version=2 -cpu cortex-a72 -smp 4 -m 256M \
-global virtio-mmio.force-legacy=false \
-device ramfb -device virtio-keyboard-device \
-device virtio-tablet-device \
-drive file=$(DISK_IMG),if=none,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=n0 -device virtio-net-device,netdev=n0
run: $(ELF)
qemu-system-aarch64 $(QEMU_BASE) -display none -serial stdio -kernel $<
run-graphic: $(ELF)
qemu-system-aarch64 $(QEMU_BASE) -display cocoa -serial stdio -kernel $<
# Full interactive mode: VNC server with input grab. macOS Cocoa
# doesn't reliably forward mouse/keyboard into virtio-input on its
# own; a VNC client (e.g. macOS Screen Sharing -> 'vnc://localhost:5901')
# captures host events properly and pumps them into the guest.
run-vnc: $(ELF)
@echo "QEMU listening on vnc://localhost:5901"
@echo "macOS Screen Sharing: open vnc://localhost:5901"
@echo "(no password; just hit 'Connect' / Enter)"
qemu-system-aarch64 $(QEMU_BASE) -vnc 127.0.0.1:1,to=10 -display none -serial stdio -kernel $<
screenshot: $(ELF)
bash scripts/screenshot.sh
clean:
rm -rf build
# Cross-compile a single package source under tools/repo/packages/<NAME>/source
# into a static ELF, refresh sha256 + size in its manifest.
#
# make pkg-build NAME=hello
pkg-build:
@if [ -z "$(NAME)" ]; then echo "usage: make pkg-build NAME=<pkgname>"; exit 64; fi
tools/sdk/build_pkg.sh $(NAME)
# Build every package that ships a source/ directory.
pkg-build-all:
@for d in tools/repo/packages/*/source; do \
name=$$(basename $$(dirname $$d)); \
tools/sdk/build_pkg.sh $$name; \
done
# Rebuild the package-repo container image and (re)launch it on
# host port 8090. Run this after pkg-build-all so the manifests and
# .elf files inside the container match what's on disk.
repo-rebuild:
docker rm -f hobby-repo 2>/dev/null || true
docker build -t hobby-os-repo tools/repo
docker run -d --rm --name hobby-repo -p 8090:8080 hobby-os-repo
@echo "repo listening at http://localhost:8090"
# Build + (re)launch the marketplace backend (community programs +
# ratings + comments). Mounts tools/repo as /repo so the static
# .elf collection is served from the same service, and a local
# build/mkt-data dir as /data for the SQLite database. Drop the
# existing hobby-repo first so the port lines up.
mkt-rebuild:
docker rm -f hobby-repo 2>/dev/null || true
docker build -t hobby-marketplace tools/marketplace
mkdir -p build/mkt-data
docker run -d --rm --name hobby-repo -p 8090:8080 \
-v $$(pwd)/tools/repo:/repo \
-v $$(pwd)/build/mkt-data:/data \
hobby-marketplace
@echo "marketplace listening at http://localhost:8090"