OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Script to build a bootable keyfob-based chromeos system image from within | 7 # Script to build a bootable keyfob-based chromeos system image from within |
8 # a chromiumos setup. This assumes that all needed packages have been built into | 8 # a chromiumos setup. This assumes that all needed packages have been built into |
9 # the given target's root with binary packages turned on. This script will | 9 # the given target's root with binary packages turned on. This script will |
10 # build the Chrome OS image using only pre-built binary packages. | 10 # build the Chrome OS image using only pre-built binary packages. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 # Determine build version. | 63 # Determine build version. |
64 . "${SCRIPTS_DIR}/chromeos_version.sh" | 64 . "${SCRIPTS_DIR}/chromeos_version.sh" |
65 | 65 |
66 # Use canonical path since some tools (e.g. mount) do not like symlinks. | 66 # Use canonical path since some tools (e.g. mount) do not like symlinks. |
67 # Append build attempt to output directory. | 67 # Append build attempt to output directory. |
68 IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" | 68 IMAGE_SUBDIR="${CHROMEOS_VERSION_STRING}-a${FLAGS_build_attempt}" |
69 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" | 69 OUTPUT_DIR="${FLAGS_output_root}/${FLAGS_board}/${IMAGE_SUBDIR}" |
70 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" | 70 ROOT_FS_DIR="${OUTPUT_DIR}/rootfs" |
71 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" | 71 ROOT_FS_IMG="${OUTPUT_DIR}/rootfs.image" |
72 MBR_IMG="${OUTPUT_DIR}/mbr.image" | 72 MBR_IMG="${OUTPUT_DIR}/mbr.image" |
73 OUTPUT_IMG="${OUTPUT_DIR}/usb.img" | 73 OUTPUT_IMG="${OUTPUT_DIR}/chromiumos_image.bin" |
74 | 74 |
75 BOARD="${FLAGS_board}" | 75 BOARD="${FLAGS_board}" |
76 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" | 76 BOARD_ROOT="${FLAGS_build_root}/${BOARD}" |
77 | 77 |
78 LOOP_DEV= | 78 LOOP_DEV= |
79 | 79 |
80 # What cross-build are we targeting? | 80 # What cross-build are we targeting? |
81 . "${BOARD_ROOT}/etc/make.conf.board_setup" | 81 . "${BOARD_ROOT}/etc/make.conf.board_setup" |
82 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} | 82 LIBC_VERSION=${LIBC_VERSION:-"2.10.1-r1"} |
83 | 83 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 #TODO(sosa@chromium.org) - /usr/bin/xterm symlink not created in stateful. | 313 #TODO(sosa@chromium.org) - /usr/bin/xterm symlink not created in stateful. |
314 sudo ln -sf "/usr/local/bin/aterm" "/usr/bin/xterm" | 314 sudo ln -sf "/usr/local/bin/aterm" "/usr/bin/xterm" |
315 fi | 315 fi |
316 | 316 |
317 # Perform any customizations on the root file system that are needed. | 317 # Perform any customizations on the root file system that are needed. |
318 WITH_DEV="" | 318 WITH_DEV="" |
319 if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]]; then | 319 if [[ $FLAGS_withdev -eq $FLAGS_TRUE ]]; then |
320 WITH_DEV="--withdev" | 320 WITH_DEV="--withdev" |
321 fi | 321 fi |
322 | 322 |
| 323 # Extract the kernel from the root filesystem for use by the GPT image. Legacy |
| 324 # BIOS will use the kernel in the rootfs (via syslinux), ChromeOS BIOS will use |
| 325 # the kernel partition. |
| 326 sudo cp -f ${ROOT_FS_DIR}/boot/vmlinuz ${OUTPUT_DIR}/vmlinuz.image |
| 327 |
323 #TODO(sosa@chromium.org) - Does it make sense to leave /usr/local bound here? | 328 #TODO(sosa@chromium.org) - Does it make sense to leave /usr/local bound here? |
324 "${SCRIPTS_DIR}/customize_rootfs" \ | 329 "${SCRIPTS_DIR}/customize_rootfs" \ |
325 --root="$ROOT_FS_DIR" \ | 330 --root="$ROOT_FS_DIR" \ |
326 --target="$ARCH" \ | 331 --target="$ARCH" \ |
327 --board="$BOARD" \ | 332 --board="$BOARD" \ |
328 $WITH_DEV | 333 $WITH_DEV |
329 | 334 |
330 # Check that the image has been correctly created. | 335 # Check that the image has been correctly created. |
331 "${SCRIPTS_DIR}/test_image" \ | 336 "${SCRIPTS_DIR}/test_image" \ |
332 --root="$ROOT_FS_DIR" \ | 337 --root="$ROOT_FS_DIR" \ |
333 --target="$ARCH" | 338 --target="$ARCH" |
334 | 339 |
335 # Set dev_mode flag and update library cache. | 340 # Set dev_mode flag and update library cache. |
336 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then | 341 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then |
337 sudo touch "$ROOT_FS_DIR/root/.dev_mode" | 342 sudo touch "$ROOT_FS_DIR/root/.dev_mode" |
338 sudo /sbin/ldconfig -r "$ROOT_FS_DIR" | 343 sudo /sbin/ldconfig -r "$ROOT_FS_DIR" |
339 fi | 344 fi |
340 | 345 |
341 # Only bound if installing dev to stateful. | 346 # Only bound if installing dev to stateful. |
342 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then | 347 if [ $FLAGS_statefuldev -eq $FLAGS_TRUE ] ; then |
343 sudo umount "$ROOT_FS_DIR/usr/local" | 348 sudo umount "$ROOT_FS_DIR/usr/local" |
344 fi | 349 fi |
345 | 350 |
346 # Cleanup loop devices. | 351 # Cleanup loop devices. |
347 cleanup_stateful_fs_loop | 352 cleanup_stateful_fs_loop |
348 cleanup_rootfs_loop | 353 cleanup_rootfs_loop |
349 | 354 |
350 # Create a master boot record. | 355 # Create the GPT-formatted image |
351 # Start with the syslinux master boot record. We need to zero-pad to | 356 ${SCRIPTS_DIR}/build_gpt.sh \ |
352 # fill out a 512-byte sector size. | 357 --arch=${ARCH} --board=${FLAGS_board} --board_root=${BOARD_ROOT} \ |
353 SYSLINUX_MBR="/usr/share/syslinux/mbr.bin" | 358 ${OUTPUT_DIR} ${OUTPUT_IMG} |
354 dd if="$SYSLINUX_MBR" of="$MBR_IMG" bs=512 count=1 conv=sync | 359 |
355 # Create a partition table in the MBR. | |
356 NUM_SECTORS=$((`stat --format="%s" "$ROOT_FS_IMG"` / 512)) | |
357 KERNEL_SECTORS=8192 | |
358 sudo sfdisk -H64 -S32 -uS -f "$MBR_IMG" <<EOF | |
359 ,$NUM_SECTORS,L,-, | |
360 ,$NUM_SECTORS,S,-, | |
361 ,$NUM_SECTORS,L,*, | |
362 ,$KERNEL_SECTORS,L,-, | |
363 ; | |
364 EOF | |
365 if [[ "$ARCH" = "arm" ]]; then | |
366 # Write u-boot script into MBR code block that boots 4th partition kernel. | |
367 KERNEL_OFFSET=`printf "%08x" $(((3 * $NUM_SECTORS) + 1))` | |
368 KERNEL_SECS_HEX=`printf "%08x" $KERNEL_SECTORS` | |
369 MBR_SCRIPT="${OUTPUT_DIR}/mbr_script" | |
370 echo -e "echo\necho ---- ChromeOS Boot ----\necho\n" \ | |
371 "mmc read 1 C0008000 0x$KERNEL_OFFSET 0x$KERNEL_SECS_HEX\n" \ | |
372 "bootm C0008000" > ${MBR_SCRIPT} | |
373 MKIMAGE="${BOARD_ROOT}/u-boot/mkimage" | |
374 if [[ -f "$MKIMAGE".gz ]]; then | |
375 sudo gunzip "$MKIMAGE".gz | |
376 fi | |
377 if [[ -x "$MKIMAGE" ]]; then | |
378 MBR_SCRIPT_UIMG="${MBR_SCRIPT}.uimg" | |
379 "$MKIMAGE" -A "${ARCH}" -O linux -T script -a 0 -e 0 -n "COS boot" \ | |
380 -d ${MBR_SCRIPT} ${MBR_SCRIPT_UIMG} | |
381 dd bs=1 count=`stat --printf="%s" ${MBR_SCRIPT_UIMG}` \ | |
382 if="$MBR_SCRIPT_UIMG" of="$MBR_IMG" conv=notrunc | |
383 hexdump -v -C "$MBR_IMG" | |
384 else | |
385 echo "Error: u-boot mkimage not found or not executable." | |
386 fi | |
387 fi | |
388 | 360 |
389 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" | 361 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
390 echo "Done. Image created in ${OUTPUT_DIR}" | 362 echo "Done. Image created in ${OUTPUT_DIR}" |
391 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 363 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
392 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdb" | 364 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdb" |
393 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 365 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
394 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 366 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
395 echo "from the scripts directory where you entered the chroot." | 367 echo "from the scripts directory where you entered the chroot." |
396 | 368 |
397 trap - EXIT | 369 trap - EXIT |
OLD | NEW |