All of lore.kernel.org
 help / color / mirror / Atom feed
* [flasher PATCH 1/2] Switch flasher script to subprocess
@ 2014-07-02 17:32 Stephen Warren
       [not found] ` <1404322363-11580-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Warren @ 2014-07-02 17:32 UTC (permalink / raw)
  To: swarren-3lzwWm7+Weoh9ZMKESR00Q
  Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA, Stephen Warren

From: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

This avoids any issues re: quoting the commands we execute, such as
fdtput to modify the DTB sent to the flashing process.

The build script already uses subprocess, so this doesn't introduce any
new dependencies overall.

Signed-off-by: Stephen Warren <swarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 tegra-uboot-flasher | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/tegra-uboot-flasher b/tegra-uboot-flasher
index ded8d171a14a..c9adba607c69 100755
--- a/tegra-uboot-flasher
+++ b/tegra-uboot-flasher
@@ -26,6 +26,7 @@ import os
 import os.path
 import shutil
 import stat
+import subprocess
 import sys
 import tempfile
 from tegraboardconfigs import *
@@ -42,15 +43,10 @@ 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 run(cd, cmd):
+    print '+ cd', cd
+    print '+', ' '.join(cmd)
+    subprocess.check_call(cmd, cwd=cd)
 
 def gen_flashcmd_mmc(flash_image_addr, readback_addr, flash_img_size):
     flash_id = config['flash-id-uboot']
@@ -97,7 +93,7 @@ def get_loadaddr():
 def gen_tegrarcm_cmd(bootloader, loadaddr):
     if type(loadaddr) != str:
         loadaddr = "0x%08x" % loadaddr
-    return 'tegrarcm --bct=' + bct + ' --bootloader=' + bootloader + ' --loadaddr=' + loadaddr
+    return ['tegrarcm', '--bct=' + bct, '--bootloader=' + bootloader , '--loadaddr=' + loadaddr]
 
 def find_config_dir():
     if not configs.has_key(args.configname):
@@ -198,8 +194,8 @@ def func_flash():
         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'
+        # 0xfffffffe==-2; never delay or interrupt
+        cmd = ['fdtput', '-p', '-t', 'i', u_boot_dtb_runflash, '/config', 'bootdelay', '0xfffffffe']
         run(workdir, cmd)
 
         bootcmd = ''
@@ -224,7 +220,7 @@ def func_flash():
         # 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 + '"'
+        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)
@@ -249,12 +245,12 @@ def func_flash():
         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(' '.join(cmd))
         f.write("\n")
         f.close()
 
         if not args.gen_only:
-            run(workdir, flasher_sh)
+            run(workdir, [flasher_sh])
     except:
         raise
     finally:
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-07-21 15:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-02 17:32 [flasher PATCH 1/2] Switch flasher script to subprocess Stephen Warren
     [not found] ` <1404322363-11580-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-07-02 17:32   ` [flasher PATCH 2/2] Wrap any env var settings in quotes Stephen Warren
     [not found]     ` <1404322363-11580-2-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-07-02 18:42       ` Andreas Färber
     [not found]         ` <53B45286.9050408-l3A5Bk7waGM@public.gmane.org>
2014-07-02 18:46           ` Stephen Warren
2014-07-02 23:18   ` [flasher PATCH 1/2] Switch flasher script to subprocess Stephen Warren
     [not found]     ` <CA+G9XgdAAMttS66oscdY15jUns+ojOJ4-ny0eRfFYO6PXBNXCg@mail.gmail.com>
     [not found]       ` <CA+G9XgdAAMttS66oscdY15jUns+ojOJ4-ny0eRfFYO6PXBNXCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-07-21 15:42         ` Stephen Warren

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.