1 ## Copyright 2008, The Android Open Source Project 2 ## 3 ## Licensed under the Apache License, Version 2.0 (the "License"); 4 ## you may not use this file except in compliance with the License. 5 ## You may obtain a copy of the License at 6 ## 7 ## http://www.apache.org/licenses/LICENSE-2.0 8 ## 9 ## Unless required by applicable law or agreed to in writing, software 10 ## distributed under the License is distributed on an "AS IS" BASIS, 11 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 ## See the License for the specific language governing permissions and 13 ## limitations under the License. 14 ## 15 16 17 LOCAL_PATH := $(call my-dir) 18 19 ifeq ($(TARGET_ARCH),x86) 20 21 include $(CLEAR_VARS) 22 23 ############################ 24 # First, build stage1 25 26 LOCAL_SRC_FILES := \ 27 stage1/stage1.S 28 29 LOCAL_CFLAGS := \ 30 -Wall -Wmissing-prototypes -Wunused -Wshadow \ 31 -Wpointer-arith -falign-jumps=1 -falign-loops=1 \ 32 -falign-functions=1 -Wundef 33 LOCAL_CFLAGS += -m32 -O2 -fno-builtin -nostdinc -fno-reorder-functions -fno-stack-protector 34 35 LOCAL_C_INCLUDES := $(LOCAL_PATH)/stage1 36 37 LOCAL_MODULE := grub_stage1 38 LOCAL_MODULE_TAGS := eng 39 LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub 40 41 LOCAL_SYSTEM_SHARED_LIBRARIES := 42 LOCAL_SHARED_LIBRARIES := 43 44 include $(BUILD_RAW_EXECUTABLE) 45 46 $(LOCAL_BUILT_MODULE) : PRIVATE_LINK_SCRIPT := 47 $(LOCAL_BUILT_MODULE) : PRIVATE_LIBS := 48 $(LOCAL_BUILT_MODULE) : PRIVATE_RAW_EXECUTABLE_LDFLAGS := \ 49 -nostdlib -N -Ttext=0x7C00 -melf_i386 50 51 ################################################################### 52 ################################################################### 53 ## For stage2, we have to do it in several parts. 54 ## 1) Build pre_stage2 that contains all the source. 55 ## 2) Get the size of pre_stage2 from (1) and generate a header file. 56 ## 3) Build the "start sector" with the header file. 57 ## 4) concatenate start + pre_stage2 into stage2. 58 ################################################################### 59 ################################################################### 60 61 ################################### 62 ## So, build pre_stage2 target (1) 63 64 include $(CLEAR_VARS) 65 66 LOCAL_SRC_FILES := \ 67 stage2/asm.S \ 68 stage2/bios.c \ 69 stage2/boot.c \ 70 stage2/builtins.c \ 71 stage2/char_io.c \ 72 stage2/cmdline.c \ 73 stage2/common.c \ 74 stage2/console.c \ 75 stage2/disk_io.c \ 76 stage2/fsys_ext2fs.c \ 77 stage2/gunzip.c \ 78 stage2/serial.c \ 79 stage2/smp-imps.c \ 80 stage2/stage2.c \ 81 stage2/terminfo.c \ 82 stage2/tparm.c \ 83 stage2/preset_menu.c 84 85 LOCAL_CFLAGS := \ 86 -Wall -Wmissing-prototypes -Wunused -Wshadow \ 87 -Wpointer-arith -falign-jumps=1 -falign-loops=1 \ 88 -falign-functions=1 -Wundef 89 90 LOCAL_CFLAGS += -m32 -Os -fno-builtin -nostdinc -fno-reorder-functions -fno-stack-protector 91 92 LOCAL_CFLAGS += -DHAVE_CONFIG_H -DFSYS_EXT2FS=1 -DSUPPORT_SERIAL=1 93 94 LOCAL_CFLAGS += -DPRESET_MENU_EXTERNAL 95 96 LOCAL_C_INCLUDES := \ 97 $(LOCAL_PATH)/stage1 \ 98 $(LOCAL_PATH)/stage2 99 100 LOCAL_MODULE := grub_pre_stage2 101 LOCAL_MODULE_TAGS := eng 102 LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub 103 104 LOCAL_SYSTEM_SHARED_LIBRARIES := 105 LOCAL_SHARED_LIBRARIES := 106 107 include $(BUILD_RAW_EXECUTABLE) 108 109 $(LOCAL_BUILT_MODULE) : PRIVATE_LINK_SCRIPT := 110 $(LOCAL_BUILT_MODULE) : PRIVATE_LIBS := 111 $(LOCAL_BUILT_MODULE) : PRIVATE_RAW_EXECUTABLE_LDFLAGS := \ 112 -nostdlib -N -Ttext=0x8200 -melf_i386 113 114 ############################################# 115 ## Generate the stage2 start file (2) + (3) 116 117 include $(CLEAR_VARS) 118 119 LOCAL_SRC_FILES := \ 120 stage2/start.S 121 122 LOCAL_CFLAGS := \ 123 -Wall -Wmissing-prototypes -Wunused -Wshadow \ 124 -Wpointer-arith -falign-jumps=1 -falign-loops=1 \ 125 -falign-functions=1 -Wundef 126 127 LOCAL_CFLAGS += -m32 -Os -fno-builtin -nostdinc -fno-reorder-functions -fno-stack-protector 128 129 LOCAL_CFLAGS += -DHAVE_CONFIG_H -DFSYS_EXT2FS=1 -DSUPPORT_SERIAL=1 130 131 LOCAL_C_INCLUDES := \ 132 $(LOCAL_PATH)/stage1 \ 133 $(LOCAL_PATH)/stage2 134 135 LOCAL_SYSTEM_SHARED_LIBRARIES := 136 LOCAL_SHARED_LIBRARIES := 137 138 LOCAL_MODULE := grub_start_stage2 139 LOCAL_MODULE_TAGS := eng 140 LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub 141 142 # <generate the header file> 143 LOCAL_MODULE_CLASS := EXECUTABLES 144 intermediates := $(call local-intermediates-dir) 145 146 STAGE2_SIZE_OBJ := $(intermediates)/stage2_size.h 147 $(STAGE2_SIZE_OBJ) : PRIVATE_CUSTOM_TOOL = \ 148 echo "\#define STAGE2_SIZE `stat -c '%s' $<`" > $@ 149 150 LOCAL_GENERATED_SOURCES := $(STAGE2_SIZE_OBJ) 151 $(STAGE2_SIZE_OBJ): $(PRODUCT_OUT)/grub/grub_pre_stage2 152 @echo "target Generating: $@" 153 $(transform-generated-source) 154 # </generate the header file> 155 156 include $(BUILD_RAW_EXECUTABLE) 157 158 $(all_objects): $(STAGE2_SIZE_OBJ) 159 $(LOCAL_BUILT_MODULE) : PRIVATE_LINK_SCRIPT := 160 $(LOCAL_BUILT_MODULE) : PRIVATE_LIBS := 161 $(LOCAL_BUILT_MODULE) : PRIVATE_RAW_EXECUTABLE_LDFLAGS := \ 162 -nostdlib -N -Ttext=0x8200 -melf_i386 163 164 ############################################# 165 ## Generate the real deal stage2 (4) 166 167 include $(CLEAR_VARS) 168 169 my_files := $(PRODUCT_OUT)/grub/grub_start_stage2 \ 170 $(PRODUCT_OUT)/grub/grub_pre_stage2 171 172 file := $(PRODUCT_OUT)/grub/grub_stage2 173 $(file) : $(my_files) 174 @echo "target Creating: $@" 175 $(hide) cat $^ > $@ 176 #ALL_PREBUILT += $(file) 177 178 179 ############################################################################# 180 ## Generate a full stage1+stage2 bin that we can just drop @ offset 0 on disk 181 include $(CLEAR_VARS) 182 grub_stage1 := $(PRODUCT_OUT)/grub/grub_stage1 183 grub_stage2 := $(PRODUCT_OUT)/grub/grub_stage2 184 grub_full := $(PRODUCT_OUT)/grub/grub.bin 185 186 $(grub_full) : $(grub_stage1) $(grub_stage2) 187 @echo "target Generating GRUB bin: $@" 188 $(hide) rm -f $@ 189 $(hide) dd if=$(grub_stage1) of=$@ bs=512 count=1 2>/dev/null 190 $(hide) dd if=$(grub_stage2) of=$@ bs=512 seek=1 2>/dev/null 191 #ALL_PREBUILT += $(grub_full) 192 193 endif # x86 194