====== Oxocards ======
====== Infos ======
Unter Linux müssen noch esptool.py und ampy installiert werden.
Backup der Oxocard (keine Ahnung, wie gross der belegte Speicher ist, hier mal 3M). Ein Modell, dass ich geklont hatte, hatte eine Flashgrösse von ca. 1877392 Bytes (1.8MB). Das image (3M) ist da (wird beim flashen komprimiert): {{ :techlab:projekte:oxocard-orig.img |}}
esptool.py -p /dev/ttyUSB0 read_flash 0 3000000 oxocard-orig.img
Download der TigerJython-Dateien für die Oxocard:
wget http://www.tigerjython4kids.ch/download/MicroPython.bin
wget http://www.tigerjython4kids.ch/download/oxocardmodules.zip
Flashen des ESP32:
esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 --chip esp32 write_flash -z 0x1000 MicroPython.bin
Kopieren der Python-Dateien (aus der zip-Datei)
for a in *.py; do ampy -p /dev/ttyUSB0 put $a; echo $a; done
Backup wieder einspielen:
esptool.py --port /dev/ttyUSB0 write_flash 0 oxocard-orig.img
Oder Factory reset:
wget http://www.tigerjython4kids/download/blockly_flash.zip
esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 --chip esp32 write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader_blockly.bin 0xe000 phy_init_data_blockly.bin 0x10000 OxocardBlockly.bin 0x8000 partitions_blockly.bin
====== Scripts ======
Die obigen Zeilen sind in folgende Scripts eingearbeitet:
#!/usr/bin/ruby
$oxodir="/data/oxocard"
def ex(cmd)
puts cmd
res = system(cmd)
if (res==nil)
puts "Could not even run the command #{cmd}. Aborting."
exit(-1)
end
return res
end
def trycmd(cmd, n=2)
n.times {
return true if ex(cmd)
puts "command returned an error, trying again in 2 sec.."
sleep(2)
}
puts "Executing #{cmd} returned an error. Aborting."
exit(-1)
end
def dl(url, force=false)
file = File.basename(url)
ext = file.rindex(".")
file = file[0...ext]+"-"+Time.now.strftime("%F")+file[ext..-1]
if File.exists?(file) and !force
puts "File #{file} already exists. Not downloading again. (use -f to force)"
else
unless ex("curl -L #{url} > #{$oxodir}/#{file}")
ex("rm -f #{$oxodir}/#{file}")
puts "Could not download from #{url}, aborting."
exit(-1)
end
end
end
force = (ARGV[0]=="-f")
puts "Downloading TigerJython Images to #{$oxodir}"
dl("https://www.tigerjython4kids.ch/download/MicroPython.bin", force)
dl("https://www.tigerjython4kids.ch/download/oxocardmodules.zip", force)
dl("https://www.tigerjython4kids.ch/download/blockly_flash.zip", force)
#!/usr/bin/ruby
$oxodir="/data/oxocard"
$port = "/dev/ttyUSB0"
def ex(cmd)
puts cmd
res = system(cmd)
if (res==nil)
puts "Could not even run the command #{cmd}. Aborting."
exit(-1)
end
return res
end
def trycmd(cmd, n=2)
n.times {
return true if ex(cmd)
puts "command returned an error, trying again in 2 sec.."
sleep(2)
}
puts "Executing #{cmd} returned an error. Aborting."
exit(-1)
end
def checkForFile(glob)
files = Dir.glob(glob)
if files.size==0
puts "No file of pattern #{glob} found. Attempting downloading it..."
trycmd("ruby #{$oxodir}/bin/download-images.rb",1)
files = Dir.glob(glob)
if files.size==0
puts "Sorry, cannot get file of pattern #{glob}, aborting now."
exit(-1)
end
end
return File.realpath(files.max_by {|f| File.mtime(f)})
end
def flash_tiger()
# Flashing MicroPython
file=checkForFile("#{$oxodir}/MicroPython*.bin")
puts "Using most recent file #{file}"
trycmd("esptool.py --port #{$port} erase_flash")
trycmd("esptool.py --port #{$port} --chip esp32 write_flash -z 0x1000 #{file}")
# TigerJython python modules
file=checkForFile("#{$oxodir}/oxocardmodules*.zip")
puts "Using most recent file #{file}"
zipdir = "#{$oxodir}/oxocardmodules"
ex("rm -rf #{zipdir}; mkdir #{zipdir}")
trycmd("cd #{zipdir}; unzip #{file}",1)
Dir.glob("#{zipdir}/*.py").sort.each{|f|
trycmd("ampy -p #{$port} put '#{File.realpath(f)}'",3)
}
end
def flash_blockly()
file=checkForFile("#{$oxodir}/blockly_flash*.zip")
puts "Using most recent file #{file}"
zipdir = "#{$oxodir}/blockly"
trycmd("rm -rf #{zipdir}",1)
trycmd("cd #{zipdir}; unzip -o #{file}",1)
trycmd("esptool.py --port #{$port} erase_flash",2)
trycmd("cd #{zipdir}; esptool.py --port #{$port} --chip esp32 write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader_blockly.bin 0xe000 phy_init_data_blockly.bin 0x10000 OxocardBlockly.bin 0x8000 partitions_blockly.bin",3)
end
if ARGV.size==0
puts "Usage: ruby flash-image.rb t[iger]|b[lockly]"
exit
end
if ARGV[0]=~/^[Tt]/
flash_tiger()
elsif ARGV[0]=~/^[Bb]/
flash_blockly
else
puts "Usage: ruby flash-image.rb t[iger]|b[lockly]"
end