diff options
author | Stephen Warren <swarren@nvidia.com> | 2014-05-19 14:35:35 -0600 |
---|---|---|
committer | Stephen Warren <swarren@nvidia.com> | 2014-05-19 14:41:39 -0600 |
commit | 569fd205f3dbf84449e6943914ac812fe1529795 (patch) | |
tree | 928336cd9478dbff27b361ba28e22c20cc2ad24d | |
parent | 9a971ee7c3e35221031c91d494e6c7f19befd84f (diff) | |
download | tegra-uboot-flasher-scripts-569fd205f3dbf84449e6943914ac812fe1529795.tar.gz |
Use actual U-Boot BSS size for padding when flashing
In flashing mode, tegra-uboot-flasher downloads an image into RAM which
consists of the U-Boot binary, board DTB, some padding, and the image to
write into flash. The padding needs to be large enough so that the flash
image doesn't overlap with U-Boot's BSS at run-time, since the BSS is
zero'd out at boot, and stores variables that are written to at run-time.
Any overlap would cause the flash image to be corrupted.
tegra-uboot-flasher currently uses a guess of 1MB for the required
padding size. However, when enabling DFU support in U-Boot, the BSS size
balloons to well over 1MB, thus causing corruption to the flash image.
Solve this by recording the actual BSS size at build time, and using the
exact value at flashing time to calculate the padding. Add in an extra
4KB of padding just in case the DTB gets larger when adding in the
flashing commands. Previously, this was also assumed to fit into the
hard-coded 1MB of pad.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
-rwxr-xr-x | build | 17 | ||||
-rwxr-xr-x | tegra-uboot-flasher | 13 |
2 files changed, 28 insertions, 2 deletions
@@ -24,6 +24,7 @@ import argparse import multiprocessing import os import shutil +import subprocess import sys from tegraboardconfigs import * @@ -139,6 +140,22 @@ def import_uboot_one_board(boardname, build_uboot_dir): out_board_dir = gen_out_board_dir(boardname) mkdir(out_board_dir) + uboot = os.path.join(build_uboot_dir, 'u-boot') + cmd = [os.environ['CROSS_COMPILE'] + 'size', '-A', uboot] + lines = subprocess.check_output(cmd) + bss_size = None + for line in lines.split('\n'): + fields = line.split() + if fields[0] == '.bss': + bss_size = fields[1] + break + if not bss_size: + raise Exception('Could not find bss size in `size`') + dst = os.path.join(out_board_dir, 'u-boot-bss-size') + f = open(dst, 'wt') + f.write(bss_size) + f.close() + src = os.path.join(build_uboot_dir, 'u-boot-nodtb-tegra.bin') dst = os.path.join(out_board_dir, 'u-boot-nodtb-tegra.bin') cp(src, dst) diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher index 8c6a21c..ded8d17 100755 --- a/tegra-uboot-flasher +++ b/tegra-uboot-flasher @@ -156,9 +156,18 @@ def func_flash(): if args.debug: print 'u_boot_plus_dtb_size %d 0x%x' % (u_boot_plus_dtb_size, u_boot_plus_dtb_size) - # Add 1024k to avoid U-Boot's BSS, and in case the DT size changes due to fdtput + bss_size_fn = os.path.join(out_board_dir, 'u-boot-bss-size') + bss_size_f = open(bss_size_fn, 'rt') + bss_size_s = bss_size_f.read() + bss_size_f.close() + bss_size = int(bss_size_s) + if args.debug: + print 'bss_size %d 0x%x' % (bss_size, bss_size) + + # Avoid U-Boot's BSS, so the BSS-zeroing doesn't trash the DTB + # Add 4KB in case the DTB size changes due to fdtput # Align to 4k, so flash writes don't need a bounce buffer for DMA - padded_size = (u_boot_plus_dtb_size + (1024 * 1024) + (4 * 1024) - 1) & ~((4 * 1024) - 1) + padded_size = (u_boot_plus_dtb_size + bss_size + (2 * 4 * 1024) - 1) & ~((4 * 1024) - 1) if args.debug: print 'padded_size %d 0x%x' % (padded_size, padded_size) |