Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Unified Diff: src/platform/installer/chromeos-common.sh

Issue 1618013: add install to arm platform (Closed)
Patch Set: unfork the make pmbr code Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/platform/installer/chromeos-install » ('j') | src/platform/installer/chromeos-install » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/installer/chromeos-common.sh
diff --git a/src/platform/installer/chromeos-common.sh b/src/platform/installer/chromeos-common.sh
index 83fb0348efc51c36d77db5c28e93c77c4ba2a01b..4cec35973f07b4dcc4530b92b7a1865acc19ced1 100644
--- a/src/platform/installer/chromeos-common.sh
+++ b/src/platform/installer/chromeos-common.sh
@@ -24,17 +24,17 @@ ESP_GUID='28732ac1-1ff8-d211-ba4b-00a0c93ec93b'
# Args: FILENAME
# Return: whole number of sectors needed to fully contain FILENAME
numsectors() {
- case $1 in
- /dev/*[0-9])
- dnum=${1##*/}
- dev=${dnum%%[0-9]*}
- cat /sys/block/$dev/$dnum/size
- ;;
- /dev/*)
+ if [ -b "${1}" ]; then
dev=${1##*/}
- cat /sys/block/$dev/size
- ;;
- *)
+ if [ -e /sys/block/$dev/size ]; then
+ cat /sys/block/$dev/size
+ else
+ part=${1##*/}
+ block=$(get_block_dev_from_partition_dev "${1}")
+ block=${block##*/}
+ cat /sys/block/$block/$part/size
+ fi
+ else
local bytes=$(stat -c%s "$1")
local sectors=$(( $bytes / 512 ))
local rem=$(( $bytes % 512 ))
@@ -42,8 +42,7 @@ numsectors() {
sectors=$(( $sectors + 1 ))
fi
echo $sectors
- ;;
- esac
+ fi
}
# Round a number of 512-byte sectors up to an integral number of 4096-byte
@@ -330,3 +329,85 @@ partsize() {
echo ${X#* }
}
+# Extract the whole disk block device from the partition device.
+# This works for /dev/sda3 (-> /dev/sda) as well as /dev/mmcblk0p2
+# (-> /dev/mmcblk0).
+get_block_dev_from_partition_dev() {
+ local partition=$1
+ if ! (expr match "$partition" ".*[0-9]$" >/dev/null) ; then
+ echo "Invalid partition name: $partition" >&2
+ exit 1
+ fi
+ # Remove the last digit.
+ local block=$(echo "$partition" | sed -e 's/\(.*\)[0-9]$/\1/')
+ # If needed, strip the trailing 'p'.
+ if (expr match "$block" ".*[0-9]p$" >/dev/null); then
+ echo "${block%p}"
+ else
+ echo "$block"
+ fi
+}
+
+# Extract the partition number from the partition device.
+# This works for /dev/sda3 (-> 3) as well as /dev/mmcblk0p2 (-> 2).
+get_partition_number() {
+ local partition=$1
+ if ! (expr match "$partition" ".*[0-9]$" >/dev/null) ; then
+ echo "Invalid partition name: $partition" >&2
+ exit 1
+ fi
+ # Extract the last digit.
+ echo "$partition" | sed -e 's/^.*\([0-9]\)$/\1/'
+}
+
+# Construct a partition device name from a whole disk block device and a
+# partition number.
+# This works for [/dev/sda, 3] (-> /dev/sda3) as well as [/dev/mmcblk0, 2]
+# (-> /dev/mmcblk0p2).
+make_partition_dev() {
+ local block=$1
+ local num=$2
+ # If the disk block device ends with a number, we add a 'p' before the
+ # partition number.
+ if (expr match "$block" ".*[0-9]$" >/dev/null) ; then
+ echo "${block}p${num}"
+ else
+ echo "${block}${num}"
+ fi
+}
+
+# Construct a PMBR for the arm platform, Uboot will load PMBR and "autoscr" it.
+# Arguments List:
+# $1 : Kernel Partition Offset.
+# $2 : Kernel Partition Size ( in Sectors ).
+# $3 : DEVICE
+# Return file path of the generated PMBR.
+
+make_arm_mbr() {
+ # Create the U-Boot script to copy the kernel into memory and boot it.
+ local KERNEL_OFFSET=$(printf "0x%08x" ${1})
+ local KERNEL_SECS_HEX=$(printf "0x%08x" ${2})
+ local DEVICE=${3}
+
+ BOOTARGS="root=/dev/mmcblk${DEVICE}p3"
+ BOOTARGS="${BOOTARGS} init=/sbin/init"
+ BOOTARGS="${BOOTARGS} console=ttySAC2,115200"
+ BOOTARGS="${BOOTARGS} mem=1024M"
+ BOOTARGS="${BOOTARGS} rootwait"
+
+ MBR_SCRIPT="/var/tmp/mbr_script"
+ echo -e "echo\necho ---- ChromeOS Boot ----\necho\n" \
+ "setenv bootargs ${BOOTARGS}\n" \
+ "mmc read ${DEVICE} C0008000 $KERNEL_OFFSET $KERNEL_SECS_HEX\n" \
+ "bootm C0008000" > ${MBR_SCRIPT}
+ MKIMAGE="/usr/bin/mkimage"
+ if [ -x "$MKIMAGE" ]; then
+ MBR_SCRIPT_UIMG="${MBR_SCRIPT}.uimg"
+ "$MKIMAGE" -A "arm" -O linux -T script -a 0 -e 0 -n "COS boot" \
+ -d ${MBR_SCRIPT} ${MBR_SCRIPT_UIMG} >&2
+ else
+ echo "Error: u-boot mkimage not found or not executable." >&2
+ exit 1
+ fi
+ echo ${MBR_SCRIPT_UIMG}
+}
« no previous file with comments | « no previous file | src/platform/installer/chromeos-install » ('j') | src/platform/installer/chromeos-install » ('J')

Powered by Google App Engine
This is Rietveld 408576698