OSDN Git Service

support GPT disks android-x86-4.4-r3
authorChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 7 May 2015 17:04:33 +0000 (01:04 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 7 May 2015 17:04:33 +0000 (01:04 +0800)
* allow to create GPT partitions
* allow to install to a GPT partition
* allow to install grub2-efi to the ESP partition

Based on the nice work of hatharry <hatharry@gmail.com>.

Android.mk
boot/efi/boot/grub.cfg
install/bin/cgdisk [new file with mode: 0755]
install/grub2/efi/boot/bootia32.efi [moved from boot/efi/boot/bootia32.efi with 100% similarity]
install/grub2/efi/boot/bootx64.efi [moved from boot/efi/boot/bootx64.efi with 100% similarity]
install/lib/libgcc_s.so.1 [new file with mode: 0644]
install/lib/libstdc++.so.6 [new file with mode: 0644]
install/lib/libuuid.so.1
install/scripts/1-install

index 790c2e4..ccf82ac 100644 (file)
@@ -75,7 +75,7 @@ $(INITRD_RAMDISK): $(initrd_bin) $(systemimg) $(TARGET_INITRD_SCRIPTS) | $(ACP)
        $(MKBOOTFS) $(TARGET_INSTALLER_OUT) | gzip -9 > $@
 
 INSTALL_RAMDISK := $(PRODUCT_OUT)/install.img
-$(INSTALL_RAMDISK): $(wildcard $(LOCAL_PATH)/install/*/*) | $(MKBOOTFS)
+$(INSTALL_RAMDISK): $(wildcard $(LOCAL_PATH)/install/*/* $(LOCAL_PATH)/install/*/*/*/*) | $(MKBOOTFS)
        $(if $(TARGET_INSTALL_SCRIPTS),$(ACP) -p $(TARGET_INSTALL_SCRIPTS) $(TARGET_INSTALLER_OUT)/scripts)
        $(MKBOOTFS) $(dir $(dir $(<D))) | gzip -9 > $@
 
@@ -109,7 +109,7 @@ $(EFI_IMAGE): $(wildcard $(LOCAL_PATH)/boot/efi/*/*) $(BUILT_IMG) $(ESP_LAYOUT)
         done; \
        size=$$(($$(($$(($$(($$(($$size + $$(($$size / 100)))) - 1)) / 32)) + 1)) * 32)); \
        rm -f $@.fat; mkdosfs -n Android-x86 -C $@.fat $$size
-       $(hide) mcopy -Qsi $@.fat $(dir $(<D)) $(BUILT_IMG) ::
+       $(hide) mcopy -Qsi $@.fat $(<D)/../../../install/grub2/efi $(BUILT_IMG) ::
        $(hide) mcopy -Qoi $@.fat $(@D)/grub.cfg ::efi/boot
        $(hide) cat /dev/null > $@; $(edit_mbr) -l $(ESP_LAYOUT) -i $@ esp=$@.fat
        $(hide) rm -f $@.fat
index 5b5d855..8d98b97 100644 (file)
@@ -1,18 +1,18 @@
 menuentry 'Android-x86 VER Live' --class android-x86 {
        search --file --no-floppy --set=root /system.sfs
-       linuxefi /kernel CMDLINE sdhci.debug_quirks=0x8000 quiet DATA=
+       linuxefi /kernel CMDLINE quiet DATA=
        initrdefi /initrd.img
 }
 
 menuentry 'Android-x86 VER DEBUG mode' --class android-x86 {
        search --file --no-floppy --set=root /system.sfs
-       linuxefi /kernel CMDLINE sdhci.debug_quirks=0x8000 DATA= DEBUG=2
+       linuxefi /kernel CMDLINE DATA= DEBUG=2
        initrdefi /initrd.img
 }
 
 menuentry 'Android-x86 VER Installation' --class android-x86 {
        search --file --no-floppy --set=root /system.sfs
-       linuxefi /kernel CMDLINE sdhci.debug_quirks=0x8000 DEBUG= INSTALL=1
+       linuxefi /kernel CMDLINE DEBUG= INSTALL=1
        initrdefi /initrd.img
 }
 
diff --git a/install/bin/cgdisk b/install/bin/cgdisk
new file mode 100755 (executable)
index 0000000..97d2512
Binary files /dev/null and b/install/bin/cgdisk differ
diff --git a/install/lib/libgcc_s.so.1 b/install/lib/libgcc_s.so.1
new file mode 100644 (file)
index 0000000..5d13c56
Binary files /dev/null and b/install/lib/libgcc_s.so.1 differ
diff --git a/install/lib/libstdc++.so.6 b/install/lib/libstdc++.so.6
new file mode 100644 (file)
index 0000000..72b5560
Binary files /dev/null and b/install/lib/libstdc++.so.6 differ
index 64a0302..f7862df 100644 (file)
Binary files a/install/lib/libuuid.so.1 and b/install/lib/libuuid.so.1 differ
index b2e7edf..fd68e1c 100644 (file)
@@ -60,7 +60,12 @@ partition_drive()
                choose "Choose Drive" "Please select a drive to edit partitions:"
        fi
        if [ $retval -eq 0 ]; then
-               cfdisk /dev/$choice
+               dialog --title " Confirm " --defaultno --yesno "\n Do you want to use GPT?" 7 29
+               if [ $? -eq 0 ]; then
+                       cgdisk /dev/$choice
+               else
+                       cfdisk /dev/$choice
+               fi
                if [ $? -eq 0 ]; then
                        retval=1
                else
@@ -72,12 +77,31 @@ partition_drive()
 
 select_dev()
 {
-       fdisk -l | grep ^/dev | cut -b6-12,55- | awk '{
-               if (!match($2, "Extended")) {
-                       printf("\"%-28s", $0)
-                       system("echo -n `cat /sys/block/*/"$1"/../device/model`")
-                       printf("\" \"\"\n")
-               }
+       blkid | grep -v -E "^/dev/block/|^/dev/loop" | cut -b6- | sort | awk '{
+               t="unknown"
+               for (i = NF; i > 1; --i)
+                       if (match($i, "^TYPE")) {
+                               t=$i
+                               break
+                       }
+               gsub(/TYPE=|"/, "", t)
+               printf("%s\t%s\n", $1, t)
+       }' > $tempfile
+
+       lsblk=`ls /sys/block | grep -v -E "loop|ram|sr|boot|rpmb"`
+       for d in $lsblk; do
+               p=0
+               for i in /sys/block/$d/$d* /sys/block/$d; do
+                       [ -e $i/partition ] && p=1
+                       [ $p -eq 1 -a "$i" = "/sys/block/$d" ] && break
+                       echo $i | grep -q -E "boot|rpmb" && continue
+                       [ -d $i ] && ( grep "`basename $i:`" $tempfile || echo "`basename $i` unknown" )
+               done
+       done | awk '{
+               sub(/:/, "", $1)
+               printf("\"%-13s%-17s", $1, $2)
+               system("cd /sys/block; for f in "$1"/device/model "$1"/device/name */"$1"/../device/model */"$1"/../device/name; do [ -e $f ] && echo -n `cat $f` && break; done")
+               printf("\" \"\"\n")
        } END {
                printf("\"Create/Modify partitions\" \"\"\n\"Detect devices\" \"\"")
        }' > $menufile
@@ -112,7 +136,7 @@ format_fs()
                        ;;
        esac
        if [ -n "$cmd" ]; then
-               dialog --title " Confirm " --no-label Skip --yesno \
+               dialog --title " Confirm " --defaultno --yesno \
                        "\n You chose to format $1 to $choice.\n All data in that partition will LOSE.\n\n Are you sure to format the partition $1?" 10 51
                [ $? -ne 0 ] && return 1
                $cmd Android-x86 /dev/$1 | awk '{
@@ -135,7 +159,6 @@ create_menulst()
        menulst=/hd/grub/menu.lst
        [ -n "$VESA" ] && vga=" vga=788 modeset=0"
        echo -e "${GRUB_OPTIONS:-default=0\ntimeout=6\nsplashimage=/grub/android-x86.xpm.gz\n}root (hd0,$1)\n" > $menulst
-       cmdline=`cat /proc/cmdline | sed "s|\(initrd.*img\s*\)||; s|quiet\s*||; s|\(vga=\w\+\?\s*\)||; s|\(DPI=\w\+\?\s*\)||; s|\(INSTALL=\w\+\?\s*\)||; s|\(SRC=\S\+\?\s*\)||; s|\(DEBUG=\w\+\?\s*\)||; s|\(BOOT_IMAGE.*\)||"`
 
        create_entry "Android-x86 $VER" quiet $cmdline
        create_entry "Android-x86 $VER (Debug mode)" $cmdline DEBUG=2
@@ -211,6 +234,20 @@ try_upgrade()
        done
 }
 
+get_part_info()
+{
+       d=0
+       while [ 1 ]; do
+               h=`echo $d | awk '{ printf("%c", $1+97) }'`
+               for part in /sys/block/[shv]d$h/$1 /sys/block/mmcblk$d/$1; do
+                       [ -d $part ] && break 2
+               done
+               d=$(($d+1))
+       done
+       p=`cat $part/partition`
+       disk=$(basename `dirname $part`)
+}
+
 install_to()
 {
        cd /
@@ -224,20 +261,15 @@ install_to()
        done
 
        fs=`cat /proc/mounts | grep /dev/$1 | awk '{ print $3 }'`
+       cmdline=`sed "s|\(initrd.*img\s*\)||; s|quiet\s*||; s|\(vga=\w\+\?\s*\)||; s|\(DPI=\w\+\?\s*\)||; s|\(INSTALL=\w\+\?\s*\)||; s|\(SRC=\S\+\?\s*\)||; s|\(DEBUG=\w\+\?\s*\)||; s|\(BOOT_IMAGE=\S\+\?\s*\)||" /proc/cmdline`
 
        asrc=android-$VER
        dialog --title " Confirm " --no-label Skip --defaultno --yesno \
                "\n Do you want to install boot loader GRUB?" 7 47
        if [ $? -eq 0 ]; then
                cp -af /grub /hd
-               d=0
-               while [ 1 ]; do
-                       h=`echo $d | awk '{ printf("%c", $1+97) }'`
-                       [ -d /sys/block/[shv]d$h/$1 ] && break
-                       d=$(($d+1))
-               done
-               p=$((`echo $1 | cut -b4-`-1))
-               disk=`echo $1 | cut -b-3`
+               get_part_info $1
+               p=$(($p-1))
                create_menulst $p
                create_winitem $1 $d
                rm -f /hd/boot/grub/stage1
@@ -246,6 +278,31 @@ install_to()
                [ $? -ne 0 ] && return 255
        fi
 
+       dialog --title " Confirm " --no-label Skip --defaultno --yesno \
+               "\n Do you want to install EFI GRUB2?" 7 39
+       if [ $? -eq 0 ]; then
+               get_part_info $1
+               for i in /sys/block/$disk/$disk*; do
+                       [ 0`cat $i/partition` -eq 1 ] && break
+               done
+               boot=`basename $i`
+               mountpoint -q /hd && umount /hd
+               dialog --title " Confirm " --defaultno --yesno \
+                       "\n Do you want to format the boot partition\n /dev/$boot?" 8 45
+               [ $? -eq 0 ] && mkdosfs -n EFI /dev/$boot
+               try_mount rw /dev/$boot /hd
+               cp -af /grub2/efi /hd
+               grubcfg=/hd/efi/boot/grub.cfg
+               echo -e "set timeout=6" > $grubcfg
+               echo -e "menuentry \"Android-x86 $VER\" {\n\tsearch --set=root --file /$asrc/kernel\n\tlinuxefi /$asrc/kernel quiet $cmdline \n\tinitrdefi /$asrc/initrd.img\n}" >> $grubcfg
+               echo -e "menuentry \"Android-x86 $VER (DEBUG mode)\" {\n\tsearch --set=root --file /$asrc/kernel\n\tlinuxefi /$asrc/kernel $cmdline DEBUG=2\n\tinitrdefi /$asrc/initrd.img\n}" >> $grubcfg
+               if [ -e /hd/EFI/Microsoft/Boot/bootmgfw.efi ]; then
+                       echo -e "menuentry \"Windows (UEFI)\" {\n\tsearch --set=root --file /EFI/Microsoft/Boot/bootmgfw.efi\n\tchainloader /EFI/Microsoft/Boot/bootmgfw.efi\n}" >> $grubcfg
+               fi
+               mountpoint -q /hd && umount /hd
+               try_mount rw /dev/$1 /hd
+       fi
+
        dialog --title " Question " --yesno \
                "\nDo you want to install /system directory as read-write?\n\nMaking /system be read-write is easier for debugging, but it needs more disk space and longer installation time." 10 61
        instal_rw=$?
@@ -274,11 +331,13 @@ install_to()
        result=$((`cat /tmp/result`*255))
 
        if [ $result -eq 0 ]; then
-               chmod 644 *
-               chown 0.0 *
                for d in android mnt sfs ./$SRC; do
                        [ -d $d ] && mv $d/* . && rmdir $d
                done
+               chown 0.0 *
+               for f in *; do
+                       [ -d $f ] || chmod 644 $f
+               done
 
                case "$fs" in
                        vfat|fuseblk)
@@ -290,6 +349,7 @@ install_to()
                esac
        fi
 
+       dialog --infobox "\n Syncing to disk..." 5 27
        sync
 
        return $result