2 # Copyright (C) 2006-2012 OpenWrt.org
3 # Copyright (C) 2019 Alexander Couzens <lynxis@fe80.eu>
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
8 include $(TOPDIR
)/rules.mk
9 include $(INCLUDE_DIR
)/image.mk
11 export PATH
=$(TARGET_PATH
):/sbin
13 GRUB2_MODULES
= biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial
test vga
14 GRUB2_MODULES_ISO
= biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial
test vga
17 GRUB_TERMINAL_CONFIG
=
18 GRUB_CONSOLE_CMDLINE
=
20 USE_ATKBD
= generic
64
22 ifneq ($(strip $(foreach subtarget
,$(USE_ATKBD
),$(CONFIG_TARGET_x86_
$(subtarget
)))),)
23 GRUB2_MODULES
+= at_keyboard
24 GRUB2_MODULES_ISO
+= at_keyboard
27 ifneq ($(CONFIG_GRUB_CONSOLE
),)
28 GRUB_CONSOLE_CMDLINE
+= console
=tty0
29 GRUB_TERMINALS
+= console
32 GRUB_SERIAL
:=$(call qstrip
,$(CONFIG_GRUB_SERIAL
))
34 ifneq ($(GRUB_SERIAL
),)
35 GRUB_CONSOLE_CMDLINE
+= console
=$(GRUB_SERIAL
),$(CONFIG_GRUB_BAUDRATE
)n8
$(if
$(CONFIG_GRUB_FLOWCONTROL
),r
,)
36 GRUB_SERIAL_CONFIG
:= serial
--unit
=0 --speed
=$(CONFIG_GRUB_BAUDRATE
) --word=8 --parity
=no
--stop
=1 --rtscts
=$(if
$(CONFIG_GRUB_FLOWCONTROL
),on
,off
)
37 GRUB_TERMINALS
+= serial
40 ifneq ($(GRUB_TERMINALS
),)
41 GRUB_TERMINAL_CONFIG
:= terminal_input
$(GRUB_TERMINALS
); terminal_output
$(GRUB_TERMINALS
)
44 SIGNATURE
:=$(shell perl
-e
'printf("%08x", rand(0xFFFFFFFF))')
45 ROOTPART
:=$(call qstrip
,$(CONFIG_TARGET_ROOTFS_PARTNAME
))
46 ROOTPART
:=$(if
$(ROOTPART
),$(ROOTPART
),PARTUUID
=$(SIGNATURE
)-02)
48 GRUB_TIMEOUT
:=$(call qstrip
,$(CONFIG_GRUB_TIMEOUT
))
49 GRUB_TITLE
:=$(call qstrip
,$(CONFIG_GRUB_TITLE
))
51 # Convert a raw image into a $1 type image.
52 # E.g. | qemu-image vdi
53 define Build
/qemu-image
54 qemu-img convert
-f raw
-O
$1 \
61 -rm -rf
"$@.grubpc" "$@.root.grub"
62 $(INSTALL_DIR
) $@.root.grub
/boot
/grub
$@.grubpc
63 $(CP
) $(IMAGE_KERNEL
) $@.root.grub
/boot
/vmlinuz
66 -d
$(STAGING_DIR_HOST
)/lib
/grub
/i386-pc \
67 -o
$@.grubpc
/core.img \
71 $(CP
) $(STAGING_DIR_HOST
)/lib
/grub
/i386-pc
/*.img
$@.grubpc
/
72 echo
'(hd0) $@' > $@.grubpc
/device.map
74 -e
's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
75 -e
's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
76 -e
's#@CMDLINE@#$(strip $(call Image/cmdline/$(FILESYSTEM)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
77 -e
's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
78 -e
's#@TITLE@#$(GRUB_TITLE)#g' \
79 .
/grub.cfg
> $@.root.grub
/boot
/grub
/grub.cfg
80 -$(CP
) $(STAGING_DIR_ROOT
)/boot
/.
$@.root.grub
/boot
/
81 PADDING
="1" SIGNATURE
="$(SIGNATURE)" PATH
="$(TARGET_PATH)" $(SCRIPT_DIR
)/gen_image_generic.sh \
83 $(CONFIG_TARGET_KERNEL_PARTSIZE
) $@.root.grub \
84 $(CONFIG_TARGET_ROOTFS_PARTSIZE
) $(IMAGE_ROOTFS
) \
87 --device-map
="$@.grubpc/device.map" \
91 rm -rf
"$@.grubpc" "$@.root.grub"
94 ifneq ($(CONFIG_GRUB_IMAGES
),)
95 BOOTOPTS
:=$(call qstrip
,$(CONFIG_GRUB_BOOTOPTS
))
97 define Image
/cmdline
/ext4
98 root
=$(ROOTPART
) rootfstype
=ext4 rootwait
101 define Image
/cmdline
/squashfs
102 root
=$(ROOTPART
) rootfstype
=squashfs rootwait
107 -rm -rf
"$@.root.grub/boot/grub" "$@.grubiso"
108 $(INSTALL_DIR
) $@.root.grub
/boot
/grub
$@.grubiso
109 $(CP
) $(IMAGE_KERNEL
) $@.root.grub
/boot
/vmlinuz
112 -d
$(STAGING_DIR_HOST
)/lib
/grub
/i386-pc \
113 -o
$@.grub2
/eltorito.img \
115 -c .
/grub-early.cfg \
118 $(STAGING_DIR_HOST
)/lib
/grub
/i386-pc
/cdboot.img \
119 $@.grub2
/eltorito.img \
120 > $@.root.grub
/boot
/grub
/eltorito.img
122 -e
's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
123 -e
's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
124 -e
's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(FILESYSTEM)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
125 -e
's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
126 -e
's#@TITLE@#$(GRUB_TITLE)#g' \
127 .
/grub-iso.cfg
> $@.root.grub
/boot
/grub
/grub.cfg
128 -$(CP
) $(STAGING_DIR_ROOT
)/boot
/.
$@.root.grub
/boot
/
129 mkisofs
-R
-b boot
/grub
/eltorito.img
-no-emul-boot
-boot-info-table \
130 -o
$@
$@.root.grub
$(TARGET_DIR
)
131 rm -rf
"$@.root.grub/boot/grub" "$@.grubiso"
134 define Device
/generic
136 DEVICE_TITLE
:= Generic
(ext4
/squashfs
)
138 IMAGES
:= vdi.gz vmdk.gz raw.img.gz
139 IMAGE
/vdi.gz
:= grubpc | qemu-image vdi | gzip
140 IMAGE
/vmdk.gz
:= grubpc | qemu-image vmdk | gzip
141 IMAGE
/raw.img.gz
:= grubpc | gzip
142 FILESYSTEMS
:= squashfs ext4
145 TARGET_DEVICES
+= generic
147 define Device
/generic-iso
149 DEVICE_TITLE
:= Generic
(iso
)
152 IMAGE
/iso.gz
:= grubiso | append-metadata | gzip
156 TARGET_DEVICES
+= generic-iso
158 ifeq ($(SUBTARGET
),geode
)
164 IMAGE
/iso.gz
:= grubiso | append-metadata | gzip
166 DEVICE_PACKAGES
:= soloscli linux-atm br2684ctl ppp-mod-pppoa pppdump pppstats \
167 hwclock flashrom tc kmod-pppoa kmod-8139cp kmod-mppe \
168 kmod-usb-ohci-pci kmod-hwmon-lm90
170 TARGET_DEVICES
+= geos
174 $(eval
$(call BuildImage
))