Makefile 65 KB

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