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 17LOCAL_PATH := $(call my-dir) 18 19ifeq ($(TARGET_ARCH),x86) 20 21include $(CLEAR_VARS) 22 23############################ 24# First, build stage1 25 26LOCAL_SRC_FILES := \ 27 stage1/stage1.S 28 29LOCAL_CFLAGS := \ 30 -Wall -Wmissing-prototypes -Wunused -Wshadow \ 31 -Wpointer-arith -falign-jumps=1 -falign-loops=1 \ 32 -falign-functions=1 -Wundef 33LOCAL_CFLAGS += -m32 -O2 -fno-builtin -nostdinc 34 35LOCAL_C_INCLUDES := $(LOCAL_PATH)/stage1 36 37LOCAL_MODULE := grub_stage1 38LOCAL_MODULE_TAGS := eng 39LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub 40 41LOCAL_SYSTEM_SHARED_LIBRARIES := 42LOCAL_SHARED_LIBRARIES := 43 44include $(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=7C00 -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 64include $(CLEAR_VARS) 65 66LOCAL_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 85LOCAL_CFLAGS := \ 86 -Wall -Wmissing-prototypes -Wunused -Wshadow \ 87 -Wpointer-arith -falign-jumps=1 -falign-loops=1 \ 88 -falign-functions=1 -Wundef 89 90LOCAL_CFLAGS += -m32 -Os -fno-builtin -nostdinc 91 92LOCAL_CFLAGS += -DHAVE_CONFIG_H -DFSYS_EXT2FS=1 -DSUPPORT_SERIAL=1 93 94LOCAL_CFLAGS += -DPRESET_MENU_EXTERNAL 95 96LOCAL_C_INCLUDES := \ 97 $(LOCAL_PATH)/stage1 \ 98 $(LOCAL_PATH)/stage2 99 100LOCAL_MODULE := grub_pre_stage2 101LOCAL_MODULE_TAGS := eng 102LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub 103 104LOCAL_SYSTEM_SHARED_LIBRARIES := 105LOCAL_SHARED_LIBRARIES := 106 107include $(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=8200 -melf_i386 113 114############################################# 115## Generate the stage2 start file (2) + (3) 116 117include $(CLEAR_VARS) 118 119LOCAL_SRC_FILES := \ 120 stage2/start.S 121 122LOCAL_CFLAGS := \ 123 -Wall -Wmissing-prototypes -Wunused -Wshadow \ 124 -Wpointer-arith -falign-jumps=1 -falign-loops=1 \ 125 -falign-functions=1 -Wundef 126 127LOCAL_CFLAGS += -m32 -Os -fno-builtin -nostdinc 128 129LOCAL_CFLAGS += -DHAVE_CONFIG_H -DFSYS_EXT2FS=1 -DSUPPORT_SERIAL=1 130 131LOCAL_C_INCLUDES := \ 132 $(LOCAL_PATH)/stage1 \ 133 $(LOCAL_PATH)/stage2 134 135LOCAL_SYSTEM_SHARED_LIBRARIES := 136LOCAL_SHARED_LIBRARIES := 137 138LOCAL_MODULE := grub_start_stage2 139LOCAL_MODULE_TAGS := eng 140LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub 141 142# <generate the header file> 143LOCAL_MODULE_CLASS := EXECUTABLES 144intermediates := $(call local-intermediates-dir) 145 146STAGE2_SIZE_OBJ := $(intermediates)/stage2_size.h 147$(STAGE2_SIZE_OBJ) : PRIVATE_CUSTOM_TOOL = \ 148 echo "\#define STAGE2_SIZE `stat -c '%s' $<`" > $@ 149 150LOCAL_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 156include $(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=8200 -melf_i386 163 164############################################# 165## Generate the real deal stage2 (4) 166 167include $(CLEAR_VARS) 168 169my_files := $(PRODUCT_OUT)/grub/grub_start_stage2 \ 170 $(PRODUCT_OUT)/grub/grub_pre_stage2 171 172file := $(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 181include $(CLEAR_VARS) 182grub_stage1 := $(PRODUCT_OUT)/grub/grub_stage1 183grub_stage2 := $(PRODUCT_OUT)/grub/grub_stage2 184grub_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 193endif # x86 194