Makefile 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  1. # NebOS top-level build.
  2. #
  3. # Source tree:
  4. # boot/ real-mode boot sector, MBR, VESA stage, UEFI loader (boot/efi)
  5. # kernel/ the 32-bit kernel (kernel.ld, drivers, services)
  6. # common/ freestanding code linked into both the kernel and userland
  7. # include/ ABI headers shared by boot, kernel, userland and host tools
  8. # user/apps/<n>/ one directory per ring-3 program (ucmd_<n>.c + its modules)
  9. # user/lib/<l>/ ring-3 libraries (libc, ngui, ufont, img, tls, uhttp, ...)
  10. # tools/ host-side tools (mkpack, mkrootfs, kexec_send, ...)
  11. # host/ Linux SDL3 browser harness
  12. #
  13. # Intermediate objects go to build/ (mirroring the source paths). The images
  14. # and the artifacts the dev workflow uses (kernel.elf, kernel.bin, floppy.img,
  15. # usb.img, usb-efi.img, BOOTX64.EFI, cmds.pack, browser.elf, ...) stay at the
  16. # top level, so every make target and command line works as before.
  17. CC = gcc
  18. AS = as
  19. LD = ld
  20. OBJCOPY = objcopy
  21. B = build
  22. # -march=i586: first-gen Pentium (P5); avoids CMOV etc. (P6+)
  23. CFLAGS = -ffreestanding -fno-pie -m32 -march=i586 -nostdlib -fno-stack-protector \
  24. -fno-asynchronous-unwind-tables -mno-sse -mno-sse2 -mno-mmx \
  25. -Wall -Wextra -O2 -c
  26. # Ring-3 objects are compiled with function sections so the browser link can
  27. # drop code it never reaches; the legacy rootfs pack is close to its cap.
  28. SECTION_CFLAGS = -ffunction-sections -fdata-sections
  29. # Header dependencies are generated by the compiler (build/**/*.d).
  30. DEPFLAGS = -MMD -MP
  31. ASFLAGS = --32
  32. # NOWM=1 builds a diagnostic kernel that boots to the console without the
  33. # window manager (make nowm).
  34. NOWM ?= 0
  35. ifeq ($(NOWM),1)
  36. CFLAGS += -DNOWM
  37. endif
  38. # Include paths. The kernel sees only its own headers plus the shared ABI and
  39. # common code; ring-3 code sees the user libraries. Quoted includes of a
  40. # file's own directory need no -I (e.g. an app's private headers).
  41. USER_LIB_DIRS = $(sort $(dir $(wildcard user/lib/*/)))
  42. USER_LIB_DIRS := $(filter-out user/lib/libc/,$(USER_LIB_DIRS))
  43. KERNEL_INC = -Iinclude -Icommon -Ikernel
  44. USER_INC = -Iinclude -Icommon -Iuser $(patsubst %/,-I%,$(USER_LIB_DIRS))
  45. LIBC_INC = -Iuser/lib/libc/include
  46. # QuickJS (third_party/quickjs, see its VENDOR file) is the browser's
  47. # JavaScript engine. -nostdinc keeps host headers from leaking into the
  48. # freestanding build; __nebos__ selects the local patches.
  49. QJS_DIR = third_party/quickjs
  50. QJS_CFLAGS = $(CFLAGS) -O1 $(SECTION_CFLAGS) -nostdinc $(LIBC_INC) \
  51. -I$(QJS_DIR) -fno-builtin -w -D__nebos__ -U__linux__ \
  52. -U__gnu_linux__ -U__unix__ -U__GLIBC__ -DNDEBUG \
  53. -DCONFIG_VERSION='"2026-06-04"'
  54. QJS_OBJS = $(addprefix $(B)/$(QJS_DIR)/,quickjs.o cutils.o dtoa.o \
  55. libregexp.o libunicode.o)
  56. # UEFI loader: a PE32+ x86-64 EFI application built with the mingw toolchain.
  57. # The kernel itself stays 32-bit; the loader leaves long mode before jumping.
  58. EFI_CC ?= x86_64-w64-mingw32-gcc
  59. EFI_AS ?= x86_64-w64-mingw32-as
  60. EFI_CFLAGS = -ffreestanding -fno-stack-protector -mno-red-zone -fno-builtin \
  61. -fno-asynchronous-unwind-tables -fno-unwind-tables -O2 \
  62. -Wall -Wextra -Iinclude -Ikernel -Iboot/efi -I$(B)/boot/efi
  63. EFI_LDFLAGS = -nostdlib -Wl,--subsystem,10 -Wl,-e,efi_main \
  64. -Wl,--image-base,0x0 -Wl,--dynamicbase \
  65. -Wl,--enable-reloc-section -Wl,--no-insert-timestamp
  66. .PHONY: all clean run run-smp run-floppy run-usb run-uhci run-ehci run-ehci-asix run-xhci run-xhci-asix run-net run-rndis run-e1000 run-ahci run-amd test-amd test-usb test-install run-serial floppy usb uefi run-uefi test-uefi flash dev net-dev net-install cmds-dev net-cmds browser-dev gallery-dev compat-serve netmon monitor test-crypto test-wpa test-ccmp test-images test-images-asan test-libc test-js test-font test-font-asan test-svg test-touchpad test-chat test-chat-e2e test-wifi-store fonts kernel-dev kernel-net-dev rootfs nowm
  67. all: floppy.img usb.img final.bin root.img image.bin
  68. # ---- Generic compile rules -------------------------------------------------
  69. #
  70. # Per-object variations are target-specific variables on the .o:
  71. # OPT optimisation override appended after CFLAGS' -O2 (-Os, -Oz)
  72. # XFLAGS extra flags (function sections, libc headers, -fwrapv, ...)
  73. $(B)/kernel/%.o: kernel/%.c
  74. @mkdir -p $(@D)
  75. $(CC) $(CFLAGS) $(OPT) $(XFLAGS) $(KERNEL_INC) $(DEPFLAGS) -o $@ $<
  76. $(B)/common/%.o: common/%.c
  77. @mkdir -p $(@D)
  78. $(CC) $(CFLAGS) $(SECTION_CFLAGS) -Icommon $(DEPFLAGS) -o $@ $<
  79. # Ring-3 C: by default the libc headers are visible (the old ucmd_%.o rule);
  80. # objects that were always built freestanding clear XFLAGS below.
  81. $(B)/user/%.o: XFLAGS = $(LIBC_INC)
  82. $(B)/user/%.o: user/%.c
  83. @mkdir -p $(@D)
  84. $(CC) $(CFLAGS) $(OPT) $(XFLAGS) $(USER_INC) $(DEPFLAGS) -o $@ $<
  85. $(B)/%.o: %.S
  86. @mkdir -p $(@D)
  87. $(AS) $(ASFLAGS) -I$(<D) -o $@ $<
  88. $(B)/$(QJS_DIR)/%.o: $(QJS_DIR)/%.c
  89. @mkdir -p $(@D)
  90. $(CC) $(QJS_CFLAGS) $(DEPFLAGS) -o $@ $<
  91. # ---- Kernel ----------------------------------------------------------------
  92. # Link order is part of the image layout: keep it stable. vesa_stage comes
  93. # from boot/ (it is the 0x7E00 entry), font_8x16/inflate from common/.
  94. KERNEL_LINK_ORDER = vesa_stage entry kernel timer switch sched process mm \
  95. kmalloc paging elf tss syscall sys_wm syscall_stub screen io tty rtc \
  96. terminal wm reboot poweroff disk fat serial serial_ring_buf serial_loop \
  97. vga blit cpu thermal it87 tpec ec cros_ec power_src power vga_copy \
  98. gfxbench gpu backlight ati cirrus intel nvidia nv50 radeon mtrr \
  99. font_8x8 font_8x16 fbtext gfx display mouse i2c touchpad \
  100. touchpad_gesture uhci ohci ehci xhci asix rndis iwl_trans iwl_mvm \
  101. iwl_dvm wifi_fw rtl8821au wifi ccmp usb usbmsc usbhid lsusb panic \
  102. bootcon blkdev sdhci ata ahci fatdetect fatformat format install vfs \
  103. sys_fs sys_info sys_mem sys_net idle kexec kexec_tramp dbg lspci peek \
  104. ne2000 r8168 e1000e netdev net netcore netkexec netlog dhcp dns ntp tcp \
  105. acpi ioapic lapic smp ap_tramp_embed inflate ramfs share payload
  106. kobj = $(if $(filter vesa_stage,$(1)),$(B)/boot/$(1).o,$(if $(filter \
  107. font_8x16 inflate,$(1)),$(B)/common/$(1).o,$(B)/kernel/$(1).o))
  108. KERNEL_OBJS = $(foreach n,$(KERNEL_LINK_ORDER),$(call kobj,$(n)))
  109. KERNEL_OS = terminal disk fat nvidia nv50 uhci ohci ehci xhci asix rndis \
  110. iwl_trans iwl_mvm iwl_dvm wifi_fw rtl8821au wifi ccmp usb lsusb lspci \
  111. peek ne2000 r8168 blkdev fatdetect fatformat format install usbmsc dbg vfs
  112. $(addprefix $(B)/kernel/,$(addsuffix .o,$(KERNEL_OS))): OPT = -Os
  113. $(B)/kernel/e1000e.o: OPT = -Oz
  114. # The AP trampoline is linked at 0x6000 and embedded as a binary blob; ld
  115. # names its symbols after the input path, so run it inside the build dir
  116. # (smp.c expects _binary_ap_tramp_bin_start).
  117. $(B)/kernel/ap_tramp.elf: $(B)/kernel/ap_tramp.o kernel/ap_tramp.ld
  118. $(LD) -T kernel/ap_tramp.ld -nostdlib -m elf_i386 -o $@ $<
  119. $(B)/kernel/ap_tramp.bin: $(B)/kernel/ap_tramp.elf
  120. $(OBJCOPY) -O binary $< $@
  121. $(B)/kernel/ap_tramp_embed.o: $(B)/kernel/ap_tramp.bin
  122. cd $(B)/kernel && $(LD) -m elf_i386 -r -b binary -o ap_tramp_embed.o ap_tramp.bin
  123. kernel.elf: kernel/kernel.ld $(KERNEL_OBJS)
  124. $(LD) -T kernel/kernel.ld -nostdlib -m elf_i386 -o $@ $(KERNEL_OBJS)
  125. kernel.bin: kernel.elf
  126. $(OBJCOPY) -O binary $< $@
  127. # ---- Boot sector and MBR ---------------------------------------------------
  128. $(B)/boot/boot.elf: $(B)/boot/boot.o boot/linker.ld
  129. $(LD) -T boot/linker.ld -nostdlib -m elf_i386 -o $@ $<
  130. $(B)/boot/mbr.elf: $(B)/boot/mbr.o boot/mbr.ld
  131. $(LD) -T boot/mbr.ld -nostdlib -m elf_i386 -o $@ $<
  132. mbr.bin: $(B)/boot/mbr.elf
  133. $(OBJCOPY) -O binary $< $@
  134. boot.bin: $(B)/boot/boot.elf
  135. $(OBJCOPY) -O binary --only-section=.boot $< $@.tmp
  136. dd if=$@.tmp of=$@ bs=1 count=510 2>/dev/null
  137. printf '\x55\xaa' >> $@
  138. rm -f $@.tmp
  139. # Byte offsets inside boot.bin (see boot.S). Keep decimal: dd's seek= does not
  140. # parse 0x… literals (it silently treats them as 0) and the error is hidden by
  141. # the 2>/dev/null below.
  142. # 62 = kernel_sectors field (0x3E)
  143. # 64 = kernel_lba field (0x40, word; LBA 64 fits in the low byte)
  144. # 66 = pack_lba field (0x42, dword; rootfs image LBA)
  145. KERNEL_SECTORS_OFFSET = 62
  146. BOOT_SECTOR_START_OFFSET = 64
  147. PACK_LBA_OFFSET = 66
  148. # USB rootfs partition (type 0x7F) and UEFI ESP (type 0xEF). Partition 1
  149. # has room for a 512 KB kernel; the rootfs starts after it at LBA 1088.
  150. # The header and the 242 KB gzip pack are still inside the first 1.44 MB.
  151. ROOTFS_LBA = 1088
  152. ROOTFS_SECTORS = 16384
  153. ESP_LBA = 18432
  154. # Patch a little-endian 16/32-bit value into a boot-sector copy. Usage:
  155. # $(call patch16,file,offset,value)
  156. # (shell snippets are inlined below because make functions cannot easily
  157. # expand `$$(...)` arithmetic; the helpers keep the rules readable.)
  158. patch32 = printf "$$(printf '\\x%02x\\x%02x\\x%02x\\x%02x' \
  159. $$(( ( ($(2)) >> 0) & 0xFF )) $$(( ( ($(2)) >> 8) & 0xFF )) \
  160. $$(( ( ($(2)) >> 16) & 0xFF )) $$(( ( ($(2)) >> 24) & 0xFF )))" | \
  161. dd of=$(1) bs=1 seek=$(3) conv=notrunc 2>/dev/null
  162. patch16 = printf "$$(printf '\\x%02x\\x%02x' \
  163. $$(( ( ($(2)) >> 0) & 0xFF )) $$(( ( ($(2)) >> 8) & 0xFF )))" | \
  164. dd of=$(1) bs=1 seek=$(3) conv=notrunc 2>/dev/null
  165. floppy.img: boot.bin kernel.bin rootfs.bin
  166. SECTORS=$$(( ($$(stat -c%s kernel.bin) + 511) / 512 )); \
  167. cp boot.bin $@.boot.tmp; \
  168. $(call patch16,$@.boot.tmp,$$SECTORS,$(KERNEL_SECTORS_OFFSET)); \
  169. $(call patch32,$@.boot.tmp,1 + SECTORS,$(PACK_LBA_OFFSET)); \
  170. cat $@.boot.tmp kernel.bin > $@; \
  171. PAD=$$(( SECTORS * 512 - $$(stat -c%s kernel.bin) )); \
  172. dd if=/dev/zero bs=1 count=$$PAD 2>/dev/null >> $@; \
  173. cat rootfs.bin >> $@; \
  174. SIZE=$$(stat -c%s $@); \
  175. if [ $$SIZE -gt 1474560 ]; then \
  176. echo "error: floppy.img is $$SIZE bytes; max is 1474560"; \
  177. rm -f $@; exit 1; \
  178. fi; \
  179. truncate -s 1474560 $@; \
  180. rm -f $@.boot.tmp
  181. usb.img: mbr.bin boot.bin kernel.bin cmds.img
  182. SECTORS=$$(( ($$(stat -c%s kernel.bin) + 511) / 512 )); \
  183. cp boot.bin $@.boot.tmp; \
  184. $(call patch16,$@.boot.tmp,$$SECTORS,$(KERNEL_SECTORS_OFFSET)); \
  185. printf '\x40' | dd of=$@.boot.tmp bs=1 seek=$(BOOT_SECTOR_START_OFFSET) conv=notrunc 2>/dev/null; \
  186. $(call patch32,$@.boot.tmp,$(ROOTFS_LBA),$(PACK_LBA_OFFSET)); \
  187. cat mbr.bin > $@; \
  188. dd if=/dev/zero bs=512 count=62 2>/dev/null >> $@; \
  189. cat $@.boot.tmp kernel.bin >> $@; \
  190. truncate -s 9M $@; \
  191. dd if=cmds.img of=$@ bs=512 seek=$(ROOTFS_LBA) conv=notrunc 2>/dev/null; \
  192. printf '\x00\x11\x12\x00\x7f\x16\x15\x01\x40\x04\x00\x00\x00\x40\x00\x00' | \
  193. dd of=$@ bs=1 seek=462 conv=notrunc 2>/dev/null; \
  194. rm -f $@.boot.tmp
  195. image.bin: floppy.img
  196. cp floppy.img image.bin
  197. final.bin: boot.bin kernel.bin rootfs.bin
  198. SECTORS=$$(( ($$(stat -c%s kernel.bin) + 511) / 512 )); \
  199. cp boot.bin $@.boot.tmp; \
  200. $(call patch16,$@.boot.tmp,$$SECTORS,$(KERNEL_SECTORS_OFFSET)); \
  201. $(call patch32,$@.boot.tmp,1 + SECTORS,$(PACK_LBA_OFFSET)); \
  202. cat $@.boot.tmp kernel.bin > $@; \
  203. PAD=$$(( SECTORS * 512 - $$(stat -c%s kernel.bin) )); \
  204. dd if=/dev/zero bs=1 count=$$PAD 2>/dev/null >> $@; \
  205. cat rootfs.bin >> $@; \
  206. rm -f $@.boot.tmp
  207. # ---- UEFI loader and dual-boot USB image -------------------------------
  208. #
  209. # The legacy image (usb.img) is left byte-for-byte alone. usb-efi.img copies
  210. # it, adds a third MBR partition (type 0xEF, starting at the old 64 MB end)
  211. # and writes a small FAT16 ESP there. BIOS booting still uses the active
  212. # partition 1 at LBA 63; UEFI finds BOOTX64.EFI in the ESP.
  213. $(B)/boot/efi/efi_entry.h: kernel.elf
  214. @mkdir -p $(@D)
  215. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  216. if [ -z "$$entry" ]; then echo "efi: kernel_entry not found" >&2; exit 1; fi; \
  217. printf '#define KERNEL_ENTRY 0x%s\n' "$$entry" > $@
  218. $(B)/boot/efi/main.o: boot/efi/main.c $(B)/boot/efi/efi_entry.h
  219. @mkdir -p $(@D)
  220. $(EFI_CC) $(EFI_CFLAGS) $(DEPFLAGS) -c -o $@ $<
  221. # payload.S embeds kernel.bin and cmds_pack_gz.bin (top level) and tramp.bin.
  222. $(B)/boot/efi/payload.o: boot/efi/payload.S kernel.bin cmds_pack_gz.bin $(B)/boot/efi/tramp.bin
  223. $(EFI_AS) --64 -I$(B)/boot/efi -o $@ $<
  224. $(B)/boot/efi/tramp.o: boot/efi/tramp.S
  225. @mkdir -p $(@D)
  226. $(AS) --64 -o $@ $<
  227. $(B)/boot/efi/tramp.elf: $(B)/boot/efi/tramp.o boot/efi/tramp.ld
  228. $(LD) -T boot/efi/tramp.ld -nostdlib -m elf_x86_64 -o $@ $<
  229. $(B)/boot/efi/tramp.bin: $(B)/boot/efi/tramp.elf
  230. $(OBJCOPY) -O binary $< $@
  231. BOOTX64.EFI: $(B)/boot/efi/main.o $(B)/boot/efi/payload.o
  232. $(EFI_CC) $(EFI_LDFLAGS) -o $@ $^
  233. ESP_SECTORS = 16384
  234. esp.img: BOOTX64.EFI
  235. truncate -s $$(( $(ESP_SECTORS) * 512 )) $@
  236. mkfs.fat -F 16 -s 2 -n NEBOSESP $@
  237. mmd -i $@ ::/EFI
  238. mmd -i $@ ::/EFI/BOOT
  239. mcopy -i $@ BOOTX64.EFI ::/EFI/BOOT/BOOTX64.EFI
  240. usb-efi.img: usb.img esp.img
  241. cp usb.img $@
  242. # The legacy partition is a raw kernel blob with a deliberately empty
  243. # BPB (boot.S), so neither UEFI firmware nor VFS mistakes it for FAT.
  244. # Partition 3: ESP at LBA 18432, type 0xEF, 8 MB (partition 2 is the
  245. # rootfs at LBA 1088 written by usb.img).
  246. printf '\x00\xfe\xff\xff\xef\xfe\xff\xff\x00\x48\x00\x00\x00\x40\x00\x00' | \
  247. dd of=$@ bs=1 seek=478 conv=notrunc 2>/dev/null
  248. dd if=esp.img of=$@ bs=512 seek=$(ESP_LBA) conv=notrunc 2>/dev/null
  249. truncate -s $$(( ($(ESP_LBA) + $(ESP_SECTORS)) * 512 )) $@
  250. uefi: usb-efi.img
  251. # ---- Ring-3 libraries ------------------------------------------------------
  252. U = $(B)/user
  253. UL = $(B)/user/lib
  254. # libc: a static archive linked only into commands that use it. The archive
  255. # means apps that never reference malloc/string keep paying nothing, and
  256. # --gc-sections drops unused functions from the members that are pulled.
  257. LIBC_OBJS = $(addprefix $(UL)/libc/,malloc.o string.o strdup.o stdlib.o \
  258. ucmd_mem.o setjmp.o errno.o div64.o dtoa.o stdio.o \
  259. stdio_file.o math.o time.o)
  260. LIBC_A = $(UL)/libc/libc.a
  261. $(filter-out %/setjmp.o,$(LIBC_OBJS)): OPT = -Os
  262. $(filter-out %/setjmp.o,$(LIBC_OBJS)): XFLAGS = $(SECTION_CFLAGS) -fno-builtin $(LIBC_INC)
  263. $(LIBC_A): $(LIBC_OBJS)
  264. rm -f $@
  265. ar rcs $@ $^
  266. # 8x16 bitmap font and DEFLATE: shared with the kernel (common/).
  267. FONT16 = $(B)/common/font_8x16.o
  268. INFLATE = $(B)/common/inflate.o
  269. # Fixed-point TrueType text engine, linked only into GUI commands.
  270. UFONT_OBJS = $(addprefix $(UL)/ufont/,ufont.o ufont_ttf.o ufont_draw.o ufont_file.o)
  271. $(UFONT_OBJS): OPT = -Os
  272. $(UFONT_OBJS): XFLAGS = $(SECTION_CFLAGS) $(LIBC_INC)
  273. $(UL)/ufont/ufont_ttf.o: OPT = -O2
  274. # ngui: the userland immediate-mode GUI toolkit. -Os: every GUI app links
  275. # the whole toolkit, and the rootfs pack has a cap.
  276. NGUI = $(UL)/ngui/ngui.o
  277. $(NGUI): OPT = -Os
  278. $(NGUI): XFLAGS = $(SECTION_CFLAGS) $(LIBC_INC)
  279. NGUI_APP = $(NGUI) $(FONT16) $(UFONT_OBJS)
  280. # Window-manager/terminal drawing helpers (wm and term).
  281. UWM = $(UL)/uwm/uwm_lib.o
  282. $(UWM): OPT = -Os
  283. $(UWM): XFLAGS = $(SECTION_CFLAGS) $(LIBC_INC)
  284. # Image library: pure freestanding decoders + RGB565 compositing.
  285. IMGLIB_OBJS = $(addprefix $(UL)/img/,img.o img_mem.o img_blit.o img_png.o \
  286. img_bmp.o img_gif.o img_jpeg.o img_tga.o img_pnm.o img_ico.o \
  287. img_pam.o img_gif_anim.o img_file.o)
  288. IMG_DECODE_OBJS = $(addprefix $(UL)/img/,img.o img_mem.o img_blit.o img_png.o \
  289. img_bmp.o img_gif.o img_jpeg.o img_tga.o img_pnm.o img_ico.o \
  290. img_pam.o)
  291. $(IMGLIB_OBJS): XFLAGS = $(SECTION_CFLAGS)
  292. # The integer IDCT deliberately relies on 32-bit wrap-around.
  293. $(UL)/img/img_jpeg.o: XFLAGS = $(SECTION_CFLAGS) -fwrapv
  294. # TLS 1.3/1.2 client library (curl, chat and the browser; see tls.h). The
  295. # crypto files are pure freestanding C, so tls_test exercises them on the
  296. # host (make test-crypto). TLS 1.2 adds AES-128-GCM (on wpa_crypto.c's AES)
  297. # and P-256 ECDH.
  298. TLSLIB_OBJS = $(addprefix $(UL)/tls/,tls_sha256.o tls_chacha20.o tls_x25519.o \
  299. tls_gcm.o tls_p256.o wpa_crypto.o tls_rng.o tls.o)
  300. $(TLSLIB_OBJS): XFLAGS = $(SECTION_CFLAGS)
  301. $(UL)/tls/wpa_crypto.o: OPT = -O2
  302. # Shared HTTP/TLS client (curl, the browser and chat), its cookie jar and the
  303. # JSON parser. The jar and the parser have host tests (make test-chat).
  304. UHTTP_OBJS = $(UL)/uhttp/uhttp.o $(UL)/uhttp/uhttp_cookie.o
  305. UJSON = $(UL)/ujson/ujson.o
  306. $(UHTTP_OBJS) $(UJSON): XFLAGS = $(SECTION_CFLAGS)
  307. $(UL)/uhttp/uhttp_cookie.o $(UJSON): OPT = -Os
  308. # WiFi saved-network list (wifi, netmenu) and the WPA2-PSK supplicant.
  309. WIFI_STORE = $(UL)/wifi/wifi_store.o
  310. WPA_OBJS = $(UL)/wifi/wpa.o $(UL)/tls/wpa_crypto.o
  311. $(UL)/wifi/wpa.o: OPT = -Os
  312. $(UL)/wifi/wpa.o: XFLAGS = $(SECTION_CFLAGS)
  313. # ---- Ring-3 programs -------------------------------------------------------
  314. #
  315. # Every program lives in user/apps/<name>/ with its entry file ucmd_<name>.c
  316. # and is packed as bin/<name>. New command: create user/apps/<name>/
  317. # ucmd_<name>.c and add <name> to UCMDS (the order is the pack order). A
  318. # single-file command needs nothing else; one that links libraries gets an
  319. # explicit .elf rule below.
  320. UCMDS = cpuinfo ls cat save rm mkdir rmdir \
  321. meminfo mouseinfo storage top \
  322. clock colors edit wm term spin \
  323. netinfo netip netdns host dhcp \
  324. netsend netrecv ping pong netlog \
  325. netconsole netregs netloop netreset net100 netmac curl \
  326. files view sensors powerinfo mines solitaire \
  327. settime date gallery websrv browser chat \
  328. wifi netmenu
  329. app = $(U)/apps/$(1)/ucmd_$(1)
  330. UCMD_ELFS = $(foreach a,$(UCMDS),$(call app,$(a)).elf)
  331. .PRECIOUS: $(UCMD_ELFS)
  332. UCMD_LD = user/ucmd.ld
  333. # Link a ring-3 ELF at USER_BASE, dropping unreferenced sections.
  334. ULINK = $(LD) -T $(UCMD_LD) -z max-page-size=0x100 --gc-sections -nostdlib \
  335. -m elf_i386 -o $@ $(filter-out $(UCMD_LD),$^) && \
  336. $(OBJCOPY) --strip-all $@ $@
  337. # Single-file commands: no libc, no section GC.
  338. $(U)/apps/%.elf: $(U)/apps/%.o $(UCMD_LD)
  339. $(LD) -T $(UCMD_LD) -z max-page-size=0x100 -nostdlib -m elf_i386 -o $@ $<
  340. $(OBJCOPY) --strip-all $@ $@
  341. # Objects that were always compiled without the libc headers.
  342. $(call app,edit).o $(call app,wm).o $(call app,files).o $(call app,mines).o \
  343. $(call app,settime).o $(call app,solitaire).o $(U)/apps/gallery/gallery.o \
  344. $(U)/apps/hello/hello.o: XFLAGS =
  345. $(call app,settime).o $(call app,solitaire).o: OPT = -Os
  346. # websrv buffers its whole PUT/GET body on the libc heap.
  347. $(call app,websrv).elf: $(call app,websrv).o $(UCMD_LD) $(LIBC_A)
  348. $(ULINK)
  349. # edit draws text itself, so it links the 8x16 font into its ELF.
  350. $(call app,edit).elf: $(call app,edit).o $(FONT16) $(UCMD_LD)
  351. $(LD) -T $(UCMD_LD) -z max-page-size=0x100 -nostdlib -m elf_i386 -o $@ $(filter %.o,$^)
  352. $(OBJCOPY) --strip-all $@ $@
  353. # The ring-3 WM draws its own chrome; term renders its own cells. term also
  354. # reads the kernel's key codes (io.h) and VFS_PATH_MAX (vfs.h).
  355. $(call app,term).o: XFLAGS = $(LIBC_INC) -Ikernel
  356. $(call app,wm).elf: $(call app,wm).o $(UWM) $(FONT16) $(UFONT_OBJS) $(UCMD_LD) $(LIBC_A)
  357. $(ULINK)
  358. $(call app,term).elf: $(call app,term).o $(UWM) $(FONT16) $(UFONT_OBJS) $(UCMD_LD) $(LIBC_A)
  359. $(ULINK)
  360. # ngui canvas apps.
  361. $(call app,files).elf: $(call app,files).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  362. $(ULINK)
  363. $(call app,mines).elf: $(call app,mines).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  364. $(ULINK)
  365. $(call app,settime).elf: $(call app,settime).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  366. $(ULINK)
  367. $(call app,solitaire).elf: $(call app,solitaire).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  368. $(ULINK)
  369. $(call app,view).elf: $(call app,view).o $(IMGLIB_OBJS) $(INFLATE) $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  370. $(ULINK)
  371. $(call app,curl).elf: $(call app,curl).o $(UHTTP_OBJS) $(IMG_DECODE_OBJS) $(INFLATE) $(TLSLIB_OBJS) $(UCMD_LD) $(LIBC_A)
  372. $(ULINK)
  373. $(call app,wifi).elf: $(call app,wifi).o $(WIFI_STORE) $(WPA_OBJS) $(UL)/tls/tls_rng.o $(UL)/tls/tls_sha256.o $(UCMD_LD) $(LIBC_A)
  374. $(ULINK)
  375. # Control panel: NIC list, WiFi scan, saved networks, power and date/time.
  376. $(call app,netmenu).elf: $(call app,netmenu).o $(WIFI_STORE) $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  377. $(ULINK)
  378. # chat: native Cloudron Chat client (ngui + uhttp/TLS + cookie jar + JSON +
  379. # the native OIDC login driver).
  380. CHAT_LOGIN = $(U)/apps/chat/chat_login.o
  381. $(CHAT_LOGIN): OPT = -Os
  382. $(CHAT_LOGIN): XFLAGS = $(SECTION_CFLAGS)
  383. $(call app,chat).o: OPT = -Os
  384. $(call app,chat).o: XFLAGS = $(SECTION_CFLAGS) $(LIBC_INC)
  385. $(call app,chat).elf: $(call app,chat).o $(CHAT_LOGIN) $(UJSON) $(UHTTP_OBJS) $(NGUI_APP) $(IMG_DECODE_OBJS) $(INFLATE) $(TLSLIB_OBJS) $(UCMD_LD) $(LIBC_A)
  386. $(ULINK)
  387. # gallery: a live showcase of every ngui widget and primitive. The real ELF
  388. # ships in the rootfs pack as bin/gallery.app; ucmd_gallery.c (in UCMDS) is
  389. # the tiny PATH launcher (which also accepts /share/GALLERY).
  390. gallery.elf: $(U)/apps/gallery/gallery.o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  391. $(ULINK)
  392. # browser: the real app ships as bin/browser.app (and BROWSER on root.img)
  393. # because it links ngui, the image library, TLS, uhttp and QuickJS;
  394. # ucmd_browser.c is the tiny PATH launcher. Compiled with function sections
  395. # and linked with --gc-sections: unreachable image, TLS and UI paths are
  396. # dropped.
  397. BR = $(U)/apps/browser
  398. BROWSER_OBJS = $(BR)/browser.o $(BR)/browser_html.o $(BR)/svg_raster.o \
  399. $(BR)/js_browser.o $(BR)/js_mu.o
  400. $(BROWSER_OBJS): OPT = -Os
  401. $(BROWSER_OBJS): XFLAGS = $(SECTION_CFLAGS) $(LIBC_INC)
  402. $(BR)/browser_html.o: XFLAGS = $(SECTION_CFLAGS)
  403. $(BR)/js_mu.o: XFLAGS = $(SECTION_CFLAGS) -Wno-unused-parameter $(LIBC_INC) -I$(QJS_DIR)
  404. browser.elf: $(BR)/browser.o $(BR)/browser_html.o $(BR)/svg_raster.o $(BR)/js_browser.o $(BR)/js_prelude.o $(UHTTP_OBJS) $(NGUI_APP) $(IMGLIB_OBJS) $(INFLATE) $(TLSLIB_OBJS) $(BR)/js_mu.o $(QJS_OBJS) $(UCMD_LD) $(LIBC_A)
  405. $(ULINK)
  406. # hello: the first ring-3 test program (its own linker script).
  407. $(U)/apps/hello/hello.elf: $(U)/apps/hello/hello.o user/apps/hello/hello.ld
  408. $(LD) -T user/apps/hello/hello.ld -nostdlib -m elf_i386 -o $@ $<
  409. $(OBJCOPY) --strip-all $@ $@
  410. # ---- Linux host browser harness (browser-host / host-curl) -------------------
  411. #
  412. # The browser talks to the same small SYS_* ABI as on NebOS; host/syscall.c
  413. # implements it with Linux files, BSD sockets, fork/exec and an SDL3 window.
  414. # The target images and browser.elf are not involved. Build 32-bit so the
  415. # pointer-through-int syscall ABI and the ring-3 allocator behave like the
  416. # board. SDL3 is only a development dependency for the window backend.
  417. HOST_CC ?= gcc
  418. HOST_BUILD = host/build
  419. HOST_CFLAGS = -m32 -O1 -g -Wall -Wextra -Wno-unused-parameter \
  420. -Wno-sign-compare -Wno-unused-function -Wno-format-truncation \
  421. -fno-strict-aliasing -fno-omit-frame-pointer $(USER_INC) \
  422. -Ihost/include -Ithird_party/quickjs -I/usr/include/SDL3 \
  423. -DUCMD_HOST -DJS_MU_HOST -D__nebos__ -D_GNU_SOURCE \
  424. -DCONFIG_VERSION='"2026-06-04"'
  425. # The ring-3 allocator is reused on the host: rename its entry points so
  426. # glibc and SDL keep their own malloc. libc/malloc.c and every app object
  427. # must use the same set.
  428. HOST_APP_MALLOC_DEFS = -Dmalloc=libc_malloc -Dfree=libc_free \
  429. -Dcalloc=libc_calloc -Drealloc=libc_realloc \
  430. -Dmalloc_usable_size=libc_malloc_usable_size \
  431. -Dheap_reset=libc_heap_reset
  432. HOST_APP_CFLAGS = $(HOST_CFLAGS) $(HOST_APP_MALLOC_DEFS)
  433. HOST_LDFLAGS = -m32 -no-pie -L/usr/lib32
  434. HOST_LDLIBS = -lSDL3 -lm -lpthread -ldl
  435. HOST_IMGLIB_SRCS = $(addprefix user/lib/img/,img.c img_mem.c img_blit.c \
  436. img_png.c img_bmp.c img_gif.c img_jpeg.c img_tga.c img_pnm.c \
  437. img_ico.c img_pam.c img_gif_anim.c img_file.c)
  438. HOST_TLS_SRCS = $(addprefix user/lib/tls/,tls_sha256.c tls_chacha20.c \
  439. tls_x25519.c tls_gcm.c tls_p256.c wpa_crypto.c tls_rng.c tls.c)
  440. HOST_QUERY_SRCS = $(addprefix $(QJS_DIR)/,quickjs.c cutils.c dtoa.c \
  441. libregexp.c libunicode.c)
  442. HOST_UHTTP_SRCS = user/lib/uhttp/uhttp.c user/lib/uhttp/uhttp_cookie.c
  443. HOST_BROWSER_APP_SRCS = $(addprefix user/apps/browser/,browser.c \
  444. browser_html.c svg_raster.c js_browser.c) \
  445. $(HOST_UHTTP_SRCS) user/lib/ngui/ngui.c \
  446. common/font_8x16.c \
  447. $(addprefix user/lib/ufont/,ufont.c ufont_ttf.c \
  448. ufont_draw.c ufont_file.c) \
  449. $(HOST_IMGLIB_SRCS) common/inflate.c $(HOST_TLS_SRCS) \
  450. user/apps/browser/js_mu.c user/lib/libc/malloc.c \
  451. $(HOST_QUERY_SRCS)
  452. HOST_CURL_APP_SRCS = user/apps/curl/ucmd_curl.c $(HOST_UHTTP_SRCS) \
  453. $(HOST_IMGLIB_SRCS) common/inflate.c $(HOST_TLS_SRCS) \
  454. user/lib/libc/malloc.c
  455. HOST_COMMON_SRCS = host/host.c host/syscall.c host/fs.c host/net.c \
  456. host/proc.c host/heap.c host/window.c \
  457. host/window_sdl3.c host/window_headless.c
  458. HOST_COMMON_OBJS = $(addprefix $(HOST_BUILD)/,$(HOST_COMMON_SRCS:.c=.o))
  459. HOST_BROWSER_APP_OBJS = $(addprefix $(HOST_BUILD)/,$(HOST_BROWSER_APP_SRCS:.c=.o))
  460. HOST_CURL_APP_OBJS = $(addprefix $(HOST_BUILD)/,$(HOST_CURL_APP_SRCS:.c=.o))
  461. HOST_BROWSER_OBJS = $(HOST_BUILD)/host/main.o $(HOST_COMMON_OBJS) \
  462. $(HOST_BROWSER_APP_OBJS) $(HOST_BUILD)/js_prelude.o
  463. HOST_CURL_OBJS = $(HOST_BUILD)/host/curl_main.o $(HOST_COMMON_OBJS) \
  464. $(HOST_CURL_APP_OBJS)
  465. $(HOST_BUILD)/%.o: %.c
  466. @mkdir -p $(dir $@)
  467. $(HOST_CC) $(HOST_APP_CFLAGS) $(HOST_EXTRA) $(DEPFLAGS) -c -o $@ $<
  468. # Host support files use glibc malloc directly, never the renamed arena.
  469. $(HOST_BUILD)/host/%.o: host/%.c
  470. @mkdir -p $(dir $@)
  471. $(HOST_CC) $(HOST_CFLAGS) $(DEPFLAGS) -c -o $@ $<
  472. $(HOST_BUILD)/js_prelude.o: user/apps/browser/js_prelude.S user/apps/browser/js_prelude.js
  473. @mkdir -p $(dir $@)
  474. $(HOST_CC) -m32 -Wa,-Iuser/apps/browser -c -o $@ $<
  475. $(HOST_BUILD)/user/apps/browser/browser.o: HOST_EXTRA = -D_start=browser_start
  476. $(HOST_BUILD)/user/apps/curl/ucmd_curl.o: HOST_EXTRA = -D_start=curl_start
  477. browser-host: host-curl $(HOST_BROWSER_OBJS)
  478. $(HOST_CC) $(HOST_LDFLAGS) -o $@ $(filter-out host-curl,$^) $(HOST_LDLIBS)
  479. host-curl: $(HOST_CURL_OBJS)
  480. $(HOST_CC) $(HOST_LDFLAGS) -o $@ $^ $(HOST_LDLIBS)
  481. # ---- Host tests (no kernel needed) -----------------------------------------
  482. UFONT_TEST_SRCS = $(addprefix user/lib/ufont/,ufont_test.c ufont.c ufont_ttf.c ufont_draw.c)
  483. ufont_test: $(UFONT_TEST_SRCS) user/lib/ufont/ufont.h user/lib/ufont/ufont_internal.h fonts/emoji.ttf
  484. gcc -O2 -Wall -Wextra -Iinclude -o $@ $(UFONT_TEST_SRCS)
  485. test-font: ufont_test
  486. ./ufont_test
  487. test-font-asan: $(UFONT_TEST_SRCS) user/lib/ufont/ufont.h user/lib/ufont/ufont_internal.h fonts/emoji.ttf
  488. gcc -O1 -g -fsanitize=address,undefined -Iinclude -o ufont_test_asan $(UFONT_TEST_SRCS)
  489. ./ufont_test_asan
  490. fonts:
  491. tools/subset_fonts.sh
  492. SVG_SRCS = user/apps/browser/svg_test.c user/apps/browser/svg_raster.c
  493. svg_test: $(SVG_SRCS) user/apps/browser/svg_raster.h
  494. gcc -O1 -g -Wall -Wextra -fsanitize=address,undefined -o $@ $(SVG_SRCS) -lm
  495. test-svg: svg_test
  496. ./svg_test
  497. touchpad_gesture_test: kernel/touchpad_gesture_test.c kernel/touchpad_gesture.c kernel/touchpad_gesture.h
  498. gcc -O2 -Wall -Wextra -o $@ kernel/touchpad_gesture_test.c kernel/touchpad_gesture.c
  499. test-touchpad: touchpad_gesture_test
  500. ./touchpad_gesture_test
  501. # Host tests for the chat client's pure modules: JSON, cookie jar and the
  502. # login page/reply/config parsers.
  503. CHAT_TEST_CFLAGS = -O1 -g -Wall -Wextra -fsanitize=address,undefined $(USER_INC)
  504. ujson_test: user/lib/ujson/ujson_test.c user/lib/ujson/ujson.c user/lib/ujson/ujson.h
  505. gcc $(CHAT_TEST_CFLAGS) -o $@ user/lib/ujson/ujson_test.c user/lib/ujson/ujson.c
  506. uhttp_cookie_test: user/lib/uhttp/uhttp_cookie_test.c user/lib/uhttp/uhttp_cookie.c user/lib/uhttp/uhttp_cookie.h
  507. gcc $(CHAT_TEST_CFLAGS) -o $@ user/lib/uhttp/uhttp_cookie_test.c user/lib/uhttp/uhttp_cookie.c
  508. chat_login_test: user/apps/chat/chat_login_test.c user/apps/chat/chat_login.c user/apps/chat/chat_login.h user/lib/ujson/ujson.c
  509. gcc $(CHAT_TEST_CFLAGS) -DCHAT_LOGIN_PURE -o $@ user/apps/chat/chat_login_test.c user/apps/chat/chat_login.c user/lib/ujson/ujson.c
  510. test-chat: ujson_test uhttp_cookie_test chat_login_test
  511. ./ujson_test
  512. ./uhttp_cookie_test
  513. ./chat_login_test
  514. # QEMU end-to-end chat test against tools/mock_chat.py (ports 18080/18081 on
  515. # the host, 10.0.2.2 in the guest). CHAT_E2E=--totp|--consent|--passkey|
  516. # --wrong selects a login variant; screenshots land in chat-test-out/.
  517. CHAT_E2E ?=
  518. test-chat-e2e: floppy.img root.img
  519. python3 tools/qmp_chat_test.py $(CHAT_E2E)
  520. TLS_TEST_SRCS = $(addprefix user/lib/tls/,tls_test.c tls_sha256.c tls_chacha20.c \
  521. tls_x25519.c tls_gcm.c tls_p256.c wpa_crypto.c)
  522. tls_test: $(TLS_TEST_SRCS) $(wildcard user/lib/tls/*.h)
  523. gcc -O2 -o $@ $(TLS_TEST_SRCS)
  524. test-crypto: tls_test
  525. ./tls_test
  526. wpa_test: user/lib/wifi/wpa_test.c user/lib/wifi/wpa.c user/lib/tls/wpa_crypto.c user/lib/wifi/wpa.h user/lib/tls/wpa_crypto.h
  527. gcc -O2 -Wall -Wextra -Iuser/lib/tls -o $@ user/lib/wifi/wpa_test.c user/lib/wifi/wpa.c user/lib/tls/wpa_crypto.c
  528. test-wpa: wpa_test
  529. ./wpa_test
  530. wifi_store_test: user/lib/wifi/wifi_store_test.c user/lib/wifi/wifi_store.c user/lib/wifi/wifi_store.h include/wifi_cfg.h include/syscall.h
  531. gcc -m32 -O2 -Wall -Wextra -Iinclude -Iuser -o $@ user/lib/wifi/wifi_store_test.c
  532. test-wifi-store: wifi_store_test
  533. ./wifi_store_test
  534. ccmp_test: kernel/ccmp_test.c kernel/ccmp.c kernel/ccmp.h
  535. gcc -O2 -Wall -Wextra -o $@ kernel/ccmp_test.c
  536. test-ccmp: ccmp_test
  537. ./ccmp_test
  538. # Host image-library tests. The corpus and expected hashes are committed;
  539. # tools/gen_img_tests.py regenerates them.
  540. IMGTEST_SRCS = $(addprefix user/lib/img/,img_test.c img.c img_mem.c img_blit.c \
  541. img_png.c img_bmp.c img_gif.c img_gif_anim.c img_jpeg.c img_tga.c \
  542. img_pnm.c img_ico.c img_pam.c) common/inflate.c
  543. IMGTEST_DEPS = $(wildcard user/lib/img/*.h) common/inflate.h testdata/images/expected.h
  544. IMGTEST_INC = -I. -Icommon -Iinclude -Iuser
  545. img_test: $(IMGTEST_SRCS) $(IMGTEST_DEPS)
  546. gcc -O2 -fwrapv -Wall -Wextra $(IMGTEST_INC) -o $@ $(IMGTEST_SRCS)
  547. test-images: img_test
  548. ./img_test
  549. test-images-asan: $(IMGTEST_SRCS) $(IMGTEST_DEPS)
  550. # -fwrapv: the integer IDCT deliberately relies on 32-bit wrap-around.
  551. gcc -O1 -g -fwrapv -fsanitize=address,undefined $(IMGTEST_INC) -o img_test_asan $(IMGTEST_SRCS)
  552. ./img_test_asan
  553. # Host tests for the ring-3 libc. The malloc/free names are renamed so the
  554. # host libc (printf, rand, write) keeps working normally.
  555. HOST_MALLOC_DEFS = -Dmalloc=libc_malloc -Dfree=libc_free \
  556. -Dcalloc=libc_calloc -Drealloc=libc_realloc \
  557. -Dheap_reset=libc_heap_reset
  558. LT = $(B)/host-test/libc
  559. LSRC = user/lib/libc
  560. $(LT)/malloc_host.o: $(LSRC)/malloc.c
  561. @mkdir -p $(@D)
  562. gcc -O2 -Wall -Wextra $(LIBC_INC) -fno-builtin $(HOST_MALLOC_DEFS) $(DEPFLAGS) -c -o $@ $<
  563. $(LT)/test_host_mem.o: $(LSRC)/test_host_mem.c
  564. @mkdir -p $(@D)
  565. gcc -O2 -Wall -Wextra $(DEPFLAGS) -c -o $@ $<
  566. malloc_test: $(LSRC)/test_malloc.c $(LT)/malloc_host.o $(LT)/test_host_mem.o
  567. gcc -O2 -Wall -Wextra -o $@ $^
  568. $(LT)/stdio_host.o: $(LSRC)/stdio.c
  569. @mkdir -p $(@D)
  570. gcc -O2 -Wall -Wextra $(LIBC_INC) -fno-builtin $(DEPFLAGS) -c -o $@ $<
  571. $(LT)/dtoa_host.o: $(LSRC)/dtoa.c
  572. @mkdir -p $(@D)
  573. gcc -O2 -Wall -Wextra $(LIBC_INC) -fno-builtin $(DEPFLAGS) -c -o $@ $<
  574. $(LT)/math_host.o: $(LSRC)/math.c
  575. @mkdir -p $(@D)
  576. gcc -O2 -Wall -Wextra $(LIBC_INC) -fno-builtin $(DEPFLAGS) -c -o $@ $<
  577. $(LT)/div64_host.o: $(LSRC)/div64.c
  578. @mkdir -p $(@D)
  579. gcc -O2 -Wall -Wextra $(DEPFLAGS) -c -o $@ $<
  580. format_test: $(LSRC)/test_format.c $(LT)/stdio_host.o $(LT)/dtoa_host.o
  581. gcc -O2 -Wall -Wextra -Wno-format-truncation $(LIBC_INC) -o $@ $^
  582. math_test: $(LSRC)/test_math.c $(LT)/math_host.o
  583. gcc -O2 -Wall -Wextra -o $@ $^ -lm
  584. div64_test: $(LSRC)/test_div64.c $(LT)/div64_host.o
  585. gcc -O2 -Wall -Wextra -o $@ $^
  586. setjmp_test: $(LSRC)/test_setjmp.c $(UL)/libc/setjmp.o
  587. gcc -m32 -O2 -Wall -Wextra $(LIBC_INC) -o $@ $^
  588. test-libc: malloc_test format_test math_test div64_test setjmp_test
  589. ./malloc_test
  590. ./format_test
  591. ./math_test
  592. ./div64_test
  593. ./setjmp_test
  594. QJS_HOST_SRCS = $(addprefix $(QJS_DIR)/,quickjs.c cutils.c dtoa.c libregexp.c libunicode.c)
  595. JS_TEST_SRCS = user/apps/browser/js_test.c user/apps/browser/js_mu.c
  596. js_test: $(JS_TEST_SRCS) user/apps/browser/js_mu.h $(QJS_HOST_SRCS) $(wildcard $(QJS_DIR)/*.h)
  597. gcc -O1 -g -w -fsanitize=address,undefined -fno-sanitize=shift -Iinclude -Iuser -I$(QJS_DIR) -D__nebos__ -DJS_MU_HOST \
  598. -DCONFIG_VERSION='"2026-06-04"' -o $@ $(JS_TEST_SRCS) $(QJS_HOST_SRCS) -lm
  599. test-js: js_test
  600. ./js_test
  601. # ---- Host tools ------------------------------------------------------------
  602. mkpack: tools/mkpack.c
  603. gcc -O2 -o $@ $<
  604. mkrootfs: tools/mkrootfs.c include/rootfs.h
  605. gcc -O2 -Iinclude -o $@ $<
  606. mkrtwtbl: tools/mkrtwtbl.c include/rtl8821a_tbl.h third_party/rtw88/rtw8821a_table.inc
  607. gcc -O2 -Wall -Wextra -I. -Iinclude -o $@ $<
  608. kexec_send: tools/kexec_send.c
  609. gcc -O2 -o $@ $<
  610. netkexec_send: tools/netkexec_send.c
  611. gcc -O2 -o $@ $<
  612. netmonitor: tools/netmonitor.c
  613. gcc -O2 -o $@ $<
  614. # ---- Command pack (the system rootfs) ---------------------------------------
  615. #
  616. # The ring-3 command ELFs plus hello and the browser/gallery apps, packed
  617. # into bin/<name>. See tools/mkpack.c, include/rootfs.h and kernel/ramfs.h.
  618. FONT_FILES = fonts/sans.ttf fonts/sans-b.ttf fonts/sans-i.ttf \
  619. fonts/sans-bi.ttf fonts/mono.ttf fonts/emoji.ttf
  620. HELLO_ELF = $(U)/apps/hello/hello.elf
  621. PACK_FILES = $(foreach a,$(UCMDS),bin/$(a)=$(call app,$(a)).elf) \
  622. bin/hello=$(HELLO_ELF) \
  623. bin/browser.app=browser.elf \
  624. bin/gallery.app=gallery.elf \
  625. $(foreach f,$(FONT_FILES),$(f)=$(f))
  626. PACK_DEPS = $(UCMD_ELFS) $(HELLO_ELF) browser.elf gallery.elf $(FONT_FILES) mkpack
  627. # `install self` reads the flat kernel from the full pack. The lite/floppy
  628. # pack deliberately omits it (no room on a 1.44 MB disk).
  629. PACK_INSTALL_FILES = install/kernel.bin=kernel.bin
  630. # WiFi firmware (kernel/iwl_trans.c): the Intel 7265D/3165 (Chromebook, MVM)
  631. # and the 6200/6300 (ThinkPad X201, DVM). Taken from the host's
  632. # linux-firmware (`.zst` or plain); WIFI_FW_7265D / WIFI_FW_6000 override the
  633. # search. A machine without one still builds: the pack then has no
  634. # firmware/ entry for that card and `wifi` reports it missing.
  635. fw_search = $(firstword $(wildcard \
  636. /usr/lib/firmware/intel/iwlwifi/$(1).zst /usr/lib/firmware/$(1).zst \
  637. /usr/lib/firmware/intel/iwlwifi/$(1) /usr/lib/firmware/$(1) \
  638. /lib/firmware/$(1)))
  639. WIFI_FW_7265D ?= $(call fw_search,iwlwifi-7265D-29.ucode)
  640. WIFI_FW_6000 ?= $(call fw_search,iwlwifi-6000-4.ucode)
  641. WIFI_FW_FILE =
  642. PACK_FW_FILES =
  643. # $(1) = file name in the pack, $(2) = host source.
  644. define wifi_fw_rule
  645. ifneq ($(2),)
  646. WIFI_FW_FILE += firmware/$(1)
  647. PACK_FW_FILES += firmware/$(1)=firmware/$(1)
  648. firmware/$(1): $(2)
  649. @mkdir -p firmware
  650. case "$$<" in *.zst) zstd -q -d -c "$$<" > $$@ ;; *) cp "$$<" $$@ ;; esac
  651. else
  652. $$(info note: $(1) not found; building the pack without it)
  653. endif
  654. endef
  655. $(eval $(call wifi_fw_rule,iwlwifi-7265D-29.ucode,$(WIFI_FW_7265D)))
  656. $(eval $(call wifi_fw_rule,iwlwifi-6000-4.ucode,$(WIFI_FW_6000)))
  657. # Realtek RTL8821AU USB sticks (kernel/rtl8821au.c): the rtw88 8051 firmware
  658. # from linux-firmware (WIFI_FW_8821A overrides the search) and the register
  659. # tables, generated from third_party/rtw88 by the host tool mkrtwtbl. Both
  660. # are only in the full pack, like the Intel firmware.
  661. WIFI_FW_8821A ?= $(firstword $(wildcard \
  662. /usr/lib/firmware/rtw88/rtw8821a_fw.bin.zst \
  663. /usr/lib/firmware/rtw88/rtw8821a_fw.bin \
  664. /lib/firmware/rtw88/rtw8821a_fw.bin))
  665. $(eval $(call wifi_fw_rule,rtw8821a_fw.bin,$(WIFI_FW_8821A)))
  666. WIFI_FW_FILE += firmware/rtl8821a.tbl
  667. PACK_FW_FILES += firmware/rtl8821a.tbl=firmware/rtl8821a.tbl
  668. firmware/rtl8821a.tbl: mkrtwtbl
  669. @mkdir -p firmware
  670. ./mkrtwtbl $@
  671. cmds.pack: $(PACK_DEPS) $(WIFI_FW_FILE) kernel.bin
  672. ./mkpack $@ $(PACK_FILES) $(PACK_INSTALL_FILES) $(PACK_FW_FILES)
  673. # The floppy images cannot hold the ~1 MB firmware: they get the same pack
  674. # without firmware/*.
  675. cmds-lite.pack: $(PACK_DEPS)
  676. ./mkpack $@ $(PACK_FILES)
  677. # The boot-time rootfs is gzip-compressed; the raw cmds.pack is still what
  678. # cmds-dev/net-cmds send for a runtime replacement. Prefer libdeflate's
  679. # level 12 when it is installed: it saves about 8 KB over gzip -9 on the
  680. # current pack. The high-memory rootfs loader supports up to 2 MB; the
  681. # floppy images use the firmware-less lite pack (rootfs.bin).
  682. CMDS_GZ = $(shell command -v libdeflate-gzip >/dev/null 2>&1 && \
  683. echo "libdeflate-gzip -12 -c" || echo "gzip -9 -n -c")
  684. CMDS_GZ_MAX = 2097152
  685. cmds_lite_gz.bin: cmds-lite.pack
  686. $(CMDS_GZ) $< > $@
  687. cmds_pack_gz.bin: cmds.pack
  688. $(CMDS_GZ) $< > $@
  689. @sz=$$(stat -c%s $@); \
  690. if [ $$sz -gt $(CMDS_GZ_MAX) ]; then \
  691. echo "error: cmds_pack_gz.bin is $$sz bytes; the legacy rootfs cap is $(CMDS_GZ_MAX)"; \
  692. rm -f $@; exit 1; \
  693. fi
  694. # Rootfs image: one NBROOT1 header sector + the gzip pack (rootfs.h).
  695. # rootfs.bin (the lite pack, no firmware) is appended to the floppy images;
  696. # cmds.img is the 8 MB image flashed into the USB rootfs partition.
  697. rootfs.bin: cmds_lite_gz.bin mkrootfs
  698. ./mkrootfs $@ cmds_lite_gz.bin
  699. # Full NBROOT1 image (header + gzip pack, no partition padding) for the
  700. # network install path. `install self` uses the retained boot image instead.
  701. rootfs-full.bin: cmds_pack_gz.bin mkrootfs
  702. ./mkrootfs $@ cmds_pack_gz.bin
  703. rootfs: cmds.img
  704. cmds.img: cmds_pack_gz.bin mkrootfs
  705. ./mkrootfs $@ cmds_pack_gz.bin $$(( $(ROOTFS_SECTORS) * 512 ))
  706. # Diagnostic: no WM, boot console stays visible. Rebuild normally with
  707. # `make -B ...` afterwards (the objects carry -DNOWM).
  708. nowm:
  709. $(MAKE) NOWM=1 -B kernel.elf kernel.bin floppy.img usb.img usb-efi.img final.bin
  710. @echo "nowm: WM disabled; flash usb.img or usb-efi.img."
  711. root.img: browser.elf gallery.elf testdata/browser/demo.html testdata/browser/js.html testdata/browser/jsext.js testdata/images/rgb.bmp
  712. dd if=/dev/zero of=$@ bs=512 count=2880 2>/dev/null
  713. mkfs.fat -F 12 -n "ROOTDISK" $@
  714. echo "Hello from the second floppy!" | mcopy -i $@ - ::HELLO.TXT
  715. echo "This is a test file on drive 1." | mcopy -i $@ - ::TEST.TXT
  716. mcopy -i $@ browser.elf ::BROWSER
  717. mcopy -i $@ gallery.elf ::GALLERY
  718. mcopy -i $@ testdata/browser/demo.html ::DEMO.HTM
  719. mcopy -i $@ testdata/browser/js.html ::JS.HTM
  720. mcopy -i $@ testdata/browser/jsext.js ::JSEXT.JS
  721. mcopy -i $@ testdata/images/rgb.bmp ::PIC.BMP
  722. OVMF ?= $(firstword $(wildcard /usr/share/ovmf/x64/OVMF.4m.fd /usr/share/OVMF/OVMF.4m.fd))
  723. # Guest RAM for the QEMU targets. The kernel ceiling is 512 MB (phys.h);
  724. # override with `make run QEMU_MEM=1G` for larger guests.
  725. QEMU_MEM ?= 512M
  726. # root.img is deliberately not attached: a running QEMU may hold its write
  727. # lock, and the UEFI boot test does not need a second filesystem.
  728. run-uefi: usb-efi.img
  729. @test -n "$(OVMF)" || { echo "OVMF not found; set OVMF=/path/to/OVMF.4m.fd" >&2; exit 1; }
  730. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -smp 4 -bios $(OVMF) -snapshot \
  731. -drive file=usb-efi.img,format=raw,if=ide \
  732. -device pci-ohci -device usb-mouse \
  733. -device ne2k_pci,netdev=n0 -netdev user,id=n0 \
  734. -serial file:/tmp/opencode/nebos-uefi-serial.log
  735. test-uefi: usb-efi.img
  736. @test -n "$(OVMF)" || { echo "OVMF not found; set OVMF=/path/to/OVMF.4m.fd" >&2; exit 1; }
  737. @rm -f /tmp/opencode/nebos-uefi-serial.log
  738. timeout 40 qemu-system-x86_64 -M pc -m $(QEMU_MEM) -smp 4 -bios $(OVMF) -snapshot \
  739. -drive file=usb-efi.img,format=raw,if=ide \
  740. -device pci-ohci -device usb-mouse \
  741. -device ne2k_pci,netdev=n0 -netdev user,id=n0 \
  742. -display none -serial file:/tmp/opencode/nebos-uefi-serial.log \
  743. -no-reboot >/dev/null 2>&1 || true
  744. @grep -q "booted" /tmp/opencode/nebos-uefi-serial.log && \
  745. echo "UEFI boot: OK (/tmp/opencode/nebos-uefi-serial.log)" || \
  746. { echo "UEFI boot: FAILED"; tail -c 4000 /tmp/opencode/nebos-uefi-serial.log; exit 1; }
  747. run: image.bin root.img
  748. $(MAKE) run-floppy
  749. # Four logical CPUs (the Atom 330 topology). UP is still the default so a
  750. # machine without ACPI/MADT boots exactly as before.
  751. run-smp: floppy.img root.img
  752. qemu-system-i386 -M pc -m $(QEMU_MEM) -smp 4 -device pci-ohci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  753. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -smp 4 -device pci-ohci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  754. floppy: floppy.img
  755. usb: usb.img
  756. # Write the dual-boot USB image (legacy BIOS + UEFI) to a stick; prompts
  757. # before destroying anything.
  758. # make flash USB=/dev/sdX FORCE=1 skips the removable-device check.
  759. # make flash FLASH_IMG=usb.img legacy-only image
  760. # The UEFI half needs the mingw toolchain (EFI_CC); the legacy half does not.
  761. FLASH_IMG ?= usb-efi.img
  762. flash: $(FLASH_IMG)
  763. @tools/flash.sh "$(USB)" "$(FORCE)" "$(FLASH_IMG)"
  764. run-floppy: floppy.img root.img
  765. qemu-system-i386 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  766. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  767. run-usb: usb.img root.img
  768. qemu-system-i386 -M pc -m $(QEMU_MEM) -boot c -device pci-ohci -device usb-mouse -drive file=usb.img,format=raw,if=ide -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  769. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -boot c -device pci-ohci -device usb-mouse -drive file=usb.img,format=raw,if=ide -drive file=root.img,format=raw,if=floppy
  770. # UHCI variant (machines with an Intel/VIA-style controller, and the
  771. # regression test for the UHCI backend of the USB core).
  772. run-uhci: floppy.img root.img
  773. qemu-system-i386 -M pc -m $(QEMU_MEM) -device piix3-usb-uhci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  774. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device piix3-usb-uhci -device usb-mouse -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  775. # xHCI variant (Braswell/Intel PCH and other USB 3.0-only machines).
  776. run-xhci: floppy.img root.img
  777. qemu-system-i386 -M pc -m $(QEMU_MEM) -device qemu-xhci -device usb-mouse -device usb-kbd -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  778. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device qemu-xhci -device usb-mouse -device usb-kbd -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  779. # RNDIS variant: QEMU's usb-net is a full-speed RNDIS function. It sits on
  780. # xHCI (QEMU's USB2 root ports), and `-nic none` keeps the PCI e1000 out of
  781. # the way so the phone/tethering link is the active NIC.
  782. run-rndis: floppy.img root.img
  783. qemu-system-i386 -M pc -m $(QEMU_MEM) -nic none -device qemu-xhci -device usb-mouse -device usb-kbd -device usb-net,netdev=n1 -netdev user,id=n1 -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  784. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -nic none -device qemu-xhci -device usb-mouse -device usb-kbd -device usb-net,netdev=n1 -netdev user,id=n1 -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  785. # EHCI variant (USB 2.0 high-speed root ports). usb-storage is high-speed
  786. # and lands on EHCI; the mouse/keyboard are full-speed and use the UHCI
  787. # companion, exercising the multi-controller USB core.
  788. run-ehci: floppy.img root.img
  789. qemu-system-i386 -M pc -m $(QEMU_MEM) -boot a -device usb-ehci,id=ehci0 -device piix3-usb-uhci,id=uhci0 \
  790. -device usb-storage,bus=ehci0.0,drive=usbstick \
  791. -drive if=none,id=usbstick,file=root.img,format=raw \
  792. -device usb-mouse,bus=uhci0.0 -device usb-kbd,bus=uhci0.0 \
  793. -drive file=floppy.img,format=raw,if=floppy 2>/dev/null || \
  794. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -boot a -device usb-ehci,id=ehci0 -device piix3-usb-uhci,id=uhci0 \
  795. -device usb-storage,bus=ehci0.0,drive=usbstick \
  796. -drive if=none,id=usbstick,file=root.img,format=raw \
  797. -device usb-mouse,bus=uhci0.0 -device usb-kbd,bus=uhci0.0 \
  798. -drive file=floppy.img,format=raw,if=floppy
  799. # Passthrough of the real ASIX AX88772 dongle (requires the host's asix
  800. # driver to be unbound and permission on /dev/bus/usb/...; typically run with
  801. # sudo). `-nic none` keeps the QEMU e1000 out of the way so the USB NIC is
  802. # the only netdev.
  803. ASIX_HOST ?= vendorid=0x0b95,productid=0x7720
  804. run-ehci-asix: floppy.img root.img
  805. qemu-system-i386 -M pc -m $(QEMU_MEM) -nic none -device usb-ehci -device usb-host,$(ASIX_HOST) -serial file:/tmp/opencode/serial-asix.log -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  806. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -nic none -device usb-ehci -device usb-host,$(ASIX_HOST) -serial file:/tmp/opencode/serial-asix.log -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  807. run-xhci-asix: floppy.img root.img
  808. qemu-system-i386 -M pc -m $(QEMU_MEM) -nic none -device qemu-xhci -device usb-host,$(ASIX_HOST) -serial file:/tmp/opencode/serial-asix.log -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  809. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -nic none -device qemu-xhci -device usb-host,$(ASIX_HOST) -serial file:/tmp/opencode/serial-asix.log -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  810. # Network variant: a PCI NE2000 (RTL8029, the driver's QEMU match) on QEMU's
  811. # user-mode network (slirp). DHCP/DNS come from slirp, the host is 10.0.2.2
  812. # (e.g. `python3 -m http.server` + `curl http://10.0.2.2:8000/` in a window).
  813. run-net: floppy.img root.img
  814. qemu-system-i386 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device ne2k_pci,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  815. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device ne2k_pci,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 -drive file=floppy.img,format=raw,if=floppy -drive file=root.img,format=raw,if=floppy
  816. # Intel e1000 variant: QEMU's 82540EM exercises the e1000e driver's MAC/DMA
  817. # path. (The X201's 82577LM uses the same registers; only its PCH PHY is
  818. # different.) usb-kbd is there for headless QMP `send-key` typing.
  819. run-e1000: floppy.img root.img
  820. qemu-system-i386 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device usb-kbd \
  821. -device e1000,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 \
  822. -drive file=floppy.img,format=raw,if=floppy \
  823. -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  824. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device usb-kbd \
  825. -device e1000,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 \
  826. -drive file=floppy.img,format=raw,if=floppy \
  827. -drive file=root.img,format=raw,if=floppy
  828. # SATA/AHCI variant: an ICH9 AHCI controller with a test disk on port 0.
  829. # The disk image lives outside the repo and is created on first use; boot
  830. # stays on the floppy (order=a), the SATA disk shows up as sata0.
  831. SATA_IMG ?= /tmp/opencode/nebos-sata.img
  832. run-ahci: floppy.img root.img
  833. @test -f $(SATA_IMG) || truncate -s 512M $(SATA_IMG)
  834. qemu-system-i386 -M pc -m $(QEMU_MEM) -boot order=a -device pci-ohci -device usb-mouse \
  835. -drive file=floppy.img,format=raw,if=floppy \
  836. -drive file=root.img,format=raw,if=floppy \
  837. -device ich9-ahci,id=sata \
  838. -drive file=$(SATA_IMG),format=raw,if=none,id=satadisk \
  839. -device ide-hd,drive=satadisk,bus=sata.0 2>/dev/null || \
  840. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -boot order=a -device pci-ohci -device usb-mouse \
  841. -drive file=floppy.img,format=raw,if=floppy \
  842. -drive file=root.img,format=raw,if=floppy \
  843. -device ich9-ahci,id=sata \
  844. -drive file=$(SATA_IMG),format=raw,if=none,id=satadisk \
  845. -device ide-hd,drive=satadisk,bus=sata.0
  846. # AMD Piledriver regression: QEMU's Opteron_G5 is the FX-6350's family 15h
  847. # model 2 CPU. Exercises the AMD CPUID/MTRR/xAPIC paths, the AMD thermal
  848. # probe, the IOAPIC mask and six-core ACPI SMP. QEMU has no SB950 or
  849. # RTL8111E, so the e1000/OHCI devices cover the rest of the boot path.
  850. run-amd: floppy.img root.img
  851. qemu-system-x86_64 -M pc -cpu Opteron_G5 -smp 6 -m $(QEMU_MEM) \
  852. -device pci-ohci -device usb-mouse -device usb-kbd \
  853. -device e1000,netdev=n0 -netdev user,id=n0 \
  854. -drive file=floppy.img,format=raw,if=floppy \
  855. -drive file=root.img,format=raw,if=floppy
  856. test-amd: floppy.img root.img
  857. @rm -f /tmp/opencode/nebos-amd-serial.log
  858. timeout 40 qemu-system-x86_64 -M pc -cpu Opteron_G5 -smp 6 -m $(QEMU_MEM) \
  859. -device pci-ohci -device usb-mouse -device usb-kbd \
  860. -device e1000,netdev=n0 -netdev user,id=n0 \
  861. -drive file=floppy.img,format=raw,if=floppy \
  862. -drive file=root.img,format=raw,if=floppy \
  863. -display none -serial file:/tmp/opencode/nebos-amd-serial.log \
  864. -no-reboot >/dev/null 2>&1 || true
  865. @grep -q "booted" /tmp/opencode/nebos-amd-serial.log && \
  866. grep -q "smp cpus: 6" /tmp/opencode/nebos-amd-serial.log && \
  867. grep -q "ioapic: masked" /tmp/opencode/nebos-amd-serial.log && \
  868. grep -q "thermal: AMD family 15h" /tmp/opencode/nebos-amd-serial.log && \
  869. ! grep -q "PIT NOT TICKING" /tmp/opencode/nebos-amd-serial.log && \
  870. echo "AMD boot: OK (/tmp/opencode/nebos-amd-serial.log)" || \
  871. { echo "AMD boot: FAILED"; tail -c 4000 /tmp/opencode/nebos-amd-serial.log; exit 1; }
  872. # Headless USB HID regression tests (QEMU + python3): cursor movement via
  873. # injected USB mouse reports and keyboard input via injected key events,
  874. # including hotplug. See tools/*.py.
  875. test-usb: floppy.img root.img
  876. python3 tools/qmp_cursor_test.py
  877. python3 tools/qmp_cursor_test.py --uhci
  878. python3 tools/qmp_cursor_test.py --uhci72
  879. python3 tools/qmp_cursor_test.py --hotplug
  880. python3 tools/qmp_cursor_test.py --xhci
  881. python3 tools/qmp_cursor_test.py --ehci
  882. python3 tools/qmp_keyboard_test.py
  883. python3 tools/qmp_keyboard_test.py --hotplug
  884. python3 tools/qmp_keyboard_test.py --xhci
  885. python3 tools/qmp_keyboard_test.py --ehci
  886. # End-to-end installer test: boot the dual-boot USB image as an IDE disk,
  887. # attach the same image as a USB mass-storage source, type `install ide1`
  888. # on the terminal and verify + boot the cloned target.
  889. test-install: usb-efi.img
  890. python3 tools/qmp_install_test.py
  891. scp-final: final.bin
  892. scp final.bin root@192.168.0.136:
  893. ssh root@192.168.0.136 dd if=final.bin of=/dev/fd0 bs=512
  894. scp-root: root.img
  895. scp root.img root@192.168.0.136:
  896. ssh root@192.168.0.136 dd if=root.img of=/dev/fd0 bs=512
  897. SERIAL_DEV ?= /dev/ttyUSB0
  898. SERIAL_BAUD ?= 115200
  899. run-serial:
  900. @echo "Starting serial monitor on $(SERIAL_DEV) at $(SERIAL_BAUD) baud..."
  901. @echo "Type 'serial test' in the nebos terminal."
  902. @echo "Press Ctrl-A Ctrl-X to exit picocom."
  903. picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
  904. monitor:
  905. @echo "Watching $(SERIAL_DEV) @ $(SERIAL_BAUD) baud (Ctrl-A Ctrl-X to exit)."
  906. @echo "Each 'make dev' reload prints: NebOS v<version> booted"
  907. picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
  908. dev: kernel.bin cmds_pack_gz.bin kexec_send
  909. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  910. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  911. echo "Sending kernel.bin + cmds_pack_gz.bin (entry 0x$$entry) via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."; \
  912. ./kexec_send $(SERIAL_DEV) $(SERIAL_BAUD) $$entry kernel.bin cmds_pack_gz.bin
  913. # Kernel-only fast path: the board keeps its running rootfs.
  914. kernel-dev: kernel.bin kexec_send
  915. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  916. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  917. echo "Sending kernel.bin only (entry 0x$$entry) via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."; \
  918. ./kexec_send $(SERIAL_DEV) $(SERIAL_BAUD) $$entry kernel.bin
  919. # Push just the command pack (cmds.pack) to a running board: no kernel
  920. # reload, the /ramfs contents are replaced in place. The board must be idle
  921. # at a prompt (the WM loop auto-detects the transfer).
  922. cmds-dev: cmds.pack kexec_send
  923. @echo "Sending cmds.pack via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."
  924. ./kexec_send --payload $(SERIAL_DEV) $(SERIAL_BAUD) cmds.pack
  925. net-cmds: cmds.pack netkexec_send
  926. @echo "Sending cmds.pack to $(BOARD_IP):$(NETKEXEC_PORT)..."
  927. ./netkexec_send --payload $(BOARD_IP) $(NETKEXEC_PORT) cmds.pack
  928. # Development override: upload the real browser to the board's writable
  929. # /share; the bin/browser launcher prefers it over the pack copy. The board
  930. # must be running `websrv`; stop it before browsing HTTP, since the WebDAV
  931. # server owns the NIC.
  932. browser-dev: browser.elf
  933. @echo "Uploading browser.elf to http://$(BOARD_IP):8080/share/BROWSER..."
  934. curl -f -T browser.elf http://$(BOARD_IP):8080/share/BROWSER
  935. # gallery follows the same development-override model.
  936. gallery-dev: gallery.elf
  937. @echo "Uploading gallery.elf to http://$(BOARD_IP):8080/share/GALLERY..."
  938. curl -f -T gallery.elf http://$(BOARD_IP):8080/share/GALLERY
  939. # Browser compatibility ladder: serve testdata/browser/compat so the board
  940. # or a QEMU guest can open http://<host>:$(COMPAT_PORT)/.
  941. COMPAT_PORT ?= 8000
  942. compat-serve:
  943. @echo "Serving the browser compatibility ladder on port $(COMPAT_PORT)"
  944. python3 -m http.server -d testdata/browser/compat $(COMPAT_PORT)
  945. # Show the board's netlog stream (kernel debug + terminal text) like `make
  946. # monitor` does over serial.
  947. netmon: netmonitor
  948. @echo "Listening for netlog on UDP $(NETLOG_PORT) (Ctrl-C to exit)."
  949. ./netmonitor $(NETLOG_PORT)
  950. # Push a fresh kernel over Ethernet (the board auto-detects it from its idle
  951. # loop; no serial and no USB stick involved).
  952. BOARD_IP ?= 192.168.178.240
  953. NETLOG_PORT ?= 19290
  954. NETKEXEC_PORT ?= 19288
  955. net-dev: kernel.bin cmds_pack_gz.bin netkexec_send
  956. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  957. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  958. echo "Sending kernel.bin + cmds_pack_gz.bin (entry 0x$$entry) to $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  959. ./netkexec_send $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin cmds_pack_gz.bin
  960. # Kernel-only fast path: the board keeps its running rootfs.
  961. kernel-net-dev: kernel.bin netkexec_send
  962. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  963. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  964. echo "Sending kernel.bin only (entry 0x$$entry) to $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  965. ./netkexec_send $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin
  966. # Persistent update: write P1/P2 on the target disk (P4/data is untouched),
  967. # then jump into the new kernel. TARGET=auto picks the only non-USB NebOS
  968. # disk; use NETINSTALL_TARGET=mmc0/sata0/... to override.
  969. NETINSTALL_TARGET ?= auto
  970. net-install: kernel.bin rootfs-full.bin netkexec_send
  971. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  972. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  973. echo "Persisting kernel.bin + rootfs-full.bin to $(NETINSTALL_TARGET) on $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  974. ./netkexec_send --install $(NETINSTALL_TARGET) $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin rootfs-full.bin
  975. clean:
  976. rm -rf $(B) host/build
  977. rm -f kernel.elf kernel.bin boot.bin mbr.bin boot.bin.tmp image.bin \
  978. floppy.img usb.img usb-efi.img esp.img final.bin root.img \
  979. BOOTX64.EFI browser.elf gallery.elf *.boot.tmp \
  980. cmds.pack cmds-lite.pack cmds_pack_gz.bin cmds_lite_gz.bin \
  981. rootfs.bin rootfs-full.bin cmds.img \
  982. firmware/*.ucode firmware/*.tbl firmware/*.bin \
  983. mkpack mkrootfs mkrtwtbl kexec_send netkexec_send netmonitor \
  984. browser-host host-curl \
  985. ufont_test ufont_test_asan svg_test touchpad_gesture_test \
  986. ujson_test uhttp_cookie_test chat_login_test tls_test wpa_test \
  987. wifi_store_test ccmp_test img_test img_test_asan malloc_test \
  988. format_test math_test div64_test setjmp_test js_test
  989. # Compiler-generated header dependencies.
  990. -include $(shell find $(B) host/build -name '*.d' 2>/dev/null)