Makefile 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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 test-cursors 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 cursor 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 disks
  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. # Storage manager: devices, partitions, mount policies, format/install.
  379. $(call app,disks).elf: $(call app,disks).o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  380. $(ULINK)
  381. # chat: native Cloudron Chat client (ngui + uhttp/TLS + cookie jar + JSON +
  382. # the native OIDC login driver).
  383. CHAT_LOGIN = $(U)/apps/chat/chat_login.o
  384. $(CHAT_LOGIN): OPT = -Os
  385. $(CHAT_LOGIN): XFLAGS = $(SECTION_CFLAGS)
  386. $(call app,chat).o: OPT = -Os
  387. $(call app,chat).o: XFLAGS = $(SECTION_CFLAGS) $(LIBC_INC)
  388. $(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)
  389. $(ULINK)
  390. # gallery: a live showcase of every ngui widget and primitive. The real ELF
  391. # ships in the rootfs pack as bin/gallery.app; ucmd_gallery.c (in UCMDS) is
  392. # the tiny PATH launcher (which also accepts /share/GALLERY).
  393. gallery.elf: $(U)/apps/gallery/gallery.o $(NGUI_APP) $(UCMD_LD) $(LIBC_A)
  394. $(ULINK)
  395. # browser: the real app ships as bin/browser.app in the full pack (and
  396. # BROWSER on root.img, which floppy boots use)
  397. # because it links ngui, the image library, TLS, uhttp and QuickJS;
  398. # ucmd_browser.c is the tiny PATH launcher. Compiled with function sections
  399. # and linked with --gc-sections: unreachable image, TLS and UI paths are
  400. # dropped.
  401. BR = $(U)/apps/browser
  402. BROWSER_OBJS = $(BR)/browser.o $(BR)/browser_html.o $(BR)/svg_raster.o \
  403. $(BR)/js_browser.o $(BR)/js_mu.o
  404. $(BROWSER_OBJS): OPT = -Os
  405. $(BROWSER_OBJS): XFLAGS = $(SECTION_CFLAGS) $(LIBC_INC)
  406. $(BR)/browser_html.o: XFLAGS = $(SECTION_CFLAGS)
  407. $(BR)/js_mu.o: XFLAGS = $(SECTION_CFLAGS) -Wno-unused-parameter $(LIBC_INC) -I$(QJS_DIR)
  408. 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)
  409. $(ULINK)
  410. # hello: the first ring-3 test program (its own linker script).
  411. $(U)/apps/hello/hello.elf: $(U)/apps/hello/hello.o user/apps/hello/hello.ld
  412. $(LD) -T user/apps/hello/hello.ld -nostdlib -m elf_i386 -o $@ $<
  413. $(OBJCOPY) --strip-all $@ $@
  414. # ---- Linux host browser harness (browser-host / host-curl) -------------------
  415. #
  416. # The browser talks to the same small SYS_* ABI as on NebOS; host/syscall.c
  417. # implements it with Linux files, BSD sockets, fork/exec and an SDL3 window.
  418. # The target images and browser.elf are not involved. Build 32-bit so the
  419. # pointer-through-int syscall ABI and the ring-3 allocator behave like the
  420. # board. SDL3 is only a development dependency for the window backend.
  421. HOST_CC ?= gcc
  422. HOST_BUILD = host/build
  423. HOST_CFLAGS = -m32 -O1 -g -Wall -Wextra -Wno-unused-parameter \
  424. -Wno-sign-compare -Wno-unused-function -Wno-format-truncation \
  425. -fno-strict-aliasing -fno-omit-frame-pointer $(USER_INC) \
  426. -Ihost/include -Ithird_party/quickjs -I/usr/include/SDL3 \
  427. -DUCMD_HOST -DJS_MU_HOST -D__nebos__ -D_GNU_SOURCE \
  428. -DCONFIG_VERSION='"2026-06-04"'
  429. # The ring-3 allocator is reused on the host: rename its entry points so
  430. # glibc and SDL keep their own malloc. libc/malloc.c and every app object
  431. # must use the same set.
  432. HOST_APP_MALLOC_DEFS = -Dmalloc=libc_malloc -Dfree=libc_free \
  433. -Dcalloc=libc_calloc -Drealloc=libc_realloc \
  434. -Dmalloc_usable_size=libc_malloc_usable_size \
  435. -Dheap_reset=libc_heap_reset
  436. HOST_APP_CFLAGS = $(HOST_CFLAGS) $(HOST_APP_MALLOC_DEFS)
  437. HOST_LDFLAGS = -m32 -no-pie -L/usr/lib32
  438. HOST_LDLIBS = -lSDL3 -lm -lpthread -ldl
  439. HOST_IMGLIB_SRCS = $(addprefix user/lib/img/,img.c img_mem.c img_blit.c \
  440. img_png.c img_bmp.c img_gif.c img_jpeg.c img_tga.c img_pnm.c \
  441. img_ico.c img_pam.c img_gif_anim.c img_file.c)
  442. HOST_TLS_SRCS = $(addprefix user/lib/tls/,tls_sha256.c tls_chacha20.c \
  443. tls_x25519.c tls_gcm.c tls_p256.c wpa_crypto.c tls_rng.c tls.c)
  444. HOST_QUERY_SRCS = $(addprefix $(QJS_DIR)/,quickjs.c cutils.c dtoa.c \
  445. libregexp.c libunicode.c)
  446. HOST_UHTTP_SRCS = user/lib/uhttp/uhttp.c user/lib/uhttp/uhttp_cookie.c
  447. HOST_BROWSER_APP_SRCS = $(addprefix user/apps/browser/,browser.c \
  448. browser_html.c svg_raster.c js_browser.c) \
  449. $(HOST_UHTTP_SRCS) user/lib/ngui/ngui.c \
  450. common/font_8x16.c \
  451. $(addprefix user/lib/ufont/,ufont.c ufont_ttf.c \
  452. ufont_draw.c ufont_file.c) \
  453. $(HOST_IMGLIB_SRCS) common/inflate.c $(HOST_TLS_SRCS) \
  454. user/apps/browser/js_mu.c user/lib/libc/malloc.c \
  455. $(HOST_QUERY_SRCS)
  456. HOST_CURL_APP_SRCS = user/apps/curl/ucmd_curl.c $(HOST_UHTTP_SRCS) \
  457. $(HOST_IMGLIB_SRCS) common/inflate.c $(HOST_TLS_SRCS) \
  458. user/lib/libc/malloc.c
  459. HOST_COMMON_SRCS = host/host.c host/syscall.c host/fs.c host/net.c \
  460. host/proc.c host/heap.c host/window.c \
  461. host/window_sdl3.c host/window_headless.c
  462. HOST_COMMON_OBJS = $(addprefix $(HOST_BUILD)/,$(HOST_COMMON_SRCS:.c=.o))
  463. HOST_BROWSER_APP_OBJS = $(addprefix $(HOST_BUILD)/,$(HOST_BROWSER_APP_SRCS:.c=.o))
  464. HOST_CURL_APP_OBJS = $(addprefix $(HOST_BUILD)/,$(HOST_CURL_APP_SRCS:.c=.o))
  465. HOST_BROWSER_OBJS = $(HOST_BUILD)/host/main.o $(HOST_COMMON_OBJS) \
  466. $(HOST_BROWSER_APP_OBJS) $(HOST_BUILD)/js_prelude.o
  467. HOST_CURL_OBJS = $(HOST_BUILD)/host/curl_main.o $(HOST_COMMON_OBJS) \
  468. $(HOST_CURL_APP_OBJS)
  469. $(HOST_BUILD)/%.o: %.c
  470. @mkdir -p $(dir $@)
  471. $(HOST_CC) $(HOST_APP_CFLAGS) $(HOST_EXTRA) $(DEPFLAGS) -c -o $@ $<
  472. # Host support files use glibc malloc directly, never the renamed arena.
  473. $(HOST_BUILD)/host/%.o: host/%.c
  474. @mkdir -p $(dir $@)
  475. $(HOST_CC) $(HOST_CFLAGS) $(DEPFLAGS) -c -o $@ $<
  476. $(HOST_BUILD)/js_prelude.o: user/apps/browser/js_prelude.S user/apps/browser/js_prelude.js
  477. @mkdir -p $(dir $@)
  478. $(HOST_CC) -m32 -Wa,-Iuser/apps/browser -c -o $@ $<
  479. $(HOST_BUILD)/user/apps/browser/browser.o: HOST_EXTRA = -D_start=browser_start
  480. $(HOST_BUILD)/user/apps/curl/ucmd_curl.o: HOST_EXTRA = -D_start=curl_start
  481. browser-host: host-curl $(HOST_BROWSER_OBJS) | icons/adwaita16.icn
  482. $(HOST_CC) $(HOST_LDFLAGS) -o $@ $(filter-out host-curl,$^) $(HOST_LDLIBS)
  483. host-curl: $(HOST_CURL_OBJS)
  484. $(HOST_CC) $(HOST_LDFLAGS) -o $@ $^ $(HOST_LDLIBS)
  485. # ---- Host tests (no kernel needed) -----------------------------------------
  486. UFONT_TEST_SRCS = $(addprefix user/lib/ufont/,ufont_test.c ufont.c ufont_ttf.c ufont_draw.c)
  487. ufont_test: $(UFONT_TEST_SRCS) user/lib/ufont/ufont.h user/lib/ufont/ufont_internal.h fonts/emoji.ttf
  488. gcc -O2 -Wall -Wextra -Iinclude -o $@ $(UFONT_TEST_SRCS)
  489. test-font: ufont_test
  490. ./ufont_test
  491. test-font-asan: $(UFONT_TEST_SRCS) user/lib/ufont/ufont.h user/lib/ufont/ufont_internal.h fonts/emoji.ttf
  492. gcc -O1 -g -fsanitize=address,undefined -Iinclude -o ufont_test_asan $(UFONT_TEST_SRCS)
  493. ./ufont_test_asan
  494. fonts:
  495. tools/subset_fonts.sh
  496. SVG_SRCS = user/apps/browser/svg_test.c user/apps/browser/svg_raster.c
  497. svg_test: $(SVG_SRCS) user/apps/browser/svg_raster.h
  498. gcc -O1 -g -Wall -Wextra -fsanitize=address,undefined -o $@ $(SVG_SRCS) -lm
  499. test-svg: svg_test
  500. ./svg_test
  501. touchpad_gesture_test: kernel/touchpad_gesture_test.c kernel/touchpad_gesture.c kernel/touchpad_gesture.h
  502. gcc -O2 -Wall -Wextra -o $@ kernel/touchpad_gesture_test.c kernel/touchpad_gesture.c
  503. test-touchpad: touchpad_gesture_test
  504. ./touchpad_gesture_test
  505. # Host tests for the chat client's pure modules: JSON, cookie jar and the
  506. # login page/reply/config parsers.
  507. CHAT_TEST_CFLAGS = -O1 -g -Wall -Wextra -fsanitize=address,undefined $(USER_INC)
  508. ujson_test: user/lib/ujson/ujson_test.c user/lib/ujson/ujson.c user/lib/ujson/ujson.h
  509. gcc $(CHAT_TEST_CFLAGS) -o $@ user/lib/ujson/ujson_test.c user/lib/ujson/ujson.c
  510. uhttp_cookie_test: user/lib/uhttp/uhttp_cookie_test.c user/lib/uhttp/uhttp_cookie.c user/lib/uhttp/uhttp_cookie.h
  511. gcc $(CHAT_TEST_CFLAGS) -o $@ user/lib/uhttp/uhttp_cookie_test.c user/lib/uhttp/uhttp_cookie.c
  512. 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
  513. 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
  514. test-chat: ujson_test uhttp_cookie_test chat_login_test
  515. ./ujson_test
  516. ./uhttp_cookie_test
  517. ./chat_login_test
  518. # QEMU end-to-end chat test against tools/mock_chat.py (ports 18080/18081 on
  519. # the host, 10.0.2.2 in the guest). CHAT_E2E=--totp|--consent|--passkey|
  520. # --wrong selects a login variant; screenshots land in chat-test-out/.
  521. CHAT_E2E ?=
  522. test-chat-e2e: floppy.img root.img
  523. python3 tools/qmp_chat_test.py $(CHAT_E2E)
  524. TLS_TEST_SRCS = $(addprefix user/lib/tls/,tls_test.c tls_sha256.c tls_chacha20.c \
  525. tls_x25519.c tls_gcm.c tls_p256.c wpa_crypto.c)
  526. tls_test: $(TLS_TEST_SRCS) $(wildcard user/lib/tls/*.h)
  527. gcc -O2 -o $@ $(TLS_TEST_SRCS)
  528. test-crypto: tls_test
  529. ./tls_test
  530. 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
  531. 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
  532. test-wpa: wpa_test
  533. ./wpa_test
  534. 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
  535. gcc -m32 -O2 -Wall -Wextra -Iinclude -Iuser -o $@ user/lib/wifi/wifi_store_test.c
  536. test-wifi-store: wifi_store_test
  537. ./wifi_store_test
  538. ccmp_test: kernel/ccmp_test.c kernel/ccmp.c kernel/ccmp.h
  539. gcc -O2 -Wall -Wextra -o $@ kernel/ccmp_test.c
  540. test-ccmp: ccmp_test
  541. ./ccmp_test
  542. # Host image-library tests. The corpus and expected hashes are committed;
  543. # tools/gen_img_tests.py regenerates them.
  544. IMGTEST_SRCS = $(addprefix user/lib/img/,img_test.c img.c img_mem.c img_blit.c \
  545. img_png.c img_bmp.c img_gif.c img_gif_anim.c img_jpeg.c img_tga.c \
  546. img_pnm.c img_ico.c img_pam.c) common/inflate.c
  547. IMGTEST_DEPS = $(wildcard user/lib/img/*.h) common/inflate.h testdata/images/expected.h
  548. IMGTEST_INC = -I. -Icommon -Iinclude -Iuser
  549. img_test: $(IMGTEST_SRCS) $(IMGTEST_DEPS)
  550. gcc -O2 -fwrapv -Wall -Wextra $(IMGTEST_INC) -o $@ $(IMGTEST_SRCS)
  551. test-images: img_test
  552. ./img_test
  553. test-images-asan: $(IMGTEST_SRCS) $(IMGTEST_DEPS)
  554. # -fwrapv: the integer IDCT deliberately relies on 32-bit wrap-around.
  555. gcc -O1 -g -fwrapv -fsanitize=address,undefined $(IMGTEST_INC) -o img_test_asan $(IMGTEST_SRCS)
  556. ./img_test_asan
  557. # Host tests for the ring-3 libc. The malloc/free names are renamed so the
  558. # host libc (printf, rand, write) keeps working normally.
  559. HOST_MALLOC_DEFS = -Dmalloc=libc_malloc -Dfree=libc_free \
  560. -Dcalloc=libc_calloc -Drealloc=libc_realloc \
  561. -Dheap_reset=libc_heap_reset
  562. LT = $(B)/host-test/libc
  563. LSRC = user/lib/libc
  564. $(LT)/malloc_host.o: $(LSRC)/malloc.c
  565. @mkdir -p $(@D)
  566. gcc -O2 -Wall -Wextra $(LIBC_INC) -fno-builtin $(HOST_MALLOC_DEFS) $(DEPFLAGS) -c -o $@ $<
  567. $(LT)/test_host_mem.o: $(LSRC)/test_host_mem.c
  568. @mkdir -p $(@D)
  569. gcc -O2 -Wall -Wextra $(DEPFLAGS) -c -o $@ $<
  570. malloc_test: $(LSRC)/test_malloc.c $(LT)/malloc_host.o $(LT)/test_host_mem.o
  571. gcc -O2 -Wall -Wextra -o $@ $^
  572. $(LT)/stdio_host.o: $(LSRC)/stdio.c
  573. @mkdir -p $(@D)
  574. gcc -O2 -Wall -Wextra $(LIBC_INC) -fno-builtin $(DEPFLAGS) -c -o $@ $<
  575. $(LT)/dtoa_host.o: $(LSRC)/dtoa.c
  576. @mkdir -p $(@D)
  577. gcc -O2 -Wall -Wextra $(LIBC_INC) -fno-builtin $(DEPFLAGS) -c -o $@ $<
  578. $(LT)/math_host.o: $(LSRC)/math.c
  579. @mkdir -p $(@D)
  580. gcc -O2 -Wall -Wextra $(LIBC_INC) -fno-builtin $(DEPFLAGS) -c -o $@ $<
  581. $(LT)/div64_host.o: $(LSRC)/div64.c
  582. @mkdir -p $(@D)
  583. gcc -O2 -Wall -Wextra $(DEPFLAGS) -c -o $@ $<
  584. format_test: $(LSRC)/test_format.c $(LT)/stdio_host.o $(LT)/dtoa_host.o
  585. gcc -O2 -Wall -Wextra -Wno-format-truncation $(LIBC_INC) -o $@ $^
  586. math_test: $(LSRC)/test_math.c $(LT)/math_host.o
  587. gcc -O2 -Wall -Wextra -o $@ $^ -lm
  588. div64_test: $(LSRC)/test_div64.c $(LT)/div64_host.o
  589. gcc -O2 -Wall -Wextra -o $@ $^
  590. setjmp_test: $(LSRC)/test_setjmp.c $(UL)/libc/setjmp.o
  591. gcc -m32 -O2 -Wall -Wextra $(LIBC_INC) -o $@ $^
  592. test-libc: malloc_test format_test math_test div64_test setjmp_test
  593. ./malloc_test
  594. ./format_test
  595. ./math_test
  596. ./div64_test
  597. ./setjmp_test
  598. QJS_HOST_SRCS = $(addprefix $(QJS_DIR)/,quickjs.c cutils.c dtoa.c libregexp.c libunicode.c)
  599. JS_TEST_SRCS = user/apps/browser/js_test.c user/apps/browser/js_mu.c
  600. js_test: $(JS_TEST_SRCS) user/apps/browser/js_mu.h $(QJS_HOST_SRCS) $(wildcard $(QJS_DIR)/*.h)
  601. gcc -O1 -g -w -fsanitize=address,undefined -fno-sanitize=shift -Iinclude -Iuser -I$(QJS_DIR) -D__nebos__ -DJS_MU_HOST \
  602. -DCONFIG_VERSION='"2026-06-04"' -o $@ $(JS_TEST_SRCS) $(QJS_HOST_SRCS) -lm
  603. test-js: js_test
  604. ./js_test
  605. # ---- Host tools ------------------------------------------------------------
  606. mkpack: tools/mkpack.c
  607. gcc -O2 -o $@ $<
  608. mkrootfs: tools/mkrootfs.c include/rootfs.h
  609. gcc -O2 -Iinclude -o $@ $<
  610. mkrtwtbl: tools/mkrtwtbl.c include/rtl8821a_tbl.h third_party/rtw88/rtw8821a_table.inc
  611. gcc -O2 -Wall -Wextra -I. -Iinclude -o $@ $<
  612. kexec_send: tools/kexec_send.c
  613. gcc -O2 -o $@ $<
  614. netkexec_send: tools/netkexec_send.c
  615. gcc -O2 -o $@ $<
  616. netmonitor: tools/netmonitor.c
  617. gcc -O2 -o $@ $<
  618. mkicons: tools/mkicons.c include/icon_abi.h user/apps/browser/svg_raster.c user/apps/browser/svg_raster.h
  619. gcc -O2 -Wall -Wextra -Iinclude -o $@ tools/mkicons.c user/apps/browser/svg_raster.c -lm
  620. mkcursors: tools/mkcursors.c include/cursor_abi.h
  621. gcc -O2 -Wall -Wextra -Iinclude -o $@ $<
  622. cursor_test: tools/cursor_test.c include/cursor_abi.h
  623. gcc -O1 -g -Wall -Wextra -fsanitize=address,undefined -Iinclude -o $@ $<
  624. # ---- Command pack (the system rootfs) ---------------------------------------
  625. #
  626. # The ring-3 command ELFs plus hello and the browser/gallery apps, packed
  627. # into bin/<name>. See tools/mkpack.c, include/rootfs.h and kernel/ramfs.h.
  628. FONT_FILES = fonts/sans.ttf fonts/sans-b.ttf fonts/sans-i.ttf \
  629. fonts/sans-bi.ttf fonts/mono.ttf fonts/emoji.ttf
  630. # Mouse cursors: the Adwaita theme's 24 px images (assets/cursors/adwaita/,
  631. # LGPL-3 / CC-BY-SA-3.0) converted to one NBCUR1 bundle (include/cursor_abi.h)
  632. # that kernel/cursor.c loads from /ramfs/cursors/adwaita24.cur. Full pack
  633. # only (~18 KB gzip): the floppy lite pack has no room, and its kernel keeps
  634. # the built-in 16x16 arrow.
  635. CURSOR_THEME = assets/cursors/adwaita
  636. CURSOR_FILE = cursors/adwaita24.cur
  637. $(CURSOR_FILE): mkcursors $(filter-out %/README %/COPYING%,$(wildcard $(CURSOR_THEME)/*))
  638. @mkdir -p cursors
  639. ./mkcursors $(CURSOR_THEME) 24 $@
  640. # Defined after CURSOR_FILE: make expands a rule's prerequisites at once.
  641. test-cursors: cursor_test $(CURSOR_FILE)
  642. ./cursor_test $(CURSOR_FILE)
  643. # UI icons: the Adwaita symbolic SVGs (assets/icons/adwaita/, LGPL-3 /
  644. # CC-BY-SA-3.0) rasterized by mkicons (with the browser's svg_raster.c) into
  645. # one NBICO1 bundle of 16 px coverage masks (include/icon_abi.h) that ngui
  646. # loads from /ramfs/icons/adwaita16.icn and tints. ~3.3 KB (~0.8 KB gzip),
  647. # so the floppy lite pack carries it as well.
  648. ICON_THEME = assets/icons/adwaita
  649. ICON_FILE = icons/adwaita16.icn
  650. $(ICON_FILE): mkicons $(wildcard $(ICON_THEME)/*.svg)
  651. @mkdir -p icons
  652. ./mkicons $(ICON_THEME) 16 $@
  653. HELLO_ELF = $(U)/apps/hello/hello.elf
  654. PACK_FILES = $(foreach a,$(UCMDS),bin/$(a)=$(call app,$(a)).elf) \
  655. bin/hello=$(HELLO_ELF) \
  656. bin/gallery.app=gallery.elf \
  657. $(foreach f,$(FONT_FILES),$(f)=$(f)) \
  658. $(ICON_FILE)=$(ICON_FILE)
  659. PACK_DEPS = $(UCMD_ELFS) $(HELLO_ELF) browser.elf gallery.elf $(FONT_FILES) \
  660. $(ICON_FILE) mkpack
  661. PACK_CURSOR_FILES = $(CURSOR_FILE)=$(CURSOR_FILE)
  662. # The browser (~500 KB gzip) is in the full pack only: a floppy boot runs it
  663. # from BROWSER on root.img, which the bin/browser launcher already tries.
  664. PACK_BROWSER_FILES = bin/browser.app=browser.elf
  665. # `install self` reads the flat kernel from the full pack. The lite/floppy
  666. # pack deliberately omits it (no room on a 1.44 MB disk).
  667. PACK_INSTALL_FILES = install/kernel.bin=kernel.bin
  668. # WiFi firmware (kernel/iwl_trans.c): the Intel 7265D/3165 (Chromebook, MVM)
  669. # and the 6200/6300 (ThinkPad X201, DVM). Taken from the host's
  670. # linux-firmware (`.zst` or plain); WIFI_FW_7265D / WIFI_FW_6000 override the
  671. # search. A machine without one still builds: the pack then has no
  672. # firmware/ entry for that card and `wifi` reports it missing.
  673. fw_search = $(firstword $(wildcard \
  674. /usr/lib/firmware/intel/iwlwifi/$(1).zst /usr/lib/firmware/$(1).zst \
  675. /usr/lib/firmware/intel/iwlwifi/$(1) /usr/lib/firmware/$(1) \
  676. /lib/firmware/$(1)))
  677. WIFI_FW_7265D ?= $(call fw_search,iwlwifi-7265D-29.ucode)
  678. WIFI_FW_6000 ?= $(call fw_search,iwlwifi-6000-4.ucode)
  679. WIFI_FW_FILE =
  680. PACK_FW_FILES =
  681. # $(1) = file name in the pack, $(2) = host source.
  682. define wifi_fw_rule
  683. ifneq ($(2),)
  684. WIFI_FW_FILE += firmware/$(1)
  685. PACK_FW_FILES += firmware/$(1)=firmware/$(1)
  686. firmware/$(1): $(2)
  687. @mkdir -p firmware
  688. case "$$<" in *.zst) zstd -q -d -c "$$<" > $$@ ;; *) cp "$$<" $$@ ;; esac
  689. else
  690. $$(info note: $(1) not found; building the pack without it)
  691. endif
  692. endef
  693. $(eval $(call wifi_fw_rule,iwlwifi-7265D-29.ucode,$(WIFI_FW_7265D)))
  694. $(eval $(call wifi_fw_rule,iwlwifi-6000-4.ucode,$(WIFI_FW_6000)))
  695. # Realtek RTL8821AU USB sticks (kernel/rtl8821au.c): the rtw88 8051 firmware
  696. # from linux-firmware (WIFI_FW_8821A overrides the search) and the register
  697. # tables, generated from third_party/rtw88 by the host tool mkrtwtbl. Both
  698. # are only in the full pack, like the Intel firmware.
  699. WIFI_FW_8821A ?= $(firstword $(wildcard \
  700. /usr/lib/firmware/rtw88/rtw8821a_fw.bin.zst \
  701. /usr/lib/firmware/rtw88/rtw8821a_fw.bin \
  702. /lib/firmware/rtw88/rtw8821a_fw.bin))
  703. $(eval $(call wifi_fw_rule,rtw8821a_fw.bin,$(WIFI_FW_8821A)))
  704. WIFI_FW_FILE += firmware/rtl8821a.tbl
  705. PACK_FW_FILES += firmware/rtl8821a.tbl=firmware/rtl8821a.tbl
  706. firmware/rtl8821a.tbl: mkrtwtbl
  707. @mkdir -p firmware
  708. ./mkrtwtbl $@
  709. cmds.pack: $(PACK_DEPS) $(WIFI_FW_FILE) $(CURSOR_FILE) kernel.bin
  710. ./mkpack $@ $(PACK_FILES) $(PACK_BROWSER_FILES) $(PACK_CURSOR_FILES) \
  711. $(PACK_INSTALL_FILES) \
  712. $(PACK_FW_FILES)
  713. # The floppy images cannot hold the ~1 MB firmware: they get the same pack
  714. # without firmware/* (and without the cursor bundle or bin/browser.app).
  715. cmds-lite.pack: $(PACK_DEPS)
  716. ./mkpack $@ $(PACK_FILES)
  717. # The boot-time rootfs is gzip-compressed; the raw cmds.pack is still what
  718. # cmds-dev/net-cmds send for a runtime replacement. Prefer libdeflate's
  719. # level 12 when it is installed: it saves about 8 KB over gzip -9 on the
  720. # current pack. The high-memory rootfs loader supports up to 2 MB; the
  721. # floppy images use the firmware-less lite pack (rootfs.bin).
  722. CMDS_GZ = $(shell command -v libdeflate-gzip >/dev/null 2>&1 && \
  723. echo "libdeflate-gzip -12 -c" || echo "gzip -9 -n -c")
  724. CMDS_GZ_MAX = 2097152
  725. cmds_lite_gz.bin: cmds-lite.pack
  726. $(CMDS_GZ) $< > $@
  727. cmds_pack_gz.bin: cmds.pack
  728. $(CMDS_GZ) $< > $@
  729. @sz=$$(stat -c%s $@); \
  730. if [ $$sz -gt $(CMDS_GZ_MAX) ]; then \
  731. echo "error: cmds_pack_gz.bin is $$sz bytes; the legacy rootfs cap is $(CMDS_GZ_MAX)"; \
  732. rm -f $@; exit 1; \
  733. fi
  734. # Rootfs image: one NBROOT1 header sector + the gzip pack (rootfs.h).
  735. # rootfs.bin (the lite pack, no firmware) is appended to the floppy images;
  736. # cmds.img is the 8 MB image flashed into the USB rootfs partition.
  737. rootfs.bin: cmds_lite_gz.bin mkrootfs
  738. ./mkrootfs $@ cmds_lite_gz.bin
  739. # Full NBROOT1 image (header + gzip pack, no partition padding) for the
  740. # network install path. `install self` uses the retained boot image instead.
  741. rootfs-full.bin: cmds_pack_gz.bin mkrootfs
  742. ./mkrootfs $@ cmds_pack_gz.bin
  743. rootfs: cmds.img
  744. cmds.img: cmds_pack_gz.bin mkrootfs
  745. ./mkrootfs $@ cmds_pack_gz.bin $$(( $(ROOTFS_SECTORS) * 512 ))
  746. # Diagnostic: no WM, boot console stays visible. Rebuild normally with
  747. # `make -B ...` afterwards (the objects carry -DNOWM).
  748. nowm:
  749. $(MAKE) NOWM=1 -B kernel.elf kernel.bin floppy.img usb.img usb-efi.img final.bin
  750. @echo "nowm: WM disabled; flash usb.img or usb-efi.img."
  751. root.img: browser.elf gallery.elf testdata/browser/demo.html testdata/browser/js.html testdata/browser/jsext.js testdata/images/rgb.bmp
  752. dd if=/dev/zero of=$@ bs=512 count=2880 2>/dev/null
  753. mkfs.fat -F 12 -n "ROOTDISK" $@
  754. echo "Hello from the second floppy!" | mcopy -i $@ - ::HELLO.TXT
  755. echo "This is a test file on drive 1." | mcopy -i $@ - ::TEST.TXT
  756. mcopy -i $@ browser.elf ::BROWSER
  757. mcopy -i $@ gallery.elf ::GALLERY
  758. mcopy -i $@ testdata/browser/demo.html ::DEMO.HTM
  759. mcopy -i $@ testdata/browser/js.html ::JS.HTM
  760. mcopy -i $@ testdata/browser/jsext.js ::JSEXT.JS
  761. mcopy -i $@ testdata/images/rgb.bmp ::PIC.BMP
  762. OVMF ?= $(firstword $(wildcard /usr/share/ovmf/x64/OVMF.4m.fd /usr/share/OVMF/OVMF.4m.fd))
  763. # Guest RAM for the QEMU targets, matching the 1 GB kernel ceiling (phys.h);
  764. # override with e.g. `make run QEMU_MEM=512M` (RAM above 1 GB is ignored).
  765. QEMU_MEM ?= 1G
  766. # root.img is deliberately not attached: a running QEMU may hold its write
  767. # lock, and the UEFI boot test does not need a second filesystem.
  768. run-uefi: usb-efi.img
  769. @test -n "$(OVMF)" || { echo "OVMF not found; set OVMF=/path/to/OVMF.4m.fd" >&2; exit 1; }
  770. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -smp 4 -bios $(OVMF) -snapshot \
  771. -drive file=usb-efi.img,format=raw,if=ide \
  772. -device pci-ohci -device usb-mouse \
  773. -device ne2k_pci,netdev=n0 -netdev user,id=n0 \
  774. -serial file:/tmp/opencode/nebos-uefi-serial.log
  775. test-uefi: usb-efi.img
  776. @test -n "$(OVMF)" || { echo "OVMF not found; set OVMF=/path/to/OVMF.4m.fd" >&2; exit 1; }
  777. @rm -f /tmp/opencode/nebos-uefi-serial.log
  778. timeout 40 qemu-system-x86_64 -M pc -m $(QEMU_MEM) -smp 4 -bios $(OVMF) -snapshot \
  779. -drive file=usb-efi.img,format=raw,if=ide \
  780. -device pci-ohci -device usb-mouse \
  781. -device ne2k_pci,netdev=n0 -netdev user,id=n0 \
  782. -display none -serial file:/tmp/opencode/nebos-uefi-serial.log \
  783. -no-reboot >/dev/null 2>&1 || true
  784. @grep -q "booted" /tmp/opencode/nebos-uefi-serial.log && \
  785. echo "UEFI boot: OK (/tmp/opencode/nebos-uefi-serial.log)" || \
  786. { echo "UEFI boot: FAILED"; tail -c 4000 /tmp/opencode/nebos-uefi-serial.log; exit 1; }
  787. run: image.bin root.img
  788. $(MAKE) run-floppy
  789. # Four logical CPUs (the Atom 330 topology). UP is still the default so a
  790. # machine without ACPI/MADT boots exactly as before.
  791. run-smp: floppy.img root.img
  792. 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 || \
  793. 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
  794. floppy: floppy.img
  795. usb: usb.img
  796. # Write the dual-boot USB image (legacy BIOS + UEFI) to a stick; prompts
  797. # before destroying anything.
  798. # make flash USB=/dev/sdX FORCE=1 skips the removable-device check.
  799. # make flash FLASH_IMG=usb.img legacy-only image
  800. # The UEFI half needs the mingw toolchain (EFI_CC); the legacy half does not.
  801. FLASH_IMG ?= usb-efi.img
  802. flash: $(FLASH_IMG)
  803. @tools/flash.sh "$(USB)" "$(FORCE)" "$(FLASH_IMG)"
  804. run-floppy: floppy.img root.img
  805. 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 || \
  806. 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
  807. run-usb: usb.img root.img
  808. 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 || \
  809. 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
  810. # UHCI variant (machines with an Intel/VIA-style controller, and the
  811. # regression test for the UHCI backend of the USB core).
  812. run-uhci: floppy.img root.img
  813. 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 || \
  814. 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
  815. # xHCI variant (Braswell/Intel PCH and other USB 3.0-only machines).
  816. run-xhci: floppy.img root.img
  817. 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 || \
  818. 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
  819. # RNDIS variant: QEMU's usb-net is a full-speed RNDIS function. It sits on
  820. # xHCI (QEMU's USB2 root ports), and `-nic none` keeps the PCI e1000 out of
  821. # the way so the phone/tethering link is the active NIC.
  822. run-rndis: floppy.img root.img
  823. 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 || \
  824. 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
  825. # EHCI variant (USB 2.0 high-speed root ports). usb-storage is high-speed
  826. # and lands on EHCI; the mouse/keyboard are full-speed and use the UHCI
  827. # companion, exercising the multi-controller USB core.
  828. run-ehci: floppy.img root.img
  829. qemu-system-i386 -M pc -m $(QEMU_MEM) -boot a -device usb-ehci,id=ehci0 -device piix3-usb-uhci,id=uhci0 \
  830. -device usb-storage,bus=ehci0.0,drive=usbstick \
  831. -drive if=none,id=usbstick,file=root.img,format=raw \
  832. -device usb-mouse,bus=uhci0.0 -device usb-kbd,bus=uhci0.0 \
  833. -drive file=floppy.img,format=raw,if=floppy 2>/dev/null || \
  834. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -boot a -device usb-ehci,id=ehci0 -device piix3-usb-uhci,id=uhci0 \
  835. -device usb-storage,bus=ehci0.0,drive=usbstick \
  836. -drive if=none,id=usbstick,file=root.img,format=raw \
  837. -device usb-mouse,bus=uhci0.0 -device usb-kbd,bus=uhci0.0 \
  838. -drive file=floppy.img,format=raw,if=floppy
  839. # Passthrough of the real ASIX AX88772 dongle (requires the host's asix
  840. # driver to be unbound and permission on /dev/bus/usb/...; typically run with
  841. # sudo). `-nic none` keeps the QEMU e1000 out of the way so the USB NIC is
  842. # the only netdev.
  843. ASIX_HOST ?= vendorid=0x0b95,productid=0x7720
  844. run-ehci-asix: floppy.img root.img
  845. 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 || \
  846. 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
  847. run-xhci-asix: floppy.img root.img
  848. 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 || \
  849. 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
  850. # Network variant: a PCI NE2000 (RTL8029, the driver's QEMU match) on QEMU's
  851. # user-mode network (slirp). DHCP/DNS come from slirp, the host is 10.0.2.2
  852. # (e.g. `python3 -m http.server` + `curl http://10.0.2.2:8000/` in a window).
  853. run-net: floppy.img root.img
  854. 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 || \
  855. 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
  856. # Intel e1000 variant: QEMU's 82540EM exercises the e1000e driver's MAC/DMA
  857. # path. (The X201's 82577LM uses the same registers; only its PCH PHY is
  858. # different.) usb-kbd is there for headless QMP `send-key` typing.
  859. run-e1000: floppy.img root.img
  860. qemu-system-i386 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device usb-kbd \
  861. -device e1000,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 \
  862. -drive file=floppy.img,format=raw,if=floppy \
  863. -drive file=root.img,format=raw,if=floppy 2>/dev/null || \
  864. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -device pci-ohci -device usb-mouse -device usb-kbd \
  865. -device e1000,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080 \
  866. -drive file=floppy.img,format=raw,if=floppy \
  867. -drive file=root.img,format=raw,if=floppy
  868. # SATA/AHCI variant: an ICH9 AHCI controller with a test disk on port 0.
  869. # The disk image lives outside the repo and is created on first use; boot
  870. # stays on the floppy (order=a), the SATA disk shows up as sata0.
  871. SATA_IMG ?= /tmp/opencode/nebos-sata.img
  872. run-ahci: floppy.img root.img
  873. @test -f $(SATA_IMG) || truncate -s 512M $(SATA_IMG)
  874. qemu-system-i386 -M pc -m $(QEMU_MEM) -boot order=a -device pci-ohci -device usb-mouse \
  875. -drive file=floppy.img,format=raw,if=floppy \
  876. -drive file=root.img,format=raw,if=floppy \
  877. -device ich9-ahci,id=sata \
  878. -drive file=$(SATA_IMG),format=raw,if=none,id=satadisk \
  879. -device ide-hd,drive=satadisk,bus=sata.0 2>/dev/null || \
  880. qemu-system-x86_64 -M pc -m $(QEMU_MEM) -boot order=a -device pci-ohci -device usb-mouse \
  881. -drive file=floppy.img,format=raw,if=floppy \
  882. -drive file=root.img,format=raw,if=floppy \
  883. -device ich9-ahci,id=sata \
  884. -drive file=$(SATA_IMG),format=raw,if=none,id=satadisk \
  885. -device ide-hd,drive=satadisk,bus=sata.0
  886. # AMD Piledriver regression: QEMU's Opteron_G5 is the FX-6350's family 15h
  887. # model 2 CPU. Exercises the AMD CPUID/MTRR/xAPIC paths, the AMD thermal
  888. # probe, the IOAPIC mask and six-core ACPI SMP. QEMU has no SB950 or
  889. # RTL8111E, so the e1000/OHCI devices cover the rest of the boot path.
  890. run-amd: floppy.img root.img
  891. qemu-system-x86_64 -M pc -cpu Opteron_G5 -smp 6 -m $(QEMU_MEM) \
  892. -device pci-ohci -device usb-mouse -device usb-kbd \
  893. -device e1000,netdev=n0 -netdev user,id=n0 \
  894. -drive file=floppy.img,format=raw,if=floppy \
  895. -drive file=root.img,format=raw,if=floppy
  896. test-amd: floppy.img root.img
  897. @rm -f /tmp/opencode/nebos-amd-serial.log
  898. timeout 40 qemu-system-x86_64 -M pc -cpu Opteron_G5 -smp 6 -m $(QEMU_MEM) \
  899. -device pci-ohci -device usb-mouse -device usb-kbd \
  900. -device e1000,netdev=n0 -netdev user,id=n0 \
  901. -drive file=floppy.img,format=raw,if=floppy \
  902. -drive file=root.img,format=raw,if=floppy \
  903. -display none -serial file:/tmp/opencode/nebos-amd-serial.log \
  904. -no-reboot >/dev/null 2>&1 || true
  905. @grep -q "booted" /tmp/opencode/nebos-amd-serial.log && \
  906. grep -q "smp cpus: 6" /tmp/opencode/nebos-amd-serial.log && \
  907. grep -q "ioapic: masked" /tmp/opencode/nebos-amd-serial.log && \
  908. grep -q "thermal: AMD family 15h" /tmp/opencode/nebos-amd-serial.log && \
  909. ! grep -q "PIT NOT TICKING" /tmp/opencode/nebos-amd-serial.log && \
  910. echo "AMD boot: OK (/tmp/opencode/nebos-amd-serial.log)" || \
  911. { echo "AMD boot: FAILED"; tail -c 4000 /tmp/opencode/nebos-amd-serial.log; exit 1; }
  912. # Headless USB HID regression tests (QEMU + python3): cursor movement via
  913. # injected USB mouse reports and keyboard input via injected key events,
  914. # including hotplug. See tools/*.py.
  915. test-usb: floppy.img root.img
  916. python3 tools/qmp_cursor_test.py
  917. python3 tools/qmp_cursor_test.py --uhci
  918. python3 tools/qmp_cursor_test.py --uhci72
  919. python3 tools/qmp_cursor_test.py --hotplug
  920. python3 tools/qmp_cursor_test.py --xhci
  921. python3 tools/qmp_cursor_test.py --ehci
  922. python3 tools/qmp_keyboard_test.py
  923. python3 tools/qmp_keyboard_test.py --hotplug
  924. python3 tools/qmp_keyboard_test.py --xhci
  925. python3 tools/qmp_keyboard_test.py --ehci
  926. # End-to-end installer test: boot the dual-boot USB image as an IDE disk,
  927. # attach the same image as a USB mass-storage source, type `install ide1`
  928. # on the terminal and verify + boot the cloned target.
  929. test-install: usb-efi.img
  930. python3 tools/qmp_install_test.py
  931. scp-final: final.bin
  932. scp final.bin root@192.168.0.136:
  933. ssh root@192.168.0.136 dd if=final.bin of=/dev/fd0 bs=512
  934. scp-root: root.img
  935. scp root.img root@192.168.0.136:
  936. ssh root@192.168.0.136 dd if=root.img of=/dev/fd0 bs=512
  937. SERIAL_DEV ?= /dev/ttyUSB0
  938. SERIAL_BAUD ?= 115200
  939. run-serial:
  940. @echo "Starting serial monitor on $(SERIAL_DEV) at $(SERIAL_BAUD) baud..."
  941. @echo "Type 'serial test' in the nebos terminal."
  942. @echo "Press Ctrl-A Ctrl-X to exit picocom."
  943. picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
  944. monitor:
  945. @echo "Watching $(SERIAL_DEV) @ $(SERIAL_BAUD) baud (Ctrl-A Ctrl-X to exit)."
  946. @echo "Each 'make dev' reload prints: NebOS v<version> booted"
  947. picocom $(SERIAL_DEV) --baud $(SERIAL_BAUD)
  948. dev: kernel.bin cmds_pack_gz.bin kexec_send
  949. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  950. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  951. echo "Sending kernel.bin + cmds_pack_gz.bin (entry 0x$$entry) via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."; \
  952. ./kexec_send $(SERIAL_DEV) $(SERIAL_BAUD) $$entry kernel.bin cmds_pack_gz.bin
  953. # Kernel-only fast path: the board keeps its running rootfs.
  954. kernel-dev: kernel.bin kexec_send
  955. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  956. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  957. echo "Sending kernel.bin only (entry 0x$$entry) via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."; \
  958. ./kexec_send $(SERIAL_DEV) $(SERIAL_BAUD) $$entry kernel.bin
  959. # Push just the command pack (cmds.pack) to a running board: no kernel
  960. # reload, the /ramfs contents are replaced in place. The board must be idle
  961. # at a prompt (the WM loop auto-detects the transfer).
  962. cmds-dev: cmds.pack kexec_send
  963. @echo "Sending cmds.pack via $(SERIAL_DEV) @ $(SERIAL_BAUD)..."
  964. ./kexec_send --payload $(SERIAL_DEV) $(SERIAL_BAUD) cmds.pack
  965. net-cmds: cmds.pack netkexec_send
  966. @echo "Sending cmds.pack to $(BOARD_IP):$(NETKEXEC_PORT)..."
  967. ./netkexec_send --payload $(BOARD_IP) $(NETKEXEC_PORT) cmds.pack
  968. # Development override: upload the real browser to the board's writable
  969. # /share; the bin/browser launcher prefers it over the pack copy. The board
  970. # must be running `websrv`; stop it before browsing HTTP, since the WebDAV
  971. # server owns the NIC.
  972. browser-dev: browser.elf
  973. @echo "Uploading browser.elf to http://$(BOARD_IP):8080/share/BROWSER..."
  974. curl -f -T browser.elf http://$(BOARD_IP):8080/share/BROWSER
  975. # gallery follows the same development-override model.
  976. gallery-dev: gallery.elf
  977. @echo "Uploading gallery.elf to http://$(BOARD_IP):8080/share/GALLERY..."
  978. curl -f -T gallery.elf http://$(BOARD_IP):8080/share/GALLERY
  979. # Browser compatibility ladder: serve testdata/browser/compat so the board
  980. # or a QEMU guest can open http://<host>:$(COMPAT_PORT)/.
  981. COMPAT_PORT ?= 8000
  982. compat-serve:
  983. @echo "Serving the browser compatibility ladder on port $(COMPAT_PORT)"
  984. python3 -m http.server -d testdata/browser/compat $(COMPAT_PORT)
  985. # Show the board's netlog stream (kernel debug + terminal text) like `make
  986. # monitor` does over serial.
  987. netmon: netmonitor
  988. @echo "Listening for netlog on UDP $(NETLOG_PORT) (Ctrl-C to exit)."
  989. ./netmonitor $(NETLOG_PORT)
  990. # Push a fresh kernel over Ethernet (the board auto-detects it from its idle
  991. # loop; no serial and no USB stick involved).
  992. BOARD_IP ?= 192.168.178.240
  993. NETLOG_PORT ?= 19290
  994. NETKEXEC_PORT ?= 19288
  995. net-dev: kernel.bin cmds_pack_gz.bin netkexec_send
  996. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  997. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  998. echo "Sending kernel.bin + cmds_pack_gz.bin (entry 0x$$entry) to $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  999. ./netkexec_send $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin cmds_pack_gz.bin
  1000. # Kernel-only fast path: the board keeps its running rootfs.
  1001. kernel-net-dev: kernel.bin netkexec_send
  1002. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  1003. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  1004. echo "Sending kernel.bin only (entry 0x$$entry) to $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  1005. ./netkexec_send $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin
  1006. # Persistent update: write P1/P2 on the target disk (P4/data is untouched),
  1007. # then jump into the new kernel. TARGET=auto picks the only non-USB NebOS
  1008. # disk; use NETINSTALL_TARGET=mmc0/sata0/... to override.
  1009. NETINSTALL_TARGET ?= auto
  1010. net-install: kernel.bin rootfs-full.bin netkexec_send
  1011. @entry=$$(nm kernel.elf | awk '/ T kernel_entry$$/{print $$1}'); \
  1012. if [ -z "$$entry" ]; then echo "error: kernel_entry symbol not found"; exit 1; fi; \
  1013. echo "Persisting kernel.bin + rootfs-full.bin to $(NETINSTALL_TARGET) on $(BOARD_IP):$(NETKEXEC_PORT)..."; \
  1014. ./netkexec_send --install $(NETINSTALL_TARGET) $(BOARD_IP) $(NETKEXEC_PORT) 0x$$entry kernel.bin rootfs-full.bin
  1015. clean:
  1016. rm -rf $(B) host/build
  1017. rm -f kernel.elf kernel.bin boot.bin mbr.bin boot.bin.tmp image.bin \
  1018. floppy.img usb.img usb-efi.img esp.img final.bin root.img \
  1019. BOOTX64.EFI browser.elf gallery.elf *.boot.tmp \
  1020. cmds.pack cmds-lite.pack cmds_pack_gz.bin cmds_lite_gz.bin \
  1021. rootfs.bin rootfs-full.bin cmds.img \
  1022. firmware/*.ucode firmware/*.tbl firmware/*.bin cursors/*.cur icons/*.icn \
  1023. mkpack mkrootfs mkrtwtbl mkcursors mkicons cursor_test kexec_send netkexec_send netmonitor \
  1024. browser-host host-curl \
  1025. ufont_test ufont_test_asan svg_test touchpad_gesture_test \
  1026. ujson_test uhttp_cookie_test chat_login_test tls_test wpa_test \
  1027. wifi_store_test ccmp_test img_test img_test_asan malloc_test \
  1028. format_test math_test div64_test setjmp_test js_test
  1029. # Compiler-generated header dependencies.
  1030. -include $(shell find $(B) host/build -name '*.d' 2>/dev/null)