* [[PATCH flasher] 1/6] Move functions and data to start of file
@ 2013-06-12 23:30 Stephen Warren
[not found] ` <1371079807-16541-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Stephen Warren @ 2013-06-12 23:30 UTC (permalink / raw)
To: swarren-3lzwWm7+Weoh9ZMKESR00Q
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Future changes will create separate functions for the sub-commands that
tegra-uboot-flasher implements. This change prepares for that by moving
other functions away from what will be the body of some of those
functions.
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
tegra-uboot-flasher | 92 ++++++++++++++++++++++++++---------------------------
1 file changed, 46 insertions(+), 46 deletions(-)
diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
index ecc7ac8..447ff37 100755
--- a/tegra-uboot-flasher
+++ b/tegra-uboot-flasher
@@ -29,6 +29,52 @@ import sys
import tempfile
from tegraboardconfigs import *
+def mkdir(path):
+ if not os.path.isdir(path):
+ os.makedirs(path)
+
+def cp(src, dst):
+ print '+ cp', src, dst
+ shutil.copy(src, dst)
+
+def rmtree(path):
+ if os.path.exists(path):
+ shutil.rmtree(path)
+
+def run(dir, cmd):
+ oldcwd = os.getcwd()
+ print '+ cd', dir
+ os.chdir(dir)
+ print '+', cmd
+ ret = os.system(cmd)
+ if ret:
+ raise Exception('Command failed: %d' % ret)
+ os.chdir(oldcwd)
+
+def gen_flashcmd_mmc():
+ flash_id = configs[args.configname]['flash-id-uboot']
+ flash_img_size_sectors = flash_img_size / 512
+ flashcmd = 'mmc dev %d 1 ; ' % flash_id
+ flashcmd += 'mmc write 0x%08x 0 0x%x ; ' % (flash_image_addr, flash_img_size_sectors)
+ return flashcmd
+
+def gen_flashcmd_nand():
+ flashcmd = 'nand erase.chip ; '
+ flashcmd += 'nand write 0x%08x 0 0x%08x ; ' % (flash_image_addr, flash_img_size)
+ return flashcmd
+
+def gen_flashcmd_spi():
+ flashcmd = 'sf probe 0 ; '
+ flashcmd += 'sf erase 0 0x%08x ; ' % configs[args.configname]['flash-erase-size']
+ flashcmd += 'sf write 0x%08x 0 0x%08x ; ' % (flash_image_addr, flash_img_size)
+ return flashcmd
+
+gen_flashcmds = {
+ 'emmc': gen_flashcmd_mmc,
+ 'nand': gen_flashcmd_nand,
+ 'spi': gen_flashcmd_spi,
+}
+
parser = argparse.ArgumentParser(description='Write an image to a Tegra board\'s flash')
parser.add_argument('--debug', action='store_true',
help='Turn on debugging prints')
@@ -125,52 +171,6 @@ flash_image_addr = loadaddr + padded_size
if args.debug:
print 'flash_image_addr %d 0x%x' % (flash_image_addr, flash_image_addr)
-def mkdir(path):
- if not os.path.isdir(path):
- os.makedirs(path)
-
-def cp(src, dst):
- print '+ cp', src, dst
- shutil.copy(src, dst)
-
-def rmtree(path):
- if os.path.exists(path):
- shutil.rmtree(path)
-
-def run(dir, cmd):
- oldcwd = os.getcwd()
- print '+ cd', dir
- os.chdir(dir)
- print '+', cmd
- ret = os.system(cmd)
- if ret:
- raise Exception('Command failed: %d' % ret)
- os.chdir(oldcwd)
-
-def gen_flashcmd_mmc():
- flash_id = configs[args.configname]['flash-id-uboot']
- flash_img_size_sectors = flash_img_size / 512
- flashcmd = 'mmc dev %d 1 ; ' % flash_id
- flashcmd += 'mmc write 0x%08x 0 0x%x ; ' % (flash_image_addr, flash_img_size_sectors)
- return flashcmd
-
-def gen_flashcmd_nand():
- flashcmd = 'nand erase.chip ; '
- flashcmd += 'nand write 0x%08x 0 0x%08x ; ' % (flash_image_addr, flash_img_size)
- return flashcmd
-
-def gen_flashcmd_spi():
- flashcmd = 'sf probe 0 ; '
- flashcmd += 'sf erase 0 0x%08x ; ' % configs[args.configname]['flash-erase-size']
- flashcmd += 'sf write 0x%08x 0 0x%08x ; ' % (flash_image_addr, flash_img_size)
- return flashcmd
-
-gen_flashcmds = {
- 'emmc': gen_flashcmd_mmc,
- 'nand': gen_flashcmd_nand,
- 'spi': gen_flashcmd_spi,
-}
-
flash_type = configs[args.configname]['flash-type']
if not gen_flashcmds.has_key(flash_type):
print 'flash-type "%s" not yet supported' % flash_type
--
1.8.1.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [[PATCH flasher] 2/6] Separate out validation of config name
[not found] ` <1371079807-16541-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2013-06-12 23:30 ` Stephen Warren
[not found] ` <1371079807-16541-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-06-12 23:30 ` [[PATCH flasher] 3/6] Split list-confignames implementation into a separate function Stephen Warren
` (4 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Stephen Warren @ 2013-06-12 23:30 UTC (permalink / raw)
To: swarren-3lzwWm7+Weoh9ZMKESR00Q
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
This function will be used by multiple sub-commands in the future.
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
tegra-uboot-flasher | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
index 447ff37..ef73e2f 100755
--- a/tegra-uboot-flasher
+++ b/tegra-uboot-flasher
@@ -75,6 +75,17 @@ gen_flashcmds = {
'spi': gen_flashcmd_spi,
}
+def find_config_dir():
+ if not configs.has_key(args.configname):
+ print 'Unknown config "%s"' % args.configname
+ sys.exit(1)
+
+ global boardname, socname, out_board_dir
+
+ boardname = configs[args.configname]['board']
+ socname = boards[boardname]['soc']
+ out_board_dir = os.path.join(args.data_dir, boardname)
+
parser = argparse.ArgumentParser(description='Write an image to a Tegra board\'s flash')
parser.add_argument('--debug', action='store_true',
help='Turn on debugging prints')
@@ -122,14 +133,7 @@ if args.list_confignames:
print configname
sys.exit(0)
-if not configs.has_key(args.configname):
- print 'Unknown config "%s"' % args.configname
- sys.exit(1)
-
-boardname = configs[args.configname]['board']
-socname = boards[boardname]['soc']
-
-out_board_dir = os.path.join(args.data_dir, boardname)
+find_config_dir()
u_boot_no_dtb = os.path.join(out_board_dir, 'u-boot-nodtb-tegra.bin')
u_boot_no_dtb_size = os.path.getsize(u_boot_no_dtb)
--
1.8.1.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [[PATCH flasher] 3/6] Split list-confignames implementation into a separate function
[not found] ` <1371079807-16541-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-06-12 23:30 ` [[PATCH flasher] 2/6] Separate out validation of config name Stephen Warren
@ 2013-06-12 23:30 ` Stephen Warren
2013-06-12 23:30 ` [[PATCH flasher] 4/6] Add parameters to gen_flashcmd_* Stephen Warren
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Stephen Warren @ 2013-06-12 23:30 UTC (permalink / raw)
To: swarren-3lzwWm7+Weoh9ZMKESR00Q
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
This moves towards each sub-command being a separate function
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
tegra-uboot-flasher | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
index ef73e2f..390ae0e 100755
--- a/tegra-uboot-flasher
+++ b/tegra-uboot-flasher
@@ -86,6 +86,10 @@ def find_config_dir():
socname = boards[boardname]['soc']
out_board_dir = os.path.join(args.data_dir, boardname)
+def func_list_configs():
+ for configname in sorted(configs.keys()):
+ print configname
+
parser = argparse.ArgumentParser(description='Write an image to a Tegra board\'s flash')
parser.add_argument('--debug', action='store_true',
help='Turn on debugging prints')
@@ -129,8 +133,7 @@ if not args.data_dir:
load_configs(os.path.join(args.data_dir, 'configs'))
if args.list_confignames:
- for configname in sorted(configs.keys()):
- print configname
+ func_list_configs()
sys.exit(0)
find_config_dir()
--
1.8.1.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [[PATCH flasher] 4/6] Add parameters to gen_flashcmd_*
[not found] ` <1371079807-16541-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-06-12 23:30 ` [[PATCH flasher] 2/6] Separate out validation of config name Stephen Warren
2013-06-12 23:30 ` [[PATCH flasher] 3/6] Split list-confignames implementation into a separate function Stephen Warren
@ 2013-06-12 23:30 ` Stephen Warren
2013-06-12 23:30 ` [[PATCH flasher] 5/6] Split flashing implementation into a separate function Stephen Warren
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Stephen Warren @ 2013-06-12 23:30 UTC (permalink / raw)
To: swarren-3lzwWm7+Weoh9ZMKESR00Q
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
This way, they don't rely on global variables, which won't be global
once the flashing code is in a separate function.
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
tegra-uboot-flasher | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
index 390ae0e..c4c42a1 100755
--- a/tegra-uboot-flasher
+++ b/tegra-uboot-flasher
@@ -51,19 +51,19 @@ def run(dir, cmd):
raise Exception('Command failed: %d' % ret)
os.chdir(oldcwd)
-def gen_flashcmd_mmc():
+def gen_flashcmd_mmc(flash_image_addr, flash_img_size):
flash_id = configs[args.configname]['flash-id-uboot']
flash_img_size_sectors = flash_img_size / 512
flashcmd = 'mmc dev %d 1 ; ' % flash_id
flashcmd += 'mmc write 0x%08x 0 0x%x ; ' % (flash_image_addr, flash_img_size_sectors)
return flashcmd
-def gen_flashcmd_nand():
+def gen_flashcmd_nand(flash_image_addr, flash_img_size):
flashcmd = 'nand erase.chip ; '
flashcmd += 'nand write 0x%08x 0 0x%08x ; ' % (flash_image_addr, flash_img_size)
return flashcmd
-def gen_flashcmd_spi():
+def gen_flashcmd_spi(flash_image_addr, flash_img_size):
flashcmd = 'sf probe 0 ; '
flashcmd += 'sf erase 0 0x%08x ; ' % configs[args.configname]['flash-erase-size']
flashcmd += 'sf write 0x%08x 0 0x%08x ; ' % (flash_image_addr, flash_img_size)
@@ -200,7 +200,7 @@ try:
bootcmd = ''
if args.debug:
bootcmd = 'crc32 0x%08x 0x%08x ; ' % (flash_image_addr, flash_img_size)
- bootcmd += gen_flashcmd()
+ bootcmd += gen_flashcmd(flash_image_addr, flash_img_size)
bootcmd += 'env default -f -a ; '
# Perhaps U-Boot should set $boardname based on the ID EEPROM; then we wouldn't need this
if configs[args.configname]['dtbfn-extra'] != '':
--
1.8.1.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [[PATCH flasher] 5/6] Split flashing implementation into a separate function
[not found] ` <1371079807-16541-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
` (2 preceding siblings ...)
2013-06-12 23:30 ` [[PATCH flasher] 4/6] Add parameters to gen_flashcmd_* Stephen Warren
@ 2013-06-12 23:30 ` Stephen Warren
2013-06-12 23:30 ` [[PATCH flasher] 6/6] Rework cmdline to use sub-commands Stephen Warren
2013-06-13 22:15 ` [[PATCH flasher] 1/6] Move functions and data to start of file Stephen Warren
5 siblings, 0 replies; 8+ messages in thread
From: Stephen Warren @ 2013-06-12 23:30 UTC (permalink / raw)
To: swarren-3lzwWm7+Weoh9ZMKESR00Q
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Now, each sub-command is its own function
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
tegra-uboot-flasher | 228 ++++++++++++++++++++++++++--------------------------
1 file changed, 115 insertions(+), 113 deletions(-)
diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
index c4c42a1..630b0fb 100755
--- a/tegra-uboot-flasher
+++ b/tegra-uboot-flasher
@@ -90,6 +90,120 @@ def func_list_configs():
for configname in sorted(configs.keys()):
print configname
+def func_flash():
+ find_config_dir()
+
+ u_boot_no_dtb = os.path.join(out_board_dir, 'u-boot-nodtb-tegra.bin')
+ u_boot_no_dtb_size = os.path.getsize(u_boot_no_dtb)
+ if args.debug:
+ print 'u_boot_no_dtb_size %d 0x%x' % (u_boot_no_dtb_size, u_boot_no_dtb_size)
+
+ u_boot_dtb = os.path.join(out_board_dir, 'u-boot.dtb')
+ u_boot_dtb_size = os.path.getsize(u_boot_dtb)
+ if args.debug:
+ print 'u_boot_dtb_size %d 0x%x' % (u_boot_dtb_size, u_boot_dtb_size)
+
+ if args.flash_image:
+ flash_img = args.flash_img
+ else:
+ flash_img = os.path.join(out_board_dir, configs[args.configname]['flash-image'])
+ flash_img_size = os.path.getsize(flash_img)
+ if args.debug:
+ print 'flash_img_size %d 0x%x' % (flash_img_size, flash_img_size)
+
+ bct = os.path.join(out_board_dir, configs[args.configname]['bct'])
+
+ u_boot_plus_dtb_size = u_boot_no_dtb_size + u_boot_dtb_size
+ if args.debug:
+ print 'u_boot_plus_dtb_size %d 0x%x' % (u_boot_plus_dtb_size, u_boot_plus_dtb_size)
+
+ # Add 32k in case 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 + (32 * 1024) + (4 * 1024) - 1) & ~((4 * 1024) - 1)
+ if args.debug:
+ print 'padded_size %d 0x%x' % (padded_size, padded_size)
+
+ pad_size = padded_size - u_boot_plus_dtb_size
+ if args.debug:
+ print 'pad_size %d 0x%x' % (pad_size, pad_size)
+
+ # 0x00108000 is CONFIG_SYS_TEXT_BASE in U-Boot, minus RAM base
+ loadaddr = socs[socname]['ram-base'] + 0x00108000
+ flash_image_addr = loadaddr + padded_size
+ if args.debug:
+ print 'flash_image_addr %d 0x%x' % (flash_image_addr, flash_image_addr)
+
+ flash_type = configs[args.configname]['flash-type']
+ if not gen_flashcmds.has_key(flash_type):
+ print 'flash-type "%s" not yet supported' % flash_type
+ sys.exit(1)
+ gen_flashcmd = gen_flashcmds[flash_type]
+
+ if args.work_dir:
+ workdir = os.path.abspath(args.work_dir)
+ mkdir(workdir)
+ else:
+ workdir = tempfile.mkdtemp()
+ try:
+ u_boot_dtb_runflash = os.path.join(workdir, 'u-boot-runflash.dtb')
+ cp(u_boot_dtb, u_boot_dtb_runflash)
+
+ # -2; never delay or interrupt
+ cmd = 'fdtput -p -t i ' + u_boot_dtb_runflash + ' /config bootdelay 0xfffffffe'
+ run(workdir, cmd)
+
+ bootcmd = ''
+ if args.debug:
+ bootcmd = 'crc32 0x%08x 0x%08x ; ' % (flash_image_addr, flash_img_size)
+ bootcmd += gen_flashcmd(flash_image_addr, flash_img_size)
+ bootcmd += 'env default -f -a ; '
+ # Perhaps U-Boot should set $boardname based on the ID EEPROM; then we wouldn't need this
+ if configs[args.configname]['dtbfn-extra'] != '':
+ bootcmd += 'setenv board ' + boardname + configs[args.configname]['dtbfn-extra'] + ' ; '
+ bootcmd += 'saveenv ; '
+ # To update the bootloader, reset.
+ # If wanting to run installer, set installer_args.configname in environment, 'run bootcmd'
+ bootcmd += 'reset'
+ print 'bootcmd:', bootcmd
+ cmd = 'fdtput -p -t s ' + u_boot_dtb_runflash + ' /config bootcmd "' + bootcmd + '"'
+ run(workdir, cmd)
+
+ u_boot_dtb_runflash_size = os.path.getsize(u_boot_dtb_runflash)
+ if args.debug:
+ print 'u_boot_dtb_runflash_size %d 0x%x' % (u_boot_dtb_runflash_size, u_boot_dtb_runflash_size)
+ pad_size -= (u_boot_dtb_runflash_size - u_boot_dtb_size)
+ if args.debug:
+ print 'pad_size %d 0x%x' % (pad_size, pad_size)
+
+ uboot_flasher = os.path.join(workdir, 'u-boot-flasher.bin')
+ f = open(uboot_flasher, 'wb')
+ shutil.copyfileobj(open(u_boot_no_dtb, 'rb'), f)
+ shutil.copyfileobj(open(u_boot_dtb_runflash, 'rb'), f)
+ f.write(chr(0) * pad_size)
+ shutil.copyfileobj(open(flash_img, 'rb'), f)
+ f.close()
+
+ cmd = 'tegrarcm --bct=' + bct + ' --bootloader=' + uboot_flasher + ' --loadaddr=0x%08x' % loadaddr
+
+ flasher_sh = os.path.join(workdir, 'flasher.sh')
+ f = open(flasher_sh, 'wt')
+ os.fchmod(f.fileno(), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
+ f.write("#!/bin/sh\n")
+ f.write("\n")
+ f.write(cmd)
+ f.write("\n")
+ f.close()
+
+ if not args.gen_only:
+ run(workdir, flasher_sh)
+ except:
+ raise
+ finally:
+ if args.save_work_dir:
+ print 'Not removing work directory:', workdir
+ else:
+ rmtree(workdir)
+
parser = argparse.ArgumentParser(description='Write an image to a Tegra board\'s flash')
parser.add_argument('--debug', action='store_true',
help='Turn on debugging prints')
@@ -134,117 +248,5 @@ load_configs(os.path.join(args.data_dir, 'configs'))
if args.list_confignames:
func_list_configs()
- sys.exit(0)
-
-find_config_dir()
-
-u_boot_no_dtb = os.path.join(out_board_dir, 'u-boot-nodtb-tegra.bin')
-u_boot_no_dtb_size = os.path.getsize(u_boot_no_dtb)
-if args.debug:
- print 'u_boot_no_dtb_size %d 0x%x' % (u_boot_no_dtb_size, u_boot_no_dtb_size)
-
-u_boot_dtb = os.path.join(out_board_dir, 'u-boot.dtb')
-u_boot_dtb_size = os.path.getsize(u_boot_dtb)
-if args.debug:
- print 'u_boot_dtb_size %d 0x%x' % (u_boot_dtb_size, u_boot_dtb_size)
-
-if args.flash_image:
- flash_img = args.flash_img
-else:
- flash_img = os.path.join(out_board_dir, configs[args.configname]['flash-image'])
-flash_img_size = os.path.getsize(flash_img)
-if args.debug:
- print 'flash_img_size %d 0x%x' % (flash_img_size, flash_img_size)
-
-bct = os.path.join(out_board_dir, configs[args.configname]['bct'])
-
-u_boot_plus_dtb_size = u_boot_no_dtb_size + u_boot_dtb_size
-if args.debug:
- print 'u_boot_plus_dtb_size %d 0x%x' % (u_boot_plus_dtb_size, u_boot_plus_dtb_size)
-
-# Add 32k in case 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 + (32 * 1024) + (4 * 1024) - 1) & ~((4 * 1024) - 1)
-if args.debug:
- print 'padded_size %d 0x%x' % (padded_size, padded_size)
-
-pad_size = padded_size - u_boot_plus_dtb_size
-if args.debug:
- print 'pad_size %d 0x%x' % (pad_size, pad_size)
-
-# 0x00108000 is CONFIG_SYS_TEXT_BASE in U-Boot, minus RAM base
-loadaddr = socs[socname]['ram-base'] + 0x00108000
-flash_image_addr = loadaddr + padded_size
-if args.debug:
- print 'flash_image_addr %d 0x%x' % (flash_image_addr, flash_image_addr)
-
-flash_type = configs[args.configname]['flash-type']
-if not gen_flashcmds.has_key(flash_type):
- print 'flash-type "%s" not yet supported' % flash_type
- sys.exit(1)
-gen_flashcmd = gen_flashcmds[flash_type]
-
-if args.work_dir:
- workdir = os.path.abspath(args.work_dir)
- mkdir(workdir)
else:
- workdir = tempfile.mkdtemp()
-try:
- u_boot_dtb_runflash = os.path.join(workdir, 'u-boot-runflash.dtb')
- cp(u_boot_dtb, u_boot_dtb_runflash)
-
- # -2; never delay or interrupt
- cmd = 'fdtput -p -t i ' + u_boot_dtb_runflash + ' /config bootdelay 0xfffffffe'
- run(workdir, cmd)
-
- bootcmd = ''
- if args.debug:
- bootcmd = 'crc32 0x%08x 0x%08x ; ' % (flash_image_addr, flash_img_size)
- bootcmd += gen_flashcmd(flash_image_addr, flash_img_size)
- bootcmd += 'env default -f -a ; '
- # Perhaps U-Boot should set $boardname based on the ID EEPROM; then we wouldn't need this
- if configs[args.configname]['dtbfn-extra'] != '':
- bootcmd += 'setenv board ' + boardname + configs[args.configname]['dtbfn-extra'] + ' ; '
- bootcmd += 'saveenv ; '
- # To update the bootloader, reset.
- # If wanting to run installer, set installer_args.configname in environment, 'run bootcmd'
- bootcmd += 'reset'
- print 'bootcmd:', bootcmd
- cmd = 'fdtput -p -t s ' + u_boot_dtb_runflash + ' /config bootcmd "' + bootcmd + '"'
- run(workdir, cmd)
-
- u_boot_dtb_runflash_size = os.path.getsize(u_boot_dtb_runflash)
- if args.debug:
- print 'u_boot_dtb_runflash_size %d 0x%x' % (u_boot_dtb_runflash_size, u_boot_dtb_runflash_size)
- pad_size -= (u_boot_dtb_runflash_size - u_boot_dtb_size)
- if args.debug:
- print 'pad_size %d 0x%x' % (pad_size, pad_size)
-
- uboot_flasher = os.path.join(workdir, 'u-boot-flasher.bin')
- f = open(uboot_flasher, 'wb')
- shutil.copyfileobj(open(u_boot_no_dtb, 'rb'), f)
- shutil.copyfileobj(open(u_boot_dtb_runflash, 'rb'), f)
- f.write(chr(0) * pad_size)
- shutil.copyfileobj(open(flash_img, 'rb'), f)
- f.close()
-
- cmd = 'tegrarcm --bct=' + bct + ' --bootloader=' + uboot_flasher + ' --loadaddr=0x%08x' % loadaddr
-
- flasher_sh = os.path.join(workdir, 'flasher.sh')
- f = open(flasher_sh, 'wt')
- os.fchmod(f.fileno(), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
- f.write("#!/bin/sh\n")
- f.write("\n")
- f.write(cmd)
- f.write("\n")
- f.close()
-
- if not args.gen_only:
- run(workdir, flasher_sh)
-except:
- raise
-finally:
- if args.save_work_dir:
- print 'Not removing work directory:', workdir
- else:
- rmtree(workdir)
+ func_flash()
--
1.8.1.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [[PATCH flasher] 6/6] Rework cmdline to use sub-commands
[not found] ` <1371079807-16541-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
` (3 preceding siblings ...)
2013-06-12 23:30 ` [[PATCH flasher] 5/6] Split flashing implementation into a separate function Stephen Warren
@ 2013-06-12 23:30 ` Stephen Warren
2013-06-13 22:15 ` [[PATCH flasher] 1/6] Move functions and data to start of file Stephen Warren
5 siblings, 0 replies; 8+ messages in thread
From: Stephen Warren @ 2013-06-12 23:30 UTC (permalink / raw)
To: swarren-3lzwWm7+Weoh9ZMKESR00Q
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Instead of using options like --list-confignames to select a specific
sub-command/operation to perform, and assuming a default command of flash
if none is specified, use explicit sub-commands.
Old: tegra-uboot-flasher --list-confignames
New: tegra-uboot-flasher list-configs
Old: tegra-uboot-flasher CONFIG
New: tegra-uboot-flasher flash CONFIG
Later changes will introduce more sub-commands, e.g. "exec" to simply
download and execute a bootloader.
Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
README-user.txt | 4 ++--
tegra-uboot-flasher | 50 +++++++++++++++++++++++++++++---------------------
2 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/README-user.txt b/README-user.txt
index ce4eaf3..249a096 100644
--- a/README-user.txt
+++ b/README-user.txt
@@ -18,7 +18,7 @@ harmony, cardhu-a02-1gb.config, cardhu-a04-1gb.config.
You may find a list of valid values for configname by executing:
-tegra-uboot-flasher --list-confignames
+tegra-uboot-flasher list-configs
Simple Usage
============
@@ -27,7 +27,7 @@ To flash a board, connect a USB cable from your host PC to the Tegra device,
place that board into USB recovery mode, and execute the following as root
on the host machine:
-tegra-uboot-flasher configname
+tegra-uboot-flasher flash CONFIG
This will download code and data to the Tegra device and execute a flashing
routine. Once this is complete, the system will reboot into the freshly
diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
index 630b0fb..aae7f19 100755
--- a/tegra-uboot-flasher
+++ b/tegra-uboot-flasher
@@ -204,26 +204,37 @@ def func_flash():
else:
rmtree(workdir)
-parser = argparse.ArgumentParser(description='Write an image to a Tegra board\'s flash')
+parser = argparse.ArgumentParser(description='Execute a bootloader on a ' +
+ 'Tegra board, possibly modifying it prior to download so as to execute ' +
+ 'commands, such as writing an image to flash.')
+
parser.add_argument('--debug', action='store_true',
- help='Turn on debugging prints')
+ help='Turn on debugging prints')
parser.add_argument('--data-dir', type=str,
- help='The directory containing board data')
-parser.add_argument('--work-dir', type=str,
- help='The temporary directory used during operation')
-parser.add_argument('--save-work-dir', action='store_true',
- help='Don\'t delete the work-dir after execution')
-parser.add_argument('--flash-image', type=str,
- help='The flash image to write, instead of U-Boot itself')
-parser.add_argument('--gen-only', action='store_true',
- help='Just create the work-dir; don\'t actually flash the image')
+ help='The directory containing board data')
parser.add_argument('--force-no-out-dir', action='store_true',
- help='Don\'t check for ../_out* directories used in source tree')
-group = parser.add_mutually_exclusive_group(required=True)
-group.add_argument('--list-confignames', action='store_true',
- help='List known configuration names, and exit')
-group.add_argument('configname', type=str, nargs='?',
- help='The configuration name of the board')
+ help='Don\'t check for ../_out* directories used in source tree')
+
+subparsers = parser.add_subparsers()
+
+parser_list_configs = subparsers.add_parser('list-configs',
+ help='List known board configurations')
+parser_list_configs.set_defaults(func = func_list_configs)
+
+parser_flash = subparsers.add_parser('flash',
+ help='Write an image, usually U-Boot itself, to flash on the device')
+parser_flash.set_defaults(func = func_flash)
+parser_flash.add_argument('--work-dir', type=str,
+ help='The temporary directory used during operation')
+parser_flash.add_argument('--save-work-dir', action='store_true',
+ help='Don\'t delete the work-dir after execution')
+parser_flash.add_argument('--flash-image', type=str,
+ help='The flash image to write, instead of U-Boot itself')
+parser_flash.add_argument('--gen-only', action='store_true',
+ help='Just create the work-dir; don\'t actually flash the image')
+parser_flash.add_argument('configname', metavar='CONFIG', type=str,
+ help='The configuration name of the board')
+
args = parser.parse_args()
if args.debug: print args
@@ -246,7 +257,4 @@ if not args.data_dir:
load_configs(os.path.join(args.data_dir, 'configs'))
-if args.list_confignames:
- func_list_configs()
-else:
- func_flash()
+args.func()
--
1.8.1.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [[PATCH flasher] 2/6] Separate out validation of config name
[not found] ` <1371079807-16541-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2013-06-13 18:36 ` Thierry Reding
0 siblings, 0 replies; 8+ messages in thread
From: Thierry Reding @ 2013-06-13 18:36 UTC (permalink / raw)
To: Stephen Warren; +Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
[-- Attachment #1: Type: text/plain, Size: 1482 bytes --]
On Wed, Jun 12, 2013 at 05:30:03PM -0600, Stephen Warren wrote:
[...]
> diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
> index 447ff37..ef73e2f 100755
> --- a/tegra-uboot-flasher
> +++ b/tegra-uboot-flasher
> @@ -75,6 +75,17 @@ gen_flashcmds = {
> 'spi': gen_flashcmd_spi,
> }
>
> +def find_config_dir():
> + if not configs.has_key(args.configname):
> + print 'Unknown config "%s"' % args.configname
> + sys.exit(1)
> +
> + global boardname, socname, out_board_dir
Python supports returning touples, so maybe globals can be avoided here?
> +
> + boardname = configs[args.configname]['board']
> + socname = boards[boardname]['soc']
> + out_board_dir = os.path.join(args.data_dir, boardname)
> +
> parser = argparse.ArgumentParser(description='Write an image to a Tegra board\'s flash')
> parser.add_argument('--debug', action='store_true',
> help='Turn on debugging prints')
> @@ -122,14 +133,7 @@ if args.list_confignames:
> print configname
> sys.exit(0)
>
> -if not configs.has_key(args.configname):
> - print 'Unknown config "%s"' % args.configname
> - sys.exit(1)
> -
> -boardname = configs[args.configname]['board']
> -socname = boards[boardname]['soc']
> -
> -out_board_dir = os.path.join(args.data_dir, boardname)
> +find_config_dir()
So this'll turn into something like:
boardname, socname, out_board_dir = find_config_dir()
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [[PATCH flasher] 1/6] Move functions and data to start of file
[not found] ` <1371079807-16541-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
` (4 preceding siblings ...)
2013-06-12 23:30 ` [[PATCH flasher] 6/6] Rework cmdline to use sub-commands Stephen Warren
@ 2013-06-13 22:15 ` Stephen Warren
5 siblings, 0 replies; 8+ messages in thread
From: Stephen Warren @ 2013-06-13 22:15 UTC (permalink / raw)
To: Stephen Warren; +Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren
On 06/12/2013 05:30 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>
> Future changes will create separate functions for the sub-commands that
> tegra-uboot-flasher implements. This change prepares for that by moving
> other functions away from what will be the body of some of those
> functions.
Applied (the series), on github.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-06-13 22:15 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-12 23:30 [[PATCH flasher] 1/6] Move functions and data to start of file Stephen Warren
[not found] ` <1371079807-16541-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-06-12 23:30 ` [[PATCH flasher] 2/6] Separate out validation of config name Stephen Warren
[not found] ` <1371079807-16541-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-06-13 18:36 ` Thierry Reding
2013-06-12 23:30 ` [[PATCH flasher] 3/6] Split list-confignames implementation into a separate function Stephen Warren
2013-06-12 23:30 ` [[PATCH flasher] 4/6] Add parameters to gen_flashcmd_* Stephen Warren
2013-06-12 23:30 ` [[PATCH flasher] 5/6] Split flashing implementation into a separate function Stephen Warren
2013-06-12 23:30 ` [[PATCH flasher] 6/6] Rework cmdline to use sub-commands Stephen Warren
2013-06-13 22:15 ` [[PATCH flasher] 1/6] Move functions and data to start of file Stephen Warren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox