Commit 5f4bb7de authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

update software

parent 8a1d6ea4
# Runs 'make', 'make install', and 'make clean' in specified subdirectories # Runs 'make', 'make install', and 'make clean' in specified subdirectories
SUBDIRS := src/php_top src/python_tests src/debugfs-webgui src/jp4-canvas # src1 SUBDIRS := src/php_top src/python_tests src/debugfs-webgui src/jp4-canvas src/update # src1
INSTALLDIRS = $(SUBDIRS:%=install-%) INSTALLDIRS = $(SUBDIRS:%=install-%)
CLEANDIRS = $(SUBDIRS:%=clean-%) CLEANDIRS = $(SUBDIRS:%=clean-%)
......
DOCUMENTROOT=$(DESTDIR)/www/pages
OWN = -o root -g root
INSTDOCS = 0644
INSTALL = install
DOCS= update_nand.php \
update_software.html \
update_software.js \
update_software.php
LIB_DIR= fileupload
LIBS= $(LIB_DIR)/jquery.fileupload.css \
$(LIB_DIR)/jquery.fileupload.js \
$(LIB_DIR)/jquery.iframe-transport.js \
$(LIB_DIR)/style.css \
$(LIB_DIR)/UploadHandler.php
all:
@echo "make all in src"
install:
@echo "make install in src"
$(INSTALL) $(OWN) -d $(DOCUMENTROOT) $(DOCUMENTROOT)/js $(DOCUMENTROOT)/js/$(LIB_DIR)
$(INSTALL) $(OWN) -m $(INSTDOCS) $(DOCS) $(DOCUMENTROOT)
$(INSTALL) $(OWN) -m $(INSTDOCS) $(LIBS) $(DOCUMENTROOT)/js/$(LIB_DIR)
clean:
@echo "make clean in src"
This diff is collapsed.
@charset "UTF-8";
/*
* jQuery File Upload Plugin CSS
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
.fileinput-button {
position: relative;
overflow: hidden;
display: inline-block;
}
.fileinput-button input {
position: absolute;
top: 0;
right: 0;
margin: 0;
opacity: 0;
-ms-filter: 'alpha(opacity=0)';
font-size: 200px !important;
direction: ltr;
cursor: pointer;
}
/* Fixes for IE < 8 */
@media screen\9 {
.fileinput-button input {
filter: alpha(opacity=0);
font-size: 100%;
height: 100%;
}
}
This diff is collapsed.
This diff is collapsed.
@charset "UTF-8";
/*
* jQuery File Upload Plugin CSS Example
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
body {
padding-top: 60px;
}
<?php
# hardcoded
$UPDATE_DIR = "/var/volatile/html/update";
$NAND_PATH = "/tmp/rootfs.ro";
$FLASH_LOG = "/var/volatile/html/flash.log";
$FLASH_LOG_LINK = "var/flash.log";
$UBI_MNT = "/tmp/ubi0";
$BKP_NAME = "elphel393_backup.tar.gz";
$BKP_DIR = "/etc/elphel393";
# update files
# file, expertise level, nand partition, size - see http://wiki.elphel.com/index.php?title=NAND_flash_boot_rootfs
# partitions are also listed in the device tree
# WARNING: DO NOT CHANGE
$UPDATE_LIST = array(
array(0,"boot.bin", "/dev/mtd0","0 2"),
array(0,"u-boot-dtb.img","/dev/mtd1","0 8"),
array(0,"devicetree.dtb","/dev/mtd2","0 8"),
array(0,"uImage", "/dev/mtd3","0 128"),
array(1,"rootfs.tar.gz", "",""),
array(0,"rootfs.ubi", "/dev/mtd4","0 2048","-s 2048 -O 2048"),
array(1,"rootfs.ubifs", "/dev/mtd4","/dev/ubi_ctrl -m 4","ubiupdatevol /dev/ubi0_0"),
);
//respond_xml($updatedir);
function lookup_name($name){
global $UPDATE_LIST;
foreach($UPDATE_LIST as $e){
if ($name==$e[1]) return $e;
}
return false;
}
function verify($v){
global $UPDATE_DIR;
global $NAND_PATH;
global $UPDATE_LIST;
$safe_list = array();
if (is_dir($UPDATE_DIR)){
foreach(scandir($UPDATE_DIR) as $e){
$tmp = lookup_name($e);
if ($tmp!=false){
if ($tmp[0]==0){
array_push($safe_list,$tmp);
}
}
}
}
if (count($safe_list)==0){
$tmp = "";
foreach($UPDATE_LIST as $e){
if($e[0]==0){
$tmp .= "<li>${e[1]}</li>";
}
}
backup_note();
$msg = <<<TXT
<b style='color:red;'>ERROR</b>: Files not found. Accepted files are:
<ul>
$tmp
</ul>
TXT;
die($msg);
}else{
$tmp = "";
foreach($safe_list as $e){
$tmp .= "<li>{$e[1]}</li>";
}
if ($v) printf("Files to be flashed:<ul>$tmp</ul>");
}
//$safe_list is ready
if (is_dir($NAND_PATH)){
backup_note();
die("<b style='color:red'>ERROR</b>: Please boot from mmc (<a href='http://wiki.elphel.com/index.php?title=Tmp_manual#Boot'>instructions</a>)");
}else{
if ($v) {
backup_note();
printf("<span style='color:green'>Ready for flashing.</span>");
}
}
return $safe_list;
}
function backup_note(){
$tmp = strrpos($_SERVER['SCRIPT_NAME'],"/");
if ($tmp==0)
$base = $_SERVER['SCRIPT_NAME'];
else
$base = substr($_SERVER['SCRIPT_NAME'],0,$tmp+1);
print("<b>NOTE</b>: If flashing rootfs, please download a backup copy of <a href='$base?cmd=backup'>/etc/elphel393</a><br/>");
}
function nandflash($list){
global $UPDATE_DIR;
global $FLASH_LOG;
global $FLASH_LOG_LINK;
foreach($list as $e){
if ($e[0]==0){
exec("flash_unlock ${e[2]} >> $FLASH_LOG");
exec("flash_erase ${e[2]} ${e[3]} >> $FLASH_LOG");
if ($e[1]!="rootfs.ubi")
exec("nandwrite -n ${e[2]} -p $UPDATE_DIR/${e[1]} >> $FLASH_LOG");
else
exec("ubiformat ${e[2]} -f $UPDATE_DIR/${e[1]} ${e[4]} >> $FLASH_LOG");
}
}
print("Done. See/Download <a href='$FLASH_LOG_LINK'>flash.log</a>. Then power cycle.");
}
function backup(){
global $NAND_PATH;
global $UBI_MNT;
global $BKP_NAME;
global $BKP_DIR;
if (!is_dir($NAND_PATH)){
exec("flash_unlock /dev/mtd4");
exec("ubiattach /dev/ubi_ctrl -m 4");
if (!is_dir($UBI_MNT)) mkdir($UBI_MNT);
exec("mount -t ubifs -o ro /dev/ubi0_0 $UBI_MNT");
exec("tar -czvf var/$BKP_NAME -C ${UBI_MNT}${BKP_DIR} .");
exec("umount $UBI_MNT");
if (is_dir($UBI_MNT)) rmdir($UBI_MNT);
exec("ubidetach /dev/ubi_ctrl -m 4");
}else{
//booted from nand
exec("tar -czvf var/$BKP_NAME -C ${BKP_DIR} .");
}
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename='.$BKP_NAME);
print(file_get_contents("var/$BKP_NAME"));
}
function remove(){
global $UPDATE_DIR;
exec("rm -rf $UPDATE_DIR/*; sync");
backup_note();
print("<b>NOTE</b>: All files have been removed from <b>$UPDATE_DIR</b>.");
}
$cmd = "donothing";
if (isset($_GET['cmd']))
$cmd = $_GET['cmd'];
else if (isset($argv[1]))
$cmd = $argv[1];
switch($cmd){
case "flash":
$flash_list = verify(false);
nandflash($flash_list);
break;
case "backup":
backup();
break;
case "remove":
remove();
break;
default:
verify(true);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="author" content="?"/>
<link rel="stylesheet" href="js/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="js/fileupload/style.css">
<link rel="stylesheet" href="js/fileupload/jquery.fileupload.css">
<script src="js/jquery-2.2.3.min.js"></script>
<script src="js/jquery-ui/jquery-ui.min.js"></script>
<script src="js/fileupload/jquery.iframe-transport.js"></script>
<script src="js/fileupload/jquery.fileupload.js"></script>
<script src="js/bootstrap/js/bootstrap.min.js"></script>
<script src="update_software.js"></script>
</head>
<body onload='init()' style='padding-top:0px;'>
<h2 id='title' style='padding-left:10px;'>Update software:</h2>
<div id='test' style='padding:10px;'>
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Select files...</span>
<!-- The file input field used as target for the file upload widget -->
<input id="fileupload" type="file" name="files[]" multiple>
</span>
<span id='btn_remove' class="btn btn-danger"><b>Remove files</b></span>
<br>
<br>
<!-- The global progress bar -->
<div id="progress" class="progress" style='width:250px;'>
<div class="progress-bar progress-bar-success"></div>
</div>
<!-- The container for the uploaded files -->
<div id="files" class="files"></div>
</div>
<div style='padding-left:10px;'>
<span id='btn_verify' class="btn btn-success"><b>Verify</b></span>
<span id='btn_flash' class="btn btn-danger"><b>Flash</b></span>
<span style='padding-left:10px;'><a href='var/flash.log'>flash.log</a></span>
</div>
<div style='padding:10px;'>
<div id='status' class='blink'></div>
</div>
</body>
</html>
/*
FILE NAME : debugfs.js
DESCRIPTION: dynamic debug frontend
REVISION: 1.00
AUTHOR: Oleg Dzhimiev <oleg@elphel.com>
LICENSE: AGPL, see http://www.gnu.org/licenses/agpl.txt
Copyright (C) 2016 Elphel, Inc.
*/
var blink_intvl;
function init(){
console.log("init");
var url = "update_software.php";
$('#fileupload').fileupload({
url: url,
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo('#files');
});
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css(
'width',
progress + '%'
);
}
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined :'disabled');
$('#btn_remove').click(function(){
$.ajax({
url: "update_nand.php?cmd=remove",
success: function(result){
$("#status").html(result);
}
});
});
$('#btn_verify').click(function(){
$.ajax({
url: "update_nand.php",
success: function(result){
$("#status").addClass("blink").html(result);
}
});
});
$('#btn_flash').click(function(){
$("#status").html("Flashing...");
blink_intvl = setInterval(blink,1000);
$.ajax({
url: "update_nand.php?cmd=flash",
success: function(result){
clearInterval(blink_intvl);
$("#status").html(result);
}
});
});
}
function blink(){
$('.blink').fadeOut(500);
$('.blink').fadeIn(500);
}
function upload(){
console.log("upload");
}
\ No newline at end of file
<?php
/*
* jQuery File Upload Plugin PHP Example
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
error_reporting(E_ALL | E_STRICT);
require('js/fileupload/UploadHandler.php');
$upload_handler = new UploadHandler();
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment