source: SVN/ventana/images/mkimage_jtag @ 30

Last change on this file since 30 was 30, checked in by Tim Harvey, 2 years ago

mkimage_jtag: fix invalid code offsets in comments

Updated the comments to reflect the actual offsets used.

Signed-off-by: Tim Harvey <tharvey@…>

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/bin/sh
2#
3# mkimage_jtag v1.0.0
4# Copyright 2014 Gateworks Corporation <support@gateworks.com>
5#
6# create a binary image suitable for IMX6 targets for jtag_usbv4
7#
8# usage: mkimage_jtag [<SPL> <u-boot.img>]|[<SPL> <u-boot.img> <ubi>]|[<ubi>]
9#
10# Examples:
11#   # create jtagable bin containing just bootloader (will not overwrite all)
12#   mkimage_jtag <SPL> <u-boot.img> > uboot.bin
13#   # create jtagable bin containing bootloader+ubi (will overwrite all)
14#   mkimage_jtag <SPL> <u-boot.img> <ubi> > image.bin
15#   # create jtagable bin containing ubi (will not overwrite bootloader/env)
16#   mkimage_jtag <ubi> > image.bin
17#
18# This puts a simple header around the binary parts that make up a bootable
19# image, sending the output to stdout.
20#
21# The header consists of the following structure (little-endian):
22#
23# u16 magic: GW
24# u16 erase_mode:
25#      0=erase entire flash (use only on first header)
26#      1=erase none (perform no erase)
27#      2=erase part (erase only this part - offset must align with flash block)
28#      3=erase to end (erase from this part to end of device)
29# u32 offset: byte offset in flash (logical) to program this data
30#      (this must align with a flash block boundary if erasing part or to end
31#       and otherwise must align with a flashs page boundary)
32# u32 dsize: byte size of this data segment
33# u32 psize: part size of this data segment
34#
35# The psize value is only used in the special case where dsize=0 which
36# specifies a bootstream.  This must be the first part in a series of parts
37# and is programmed in a specific fashion on NAND FLASH in accordance with
38# the requirements of the i.MX6 BOOT ROM.  In this case the data must
39# be an i.MX6 bootlet containing an IVT and DCD, such as u-boot.imx.
40#
41
42ERASE_ALL=0
43ERASE_NON=1
44ERASE_PRT=2
45ERASE_END=3
46
47# output binary u32
48# $1 int
49u32() {
50        b0=$(( $(($1>>24)) & 0xff))
51        b1=$(( $(($1>>16)) & 0xff))
52        b2=$(( $(($1>>8)) & 0xff))
53        b3=$(( $(($1>>0)) & 0xff))
54
55        /usr/bin/printf "\\x$(/usr/bin/printf "%x" $b3)"
56        /usr/bin/printf "\\x$(/usr/bin/printf "%x" $b2)"
57        /usr/bin/printf "\\x$(/usr/bin/printf "%x" $b1)"
58        /usr/bin/printf "\\x$(/usr/bin/printf "%x" $b0)"
59}
60
61# output binary u16
62# $1 int
63u16() {
64        b0=$(( $(($1>>8)) & 0xff))
65        b1=$(( $(($1>>0)) & 0xff))
66
67        /usr/bin/printf "\\x$(/usr/bin/printf "%x" $b1)"
68        /usr/bin/printf "\\x$(/usr/bin/printf "%x" $b0)"
69}
70
71# emit a part
72# $1 file
73# $2 erase_mode
74# $3 offset
75# $4 size (only needed if offset==0 for bootloader part size)
76emit()
77{
78        local file=$1
79        local erase_mode=$2
80        local offset=$3
81        local part_size=${4:-0}
82        local fsize
83
84        fsize=$(ls -lL $file | awk '{print $5}')
85
86        /usr/bin/printf "GW" # magic
87        u16 $erase_mode
88        u32 $offset
89        u32 $fsize
90        u32 $part_size
91        cat $file
92}
93
94# output image to stdout
95case $# in
96        # ubi (w/o touching bootloader+env)
97        1)
98        emit $1 $ERASE_END 0x1100000    # rootfs@17MB+ (erase to end)
99        ;;
100
101        # bootloader (SPL + u-boot.img) w/o eraseing env/ubi
102        2)
103        emit $1 $ERASE_PRT 0 0xE00000   # SPL@0
104        emit $2 $ERASE_PRT 0x0E00000 0x0200000  # u-boot@14MB-16MB
105        ;;
106
107        # erase entire part and program SPL + u-boot.img + ubi
108        3)
109        emit $1 $ERASE_ALL 0 0xE00000   # SPL@0
110        emit $2 $ERASE_NON 0x0E00000    # u-boot@14MB
111        emit $3 $ERASE_NON 0x1100000    # rootfs@17MB
112        ;;
113
114        # usage
115        *)
116        echo "usage: $0 [<SPL> <u-boot.img>]|[<SPL> <u-boot.img> <ubi>]|[<ubi>]"
117        exit 1
118        ;;
119esac
Note: See TracBrowser for help on using the repository browser.