Makefile 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #
  2. # meg4/platform/raspberrypi/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 for Raspberry Pi
  21. #
  22. # ----- configure your MEG-4 OS image -----
  23. IMGSIZE?=256
  24. KBDMAP?=gb
  25. LANG?=en
  26. FLOPPYDEV?=/dev/mmcblk0p1
  27. # ----- end of configuration -----
  28. all: meg4.iso
  29. ### compile MEG-4 as an init process ###
  30. rootfs/init:
  31. USE_INIT=1 KBDMAP=$(KBDMAP) LANG=$(LANG) FLOPPYDEV=$(FLOPPYDEV) make --no-print-directory -C ../fbdev_alsa clean all
  32. @mkdir -p rootfs 2>/dev/null || true
  33. cp -f ../fbdev_alsa/meg4 rootfs/init
  34. strip rootfs/init
  35. ### get Raspberrypi firmware ###
  36. firmware.zip:
  37. wget -c https://github.com/raspberrypi/firmware/archive/refs/heads/master.zip -O firmware.zip
  38. boot/kernel8.img: firmware.zip
  39. unzip -uo firmware.zip 'firmware-master/boot/*' 'firmware-master/modules/*'
  40. @rm -rf boot rootfs/lib/modules 2>/dev/null || true
  41. mv firmware-master/boot boot
  42. @mkdir -p rootfs/lib 2>/dev/null || true
  43. mv firmware-master/modules rootfs/lib/modules
  44. @rm -rf firmware-master
  45. @# make sure the kernel's timestamp is newer than firmware.zip's
  46. @touch boot/kernel8.img
  47. ### create initial ramdisk ###
  48. boot/initrd: rootfs/init
  49. @mkdir rootfs/dev rootfs/mnt rootfs/proc rootfs/sys rootfs/tmp 2>/dev/null || true
  50. @chmod +x rootfs/init
  51. cd rootfs && find . | cpio -R root:root -H newc -o | gzip > ../boot/initrd
  52. ### construct disk image ###
  53. meg4.iso: boot/kernel8.img boot/initrd
  54. @printf "dtparam=audio=on\nenable_uart=1\nmax_framebuffers=2\narm_64bit=1\ninitramfs initrd followkernel" >boot/config.txt
  55. @printf "console=serial0,115200 init=/init quiet" >boot/cmdline.txt
  56. @mkdir -p boot/MEG-4 2>/dev/null || true
  57. @cp -r ../../public/floppies/* boot/MEG-4 || true
  58. dd if=/dev/zero of=meg4.iso count=$(IMGSIZE) bs=1048576
  59. printf "n\np\n1\n2048\n\nt 1\nc\na\nw\nq\n" | fdisk meg4.iso
  60. mkfs.vfat -F 32 -n "MEG-4 OS" --offset 2048 meg4.iso
  61. ifneq ($(wildcard /usr/bin/mcopy),)
  62. @# if mtools is installed, use that (available to all users)
  63. cd boot && mcopy -i ../meg4.iso@@1M -s * ::
  64. else
  65. @# use standard Linux tools otherwise (unfortunately requires root priviledge...)
  66. @mkdir mnt 2>/dev/null
  67. sudo mount -o loop,offset=1048576,user,umask=000 meg4.iso mnt
  68. cd boot && cp -r * ../mnt
  69. sudo umount mnt
  70. rm -rf mnt
  71. endif
  72. package: meg4.iso
  73. tar -czvf ../../meg4-rpi.iso.tgz meg4.iso
  74. clean:
  75. rm -rf rootfs boot firmware.zip meg4.iso 2>/dev/null || true