Makefile 58 KB

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