Makefile 58 KB

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