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

Side by Side 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 unified diff | Download patch
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 # 4 #
5 # This contains common constants and functions for installer scripts. This must 5 # This contains common constants and functions for installer scripts. This must
6 # evaluate properly for both /bin/bash and /bin/sh, since it's used both to 6 # evaluate properly for both /bin/bash and /bin/sh, since it's used both to
7 # create the initial image at compile time and to install or upgrade a running 7 # create the initial image at compile time and to install or upgrade a running
8 # image. 8 # image.
9 9
10 # Here are the GUIDs we'll be using to identify various partitions. 10 # Here are the GUIDs we'll be using to identify various partitions.
11 STATEFUL_GUID='ebd0a0a2-b9e5-4433-87c0-68b6b72699c7' 11 STATEFUL_GUID='ebd0a0a2-b9e5-4433-87c0-68b6b72699c7'
12 KERN_GUID='fe3a2a5d-4f32-41a7-b725-accc3285a309' 12 KERN_GUID='fe3a2a5d-4f32-41a7-b725-accc3285a309'
13 ROOTFS_GUID='3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec' 13 ROOTFS_GUID='3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec'
14 ESP_GUID='28732ac1-1ff8-d211-ba4b-00a0c93ec93b' 14 ESP_GUID='28732ac1-1ff8-d211-ba4b-00a0c93ec93b'
15 15
16 16
17 # The GPT tables describe things in terms of 512-byte sectors, but some 17 # The GPT tables describe things in terms of 512-byte sectors, but some
18 # filesystems prefer 4096-byte blocks. These functions help with alignment 18 # filesystems prefer 4096-byte blocks. These functions help with alignment
19 # issues. 19 # issues.
20 20
21 # This returns the size of a file or device in 512-byte sectors, rounded up if 21 # This returns the size of a file or device in 512-byte sectors, rounded up if
22 # needed. 22 # needed.
23 # Invoke as: subshell 23 # Invoke as: subshell
24 # Args: FILENAME 24 # Args: FILENAME
25 # Return: whole number of sectors needed to fully contain FILENAME 25 # Return: whole number of sectors needed to fully contain FILENAME
26 numsectors() { 26 numsectors() {
27 case $1 in 27 if [ -b "${1}" ]; then
28 /dev/*[0-9])
29 dnum=${1##*/}
30 dev=${dnum%%[0-9]*}
31 cat /sys/block/$dev/$dnum/size
32 ;;
33 /dev/*)
34 dev=${1##*/} 28 dev=${1##*/}
35 cat /sys/block/$dev/size 29 if [ -e /sys/block/$dev/size ]; then
36 ;; 30 cat /sys/block/$dev/size
37 *) 31 else
32 part=${1##*/}
33 block=$(get_block_dev_from_partition_dev "${1}")
34 block=${block##*/}
35 cat /sys/block/$block/$part/size
36 fi
37 else
38 local bytes=$(stat -c%s "$1") 38 local bytes=$(stat -c%s "$1")
39 local sectors=$(( $bytes / 512 )) 39 local sectors=$(( $bytes / 512 ))
40 local rem=$(( $bytes % 512 )) 40 local rem=$(( $bytes % 512 ))
41 if [ $rem -ne 0 ]; then 41 if [ $rem -ne 0 ]; then
42 sectors=$(( $sectors + 1 )) 42 sectors=$(( $sectors + 1 ))
43 fi 43 fi
44 echo $sectors 44 echo $sectors
45 ;; 45 fi
46 esac
47 } 46 }
48 47
49 # Round a number of 512-byte sectors up to an integral number of 4096-byte 48 # Round a number of 512-byte sectors up to an integral number of 4096-byte
50 # blocks. 49 # blocks.
51 # Invoke as: subshell 50 # Invoke as: subshell
52 # Args: SECTORS 51 # Args: SECTORS
53 # Return: Next largest multiple-of-8 sectors (ex: 4->8, 33->40, 32->32) 52 # Return: Next largest multiple-of-8 sectors (ex: 4->8, 33->40, 32->32)
54 roundup() { 53 roundup() {
55 local num=$1 54 local num=$1
56 local rem=$(( $num % 8 )) 55 local rem=$(( $num % 8 ))
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 # Args: DEVICE PARTNUM 322 # Args: DEVICE PARTNUM
324 # Returns: size (in sectors) of partition PARTNUM 323 # Returns: size (in sectors) of partition PARTNUM
325 partsize() { 324 partsize() {
326 # get string 325 # get string
327 local X="$(_partinfo $1 $2)" 326 local X="$(_partinfo $1 $2)"
328 # detect success or failure here 327 # detect success or failure here
329 [ -n "$X" ] 328 [ -n "$X" ]
330 echo ${X#* } 329 echo ${X#* }
331 } 330 }
332 331
332 # Extract the whole disk block device from the partition device.
333 # This works for /dev/sda3 (-> /dev/sda) as well as /dev/mmcblk0p2
334 # (-> /dev/mmcblk0).
335 get_block_dev_from_partition_dev() {
336 local partition=$1
337 if ! (expr match "$partition" ".*[0-9]$" >/dev/null) ; then
338 echo "Invalid partition name: $partition" >&2
339 exit 1
340 fi
341 # Remove the last digit.
342 local block=$(echo "$partition" | sed -e 's/\(.*\)[0-9]$/\1/')
343 # If needed, strip the trailing 'p'.
344 if (expr match "$block" ".*[0-9]p$" >/dev/null); then
345 echo "${block%p}"
346 else
347 echo "$block"
348 fi
349 }
350
351 # Extract the partition number from the partition device.
352 # This works for /dev/sda3 (-> 3) as well as /dev/mmcblk0p2 (-> 2).
353 get_partition_number() {
354 local partition=$1
355 if ! (expr match "$partition" ".*[0-9]$" >/dev/null) ; then
356 echo "Invalid partition name: $partition" >&2
357 exit 1
358 fi
359 # Extract the last digit.
360 echo "$partition" | sed -e 's/^.*\([0-9]\)$/\1/'
361 }
362
363 # Construct a partition device name from a whole disk block device and a
364 # partition number.
365 # This works for [/dev/sda, 3] (-> /dev/sda3) as well as [/dev/mmcblk0, 2]
366 # (-> /dev/mmcblk0p2).
367 make_partition_dev() {
368 local block=$1
369 local num=$2
370 # If the disk block device ends with a number, we add a 'p' before the
371 # partition number.
372 if (expr match "$block" ".*[0-9]$" >/dev/null) ; then
373 echo "${block}p${num}"
374 else
375 echo "${block}${num}"
376 fi
377 }
378
379 # Construct a PMBR for the arm platform, Uboot will load PMBR and "autoscr" it.
380 # Arguments List:
381 # $1 : Kernel Partition Offset.
382 # $2 : Kernel Partition Size ( in Sectors ).
383 # $3 : DEVICE
384 # Return file path of the generated PMBR.
385
386 make_arm_mbr() {
387 # Create the U-Boot script to copy the kernel into memory and boot it.
388 local KERNEL_OFFSET=$(printf "0x%08x" ${1})
389 local KERNEL_SECS_HEX=$(printf "0x%08x" ${2})
390 local DEVICE=${3}
391
392 BOOTARGS="root=/dev/mmcblk${DEVICE}p3"
393 BOOTARGS="${BOOTARGS} init=/sbin/init"
394 BOOTARGS="${BOOTARGS} console=ttySAC2,115200"
395 BOOTARGS="${BOOTARGS} mem=1024M"
396 BOOTARGS="${BOOTARGS} rootwait"
397
398 MBR_SCRIPT="/var/tmp/mbr_script"
399 echo -e "echo\necho ---- ChromeOS Boot ----\necho\n" \
400 "setenv bootargs ${BOOTARGS}\n" \
401 "mmc read ${DEVICE} C0008000 $KERNEL_OFFSET $KERNEL_SECS_HEX\n" \
402 "bootm C0008000" > ${MBR_SCRIPT}
403 MKIMAGE="/usr/bin/mkimage"
404 if [ -x "$MKIMAGE" ]; then
405 MBR_SCRIPT_UIMG="${MBR_SCRIPT}.uimg"
406 "$MKIMAGE" -A "arm" -O linux -T script -a 0 -e 0 -n "COS boot" \
407 -d ${MBR_SCRIPT} ${MBR_SCRIPT_UIMG} >&2
408 else
409 echo "Error: u-boot mkimage not found or not executable." >&2
410 exit 1
411 fi
412 echo ${MBR_SCRIPT_UIMG}
413 }
OLDNEW
« 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