mirror of
https://github.com/FunKey-Project/FunKey-OS.git
synced 2025-12-12 15:48:51 +01:00
boot according to GPT bootable flags
Signed-off-by: Michel Stempin <michel.stempin@wanadoo.fr>
This commit is contained in:
parent
feab0199f7
commit
2d456ef6c7
@ -45,6 +45,7 @@ image sdcard.img {
|
|||||||
partition rootfs {
|
partition rootfs {
|
||||||
offset = 101M
|
offset = 101M
|
||||||
partition-type = 0x83
|
partition-type = 0x83
|
||||||
|
bootable = "yes"
|
||||||
image = "rootfs.ext4"
|
image = "rootfs.ext4"
|
||||||
size = 100M
|
size = 100M
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,14 @@
|
|||||||
alt_args_mmc=setenv bootargs console=ttyS0,115200 panic=5 rootwait fbcon=map:10 fbcon=font:VGA8x8 vt.global_cursor_default=0 root=/dev/mmcblk0p1 rootfstype=ext4 rootflags=commit=120,data=writeback,barrier=0,journal_async_commit rw quiet
|
args_mmc=setenv bootargs console=ttyS0,115200 panic=5 rootwait fbcon=map:10 fbcon=font:VGA8x8 vt.global_cursor_default=0 root=/dev/mmcblk0p${bootpart} rootfstype=ext4 rootflags=commit=120,data=writeback,barrier=0,journal_async_commit rw quiet
|
||||||
alt_bootcmd=run alt_args_mmc; run alt_loadfdt; run alt_loadimage; bootz ${loadaddr} - ${fdtaddr}
|
|
||||||
alt_loadfdt=load mmc 0:1 ${fdtaddr} /boot/sun8i-v3s-funkey.dtb
|
|
||||||
alt_loadimage=load mmc 0:1 ${loadaddr} /boot/zImage
|
|
||||||
args_mmc=setenv bootargs console=ttyS0,115200 panic=5 rootwait fbcon=map:10 fbcon=font:VGA8x8 vt.global_cursor_default=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=120,data=writeback,barrier=0,journal_async_commit rw quiet
|
|
||||||
baudrate=115200
|
baudrate=115200
|
||||||
bootcmd=run args_mmc; run loadfdt; run loadimage; bootz ${loadaddr} - ${fdtaddr}
|
bootcmd=run getbootpart; run args_mmc; run loadfdt; run loadimage; bootz ${loadaddr} - ${fdtaddr}
|
||||||
bootdelay=0
|
bootdelay=0
|
||||||
console=ttyS0,115200
|
console=ttyS0,115200
|
||||||
fdt_high=0xffffffff
|
fdt_high=0xffffffff
|
||||||
fdtaddr=0x41800000
|
fdtaddr=0x41800000
|
||||||
|
getbootpart=part list mmc 0 -bootable bootpart
|
||||||
loadaddr=0x41000000
|
loadaddr=0x41000000
|
||||||
loadfdt=load mmc 0:2 ${fdtaddr} /boot/sun8i-v3s-funkey.dtb
|
loadfdt=load mmc 0:${bootpart} ${fdtaddr} /boot/sun8i-v3s-funkey.dtb
|
||||||
loadimage=load mmc 0:2 ${loadaddr} /boot/zImage
|
loadimage=load mmc 0:${bootpart} ${loadaddr} /boot/zImage
|
||||||
stderr=serial@01c28000
|
stderr=serial@01c28000
|
||||||
stdin=serial@01c28000
|
stdin=serial@01c28000
|
||||||
stdout=serial@01c28000
|
stdout=serial@01c28000
|
||||||
|
|||||||
@ -6,10 +6,16 @@
|
|||||||
source /usr/local/lib/utils
|
source /usr/local/lib/utils
|
||||||
|
|
||||||
SELF=$(basename $0)
|
SELF=$(basename $0)
|
||||||
|
|
||||||
|
# Find out the root partition number from the kernel command line
|
||||||
root_part=$(cat /proc/cmdline | sed -n 's|^.*root=/dev/\([^ ]*\).*|\1|p')
|
root_part=$(cat /proc/cmdline | sed -n 's|^.*root=/dev/\([^ ]*\).*|\1|p')
|
||||||
part_num=${root_part#mmcblk0p}
|
root_part_num=${root_part#mmcblk0p}
|
||||||
if [ "${part_num}" -eq 1 ]; then
|
if [ "${root_part_num}" -eq 1 ]; then
|
||||||
die 0 "recovery mode"
|
die 0 "recovery mode"
|
||||||
|
elif [ "${root_part_num}" = "{$root_part}" ]; then
|
||||||
|
die 1 "${root_part} is not an SD card partition, aborting"
|
||||||
|
elif [ "${root_part_num}" -ne 2 ]; then
|
||||||
|
die 2 "unknown partition layout, aborting"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
notif () {
|
notif () {
|
||||||
@ -27,56 +33,47 @@ check_swap () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_root_id () {
|
check_root_id () {
|
||||||
[ $(id -u) -ne 0 ] && die 1 "this script must be run as root, aborting"
|
[ $(id -u) -ne 0 ] && die 3 "this script must be run as root, aborting"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
resize_rootfs_partition () {
|
resize_rootfs_partition () {
|
||||||
if [ "${part_num}" = "{$root_part}" ]; then
|
|
||||||
die 2 "${root_part} is not an SD card. Don't know how to expand it, aborting"
|
# Check that the last partition is the rootfs partition
|
||||||
fi
|
local last_part_line=$(sgdisk -p /dev/mmcblk0 | tail -n 1)
|
||||||
if [ "${part_num}" -ne 2 ]; then
|
|
||||||
die 3 "your partition layout is not currently supported by this tool, aborting"
|
|
||||||
fi
|
|
||||||
local last_part_line=$(fdisk /dev/mmcblk0 -l | grep '^/' | tail -n 1)
|
|
||||||
set ${last_part_line}
|
set ${last_part_line}
|
||||||
local last_part=${1#/dev/}
|
local last_part=${1}
|
||||||
local part_start=${2}
|
if [ "${last_part}" != "${root_part_num}" ]; then
|
||||||
if [ "${last_part}" != "${root_part}" ]; then
|
die 4 "rootfs is not the last partition. Don't know how to expand, aborting"
|
||||||
die 4 "${root_part} is not the last partition. Don't know how to expand, aborting"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Return value will likely be error for fdisk as it fails to reload the
|
# Remove (temporarily) the rootfs partition
|
||||||
# partition table because the root fs is mounted
|
sgdisk -d ${root_part_num} /dev/mmcblk0 >/dev/null 2>&1 || die 5 "cannot remove the rootfs partition, aborting"
|
||||||
# NOTE: This script only works the genuine fdisk, NOT with the busybox one!!!
|
|
||||||
fdisk /dev/mmcblk0 >/dev/null 2>&1 <<EOF
|
# Re-create the rootfs partition with a 1GB size
|
||||||
d
|
sgdisk -n ${root_part_num}:0:+1G -c ${root_part_num}:rootfs /dev/mmcblk0 >/dev/null 2>&1 || die 6 "cannot resize the rootfs partition, aborting"
|
||||||
${part_num}
|
|
||||||
n
|
# Mark the rootfs partition as bootable
|
||||||
${part_num}
|
sgdisk -A ${root_part_num}:set:2 /dev/mmcblk0 >/dev/null 2>&1 || die 7 "cannot make the rootfs partition bootable, aborting"
|
||||||
${part_start}
|
|
||||||
+1G
|
# Copy the primary GPT to the end of the disk
|
||||||
w
|
sgdisk -e /dev/mmcblk0 >/dev/null 2>&1 || die 8 "cannot move the GPT to the end of the disk"
|
||||||
EOF
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
die 5 "cannot resize the rootfs partition, aborting"
|
|
||||||
fi
|
|
||||||
sync
|
sync
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_partition_table () {
|
reload_partition_table () {
|
||||||
partprobe /dev/mmcblk0 >/dev/null 2>&1 || die 6 "cannot reload the partition table, aborting"
|
partprobe /dev/mmcblk0 >/dev/null 2>&1 || die 9 "cannot reload the partition table, aborting"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
resize_rootfs_filesystem () {
|
resize_rootfs_filesystem () {
|
||||||
resize2fs /dev/${root_part} >/dev/null 2>&1 || die 7 "cannot resize the root filesystem, aborting"
|
resize2fs /dev/${root_part} >/dev/null 2>&1 || die 10 "cannot resize the root filesystem, aborting"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
write_bootloader_env () {
|
write_bootloader_env () {
|
||||||
fw_saveenv /etc/u-boot.env || die 8 "cannot write bootloader inevrionment, aborting"
|
fw_saveenv /etc/u-boot.env || die 11 "cannot write bootloader inevrionment, aborting"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,20 +82,22 @@ create_swap_file () {
|
|||||||
set ${root_part_line}
|
set ${root_part_line}
|
||||||
local space_left=${4}
|
local space_left=${4}
|
||||||
if [ ${space_left} -lt 131072 ]; then
|
if [ ${space_left} -lt 131072 ]; then
|
||||||
die 9 "not enough free space for swap file found, aborting"
|
die 12 "not enough free space for swap file found, aborting"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Create an empty 128MB /swap file, change its permissions and format it as swap
|
||||||
dd if=/dev/zero of=/swap bs=1M count=128 >/dev/null 2>&1 &&
|
dd if=/dev/zero of=/swap bs=1M count=128 >/dev/null 2>&1 &&
|
||||||
chmod 0600 /swap >/dev/null 2>&1 &&
|
chmod 0600 /swap >/dev/null 2>&1 &&
|
||||||
mkswap /swap >/dev/null 2>&1
|
mkswap /swap >/dev/null 2>&1
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
rm /swap
|
rm /swap
|
||||||
die 10 "cannot create swap file, aborting"
|
die 13 "cannot create swap file, aborting"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
enable_swap_file () {
|
enable_swap_file () {
|
||||||
swapon -a >/dev/null 2>&1 || die 11 "cannot enable swap file, aborting"
|
swapon -a >/dev/null 2>&1 || die 14 "cannot enable swap file, aborting"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,37 +105,17 @@ create_backing_store_partition () {
|
|||||||
mount | grep -q /dev/mmcblk0p3
|
mount | grep -q /dev/mmcblk0p3
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
|
|
||||||
# Find out the root partition number from kernel command line
|
# Check that the last partition is the rootfs partition
|
||||||
if [ "$part_num" = "$root_part" ]; then
|
local last_part_line=$(sgdisk -p /dev/mmcblk0 2>/dev/null | tail -n 1)
|
||||||
die 5 "$root_part is not an SD card. Don't know how to create the backing store partition"
|
set ${last_part_line}
|
||||||
fi
|
local last_part=${1}
|
||||||
if [ "$part_num" -ne 2 ]; then
|
if [ "$last_part" != "$root_part_num" ]; then
|
||||||
die 6 "your partition layout is not currently supported"
|
die 15 "rootfs is not the last partition. Don't know how to create the backing store partition"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check that the last partition is the root partition
|
# Create an additional Microsoft basic data partition share partition that fills the disk
|
||||||
local last_part_line=$(fdisk /dev/mmcblk0 -l 2>/dev/null | grep '^/' | tail -n 1)
|
let share_part=${last_part}+1
|
||||||
set $last_part_line
|
sgdisk -n ${share_part}:0:-0 -c ${share_part}:share -t ${share_part}:0700 /dev/mmcblk0 >/dev/null 2>&1 || die 16 "cannot create the backing store partition, aborting"
|
||||||
local last_part=${1#/dev/}
|
|
||||||
if [ "$last_part" != "$root_part" ]; then
|
|
||||||
die 7 "$root_part is not the last partition. Don't know how to create the backing store partition"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The return value will likely be error for fdisk as it fails
|
|
||||||
# to reload the partition table because the root fs is mounted
|
|
||||||
# NOTE: This script only works the genuine fdisk, NOT with the
|
|
||||||
# busybox one!!!
|
|
||||||
# Create a third FAT32 partition that filsl the disk
|
|
||||||
fdisk /dev/mmcblk0 >/dev/null 2>&1 <<EOF
|
|
||||||
n
|
|
||||||
3
|
|
||||||
|
|
||||||
|
|
||||||
t
|
|
||||||
3
|
|
||||||
11
|
|
||||||
w
|
|
||||||
EOF
|
|
||||||
sync
|
sync
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
@ -145,12 +124,12 @@ EOF
|
|||||||
format_backing_store_partition () {
|
format_backing_store_partition () {
|
||||||
|
|
||||||
# Format the backing store as FAT32
|
# Format the backing store as FAT32
|
||||||
mkfs.vfat /dev/mmcblk0p3 >/dev/null 2>&1 || die 9 "cannot format the backing store partition"
|
mkfs.vfat /dev/mmcblk0p3 >/dev/null 2>&1 || die 17 "cannot format the backing store partition"
|
||||||
|
|
||||||
# Add file to force assembly tests
|
# Add file to force assembly tests
|
||||||
mount /mnt/ || die 9 "Cannot mount /mnt"
|
mount /mnt/ || die 18 "Cannot mount /mnt"
|
||||||
touch /mnt/.assembly_tests || die 9 "Cannot create assembly tests run file"
|
#touch /mnt/.assembly_tests || die 19 "Cannot create assembly tests run file"
|
||||||
umount /mnt/ || die 9 "Cannot unmount /mnt"
|
umount /mnt/ || die 20 "Cannot unmount /mnt"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/toggle_boot
Executable file
8
FunKey/board/funkey/rootfs-overlay/usr/local/sbin/toggle_boot
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
sgdisk -A 1:toggle:2 -A 2:toggle:2 /dev/mmcblk0 >/dev/null 2>&1
|
||||||
|
recovery=$(sgdisk -A 1:get:2 /dev/mmcblk0 | cut -d : -f3)
|
||||||
|
if [ ${recovery} -eq 1 ]; then
|
||||||
|
echo "Next boot will be in recovery mode"
|
||||||
|
else
|
||||||
|
echo "Next boot will be in normal mode"
|
||||||
|
fi
|
||||||
@ -58,6 +58,9 @@ BR2_PACKAGE_SDL_IMAGE_JPEG=y
|
|||||||
BR2_PACKAGE_SDL_IMAGE_PNG=y
|
BR2_PACKAGE_SDL_IMAGE_PNG=y
|
||||||
BR2_PACKAGE_SDL_SOUND=y
|
BR2_PACKAGE_SDL_SOUND=y
|
||||||
BR2_PACKAGE_SDL_SOUND_PLAYSOUND=y
|
BR2_PACKAGE_SDL_SOUND_PLAYSOUND=y
|
||||||
|
BR2_PACKAGE_GPTFDISK=y
|
||||||
|
BR2_PACKAGE_GPTFDISK_GDISK=y
|
||||||
|
BR2_PACKAGE_GPTFDISK_SGDISK=y
|
||||||
BR2_PACKAGE_PARTED=y
|
BR2_PACKAGE_PARTED=y
|
||||||
BR2_PACKAGE_SYSSTAT=y
|
BR2_PACKAGE_SYSSTAT=y
|
||||||
BR2_PACKAGE_UBOOT_TOOLS=y
|
BR2_PACKAGE_UBOOT_TOOLS=y
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user