Setting up repository
[linux-libre-firmware.git] / ath9k_htc / sboot / utility / sh / make_fw.sh
1 #!/bin/sh
2
3 # Copyright (c) 2013 Qualcomm Atheros, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted (subject to the limitations in the
8 # disclaimer below) provided that the following conditions are met:
9 #
10 #  * Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 #
13 #  * Redistributions in binary form must reproduce the above copyright
14 #    notice, this list of conditions and the following disclaimer in the
15 #    documentation and/or other materials provided with the
16 #    distribution.
17 #
18 #  * Neither the name of Qualcomm Atheros nor the names of its
19 #    contributors may be used to endorse or promote products derived
20 #    from this software without specific prior written permission.
21 #
22 # NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
23 # GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
24 # HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
25 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36 # This script constructs an AR6002 ROM firmware binary image
37 # for FPGA(if FPGA_FLAG is "1") or for actual silicon if FPGA_FLAG
38 # is not "1".
39 #
40 # It takes two things as input:
41 #   sw.rom.out, which is an ELF image of ROM software
42 #        that was built for actual hardware or for FPGA
43 #   data.rom.hw.bin OR data.rom.fpga.bin, which contains
44 #        DataSets and other data that is to be included
45 #        at the end of the firmware image
46 #
47 # It produces fw.rom.bin, a firmware image appropriate for
48 # use with AR6002 ROM.
49 #
50 # The image is constructed by converting the sw.rom.out ELF
51 # image to binary, padding at the end of that binary,
52 # and appending the data binary from data.rom.*.bin.  So the
53 # final fw.rom.bin image is a binary image that's exactly
54 # the same size as the ROM hardware and which contains ROM
55 # software (including literals, read-only data, data that
56 # will be copied to RAM in order to initialize read/write data),
57 # DataSet Metadata, and DataSets.
58
59
60 sw_image=${sw_image:-$PRJ_ROOT/build/image/magpie/rom.out}
61 sw_bin=${sw_bin:-$PRJ_ROOT/build/image/magpie/rom.bin}
62
63
64 ds_in_rom="0x`xt-nm $sw_image | grep " _data_start_in_rom" | cut -b -8`"
65
66 # Place data binary at the end of ROM.
67 #data_start=$((9168*1024-`stat --format='%s' $data_bin`))
68
69 xt-objcopy  \
70   --change-section-lma .lit4+0x400000 \
71   --change-section-vma .lit4+0x400000 \
72   --change-section-lma .rodata+0x400000 \
73   --change-section-vma .rodata+0x400000 \
74   --change-section-lma .dram0.literal+0x400000 \
75   --change-section-vma .dram0.literal+0x400000 \
76   --remove-section     .dport0.data \
77   --change-section-lma .data=$((ds_in_rom)) \
78   --change-section-vma .data=$((ds_in_rom)) \
79   -O binary $sw_image $sw_bin
80
81 #cat $sw_bin $data_bin > $fw_bin
82
83 #if [ `stat --format='%s' $fw_bin` -ne $((96*1024)) ]
84 #then
85 #  echo "$0 ERROR: firmware $fw_bin is NOT the expected size."
86 #fi
87
88 exit 0