Makefile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #
  2. # meg4/platform/baremetal/Makefile
  3. #
  4. # Copyright (C) 2023 bzt
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. #
  20. # @brief Creating a bootable MEG-4 disk image
  21. #
  22. # ----- configure your MEG-4 OS image -----
  23. IMGSIZE?=256
  24. KBDMAP?=us
  25. LANG?=en
  26. FLOPPYDEV?=/dev/sda1
  27. KERNEL?=6.4.2
  28. # ----- end of configuration -----
  29. qemu=qemu-system-$(shell uname -m) -m 256 -drive file=meg4.iso,format=raw -device virtio-mouse -serial stdio
  30. # 1280 x 800 x 32
  31. FBSET=vga=0x37a
  32. all: meg4.iso
  33. ### compile MEG-4 as an init process ###
  34. rootfs/init:
  35. USE_INIT=1 KBDMAP=$(KBDMAP) LANG=$(LANG) FLOPPYDEV=$(FLOPPYDEV) make --no-print-directory -C ../fbdev_alsa clean all
  36. @mkdir -p rootfs 2>/dev/null || true
  37. cp -f ../fbdev_alsa/meg4 rootfs/init
  38. strip rootfs/init
  39. ### get the Linux kernel ###
  40. kernel.tar.xz:
  41. wget -c http://kernel.org/pub/linux/kernel/v$(word 1,$(subst ., ,$(KERNEL))).x/linux-$(KERNEL).tar.xz -O kernel.tar.xz
  42. linux-$(KERNEL)/Kconfig: kernel.tar.xz
  43. tar -xvf kernel.tar.xz
  44. @# make sure Kconfig is newer than kernel.tar.xz
  45. @touch linux-$(KERNEL)/Kconfig
  46. linux-$(KERNEL)/.config: linux-$(KERNEL)/Kconfig
  47. ifneq ($(wildcard $(KCONFIG)),)
  48. cp $(KCONFIG) linux-$(KERNEL)/.config
  49. else
  50. make -C linux-${KERNEL} -j4 defconfig
  51. sed -i "s|.*CONFIG_NET=y.*|# CONFIG_NET is not set|" linux-$(KERNEL)/.config
  52. sed -i "s/^CONFIG_DEBUG_KERNEL.*/\\# CONFIG_DEBUG_KERNEL is not set/" linux-$(KERNEL)/.config
  53. sed -i "s|.*# CONFIG_KERNEL_XZ is not set.*|CONFIG_KERNEL_XZ=y|" linux-$(KERNEL)/.config
  54. sed -i "s|.*CONFIG_KERNEL_GZIP=y.*|# CONFIG_KERNEL_GZIP is not set|" linux-$(KERNEL)/.config
  55. sed -i "s|.*# CONFIG_FB is not set.*|CONFIG_FB=y|" linux-$(KERNEL)/.config
  56. sed -i "s|.*# CONFIG_FB_VESA is not set.*|CONFIG_FB_VESA=y|" linux-$(KERNEL)/.config
  57. sed -i "s|.*# CONFIG_FB_EFI is not set.*|CONFIG_FB_EFI=y|" linux-$(KERNEL)/.config
  58. sed -i "s|.*# CONFIG_FB_SIMPLE is not set.*|CONFIG_FB_SIMPLE=y|" linux-$(KERNEL)/.config
  59. sed -i "s|.*# CONFIG_DRM is not set*|CONFIG_DRM=y|" linux-$(KERNEL)/.config
  60. sed -i "s|.*# CONFIG_DRM_FBDEV_EMULATION is not set*|CONFIG_DRM_FBDEV_EMULATION=y|" linux-$(KERNEL)/.config
  61. sed -i "s|.*# CONFIG_DRM_BOCHS is not set*|CONFIG_DRM_BOCHS=y|" linux-$(KERNEL)/.config
  62. sed -i "s|.*# CONFIG_DRM_CIRRUS_QEMU is not set*|CONFIG_DRM_CIRRUS_QEMU=y|" linux-$(KERNEL)/.config
  63. sed -i "s|.*# CONFIG_DRM_VBOXVIDEO is not set*|CONFIG_DRM_VBOXVIDEO=y|" linux-$(KERNEL)/.config
  64. sed -i "s|.*# CONFIG_DRM_SIMPLEDRM is not set*|CONFIG_DRM_SIMPLEDRM=y|" linux-$(KERNEL)/.config
  65. sed -i "s|.*# CONFIG_DRM_RADEON is not set*|CONFIG_DRM_RADEON=y|" linux-$(KERNEL)/.config
  66. sed -i "s|.*# CONFIG_DRM_AMDGPU is not set*|CONFIG_DRM_AMDGPU=y|" linux-$(KERNEL)/.config
  67. sed -i "s|.*# CONFIG_DRM_I915 is not set*|CONFIG_DRM_I915=y|" linux-$(KERNEL)/.config
  68. endif
  69. sed -i "s|.*CONFIG_DEFAULT_HOSTNAME=*|CONFIG_DEFAULT_HOSTNAME=\"MEG4\"|" linux-$(KERNEL)/.config
  70. boot/vmlinuz: linux-$(KERNEL)/.config
  71. @# patch the Linux kernel so that it will assign device files deterministically on every boot
  72. sed -i "s|PROBE_PREFER_ASYNCHRONOUS|PROBE_FORCE_SYNCHRONOUS|" linux-$(KERNEL)/drivers/scsi/sd.c
  73. @rm -rf rootfs/lib/modules 2>/dev/null || true
  74. @mkdir -p boot rootfs/lib/modules 2>/dev/null || true
  75. make -C linux-$(KERNEL) -j4 bzImage modules
  76. make INSTALL_PATH=../boot INSTALL_MOD_PATH=../rootfs -C linux-$(KERNEL) install modules_install
  77. @mv boot/vmlinuz-$(KERNEL) boot/vmlinuz 2>/dev/null || mv boot/bzImage-$(KERNEL) boot/vmlinuz 2>/dev/null || true
  78. @rm rootfs/lib/modules/$(KERNEL)/build rootfs/lib/modules/$(KERNEL)/source 2>/dev/null || true
  79. ### create initial ramdisk ###
  80. boot/initrd: rootfs/init
  81. @mkdir rootfs/dev rootfs/mnt rootfs/proc rootfs/sys rootfs/tmp 2>/dev/null || true
  82. @chmod +x rootfs/init
  83. cd rootfs && find . | cpio -R root:root -H newc -o | gzip > ../boot/initrd
  84. ### get boot loader
  85. simpleboot/distrib/simpleboot:
  86. git clone https://gitlab.com/bztsrc/simpleboot
  87. ### construct disk image ###
  88. meg4.iso: boot/vmlinuz boot/initrd simpleboot/distrib/simpleboot
  89. @mkdir -p boot/MEG-4 2>/dev/null || true
  90. @cp -r ../../public/floppies/* boot/MEG-4
  91. @cp ../../src/misc/logo.tga boot/meg4.tga
  92. @printf "kernel vmlinuz $(FBSET) console=ttyS0,115200 quiet\nmodule initrd\nbootsplash #444444 meg4.tga" >boot/simpleboot.cfg
  93. simpleboot/distrib/simpleboot -c -b $(IMGSIZE) boot meg4.iso
  94. package: meg4.iso
  95. @printf "#/bin/sh\n\nmkdir -p mnt\nsudo mount -o loop,offset=1048576,user,umask=000 meg4.iso mnt\n" > mount.sh && chmod +x mount.sh
  96. @printf "#/bin/sh\n\n$(qemu)\n" > run.sh && chmod +x run.sh
  97. tar -czvf ../../meg4-$(shell uname -m).iso.tgz meg4.iso mount.sh run.sh
  98. @rm mount.sh run.sh
  99. clean:
  100. rm -rf rootfs boot linux-* kernel.tar.xz simpleboot meg4.iso 2>/dev/null || true
  101. run: meg4.iso
  102. $(qemu)