Advertisement
Guest User

dahua-rus

a guest
Nov 2nd, 2016
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 KB | None | 0 0
  1. --
  2. -- Copyright (C) 2005 dahua Technologies, All Rights Reserved.
  3. -- 2006-4-25 15:54 Z:\wjj\ven\152\DAHUA\Install.lua
  4. -- 2006-9-21 modified by zhongjl for new partition
  5. --
  6.  
  7. -- Flash 块的大小为64K
  8. local flashSectorSize = 0x20000;
  9.  
  10. local Installer = {};
  11. Installer.TotalSize = 0; -- 总的要写到Flash中的数据大小
  12. Installer.InProgressSize = 0; -- 用来在升级过程中控制进度
  13.  
  14. -- 通知上层应用程序升级的进度信息
  15. -- params:
  16. -- 无
  17. -- return:
  18. -- 无
  19. function Installer:notify()
  20. self.InProgressSize = self.InProgressSize + flashSectorSize;
  21.  
  22. local progress = self.InProgressSize / self.TotalSize * 100;
  23. if(progress > 100) then
  24. progress = 100;
  25. end;
  26. progress = tonumber(string.format("%d", progress));
  27.  
  28. -- 注意调用方式,不是self::callback,否则会导致回调出错
  29. self.callback(0x01, progress);
  30. end
  31.  
  32. -- 根据应用程序提供的信息判断是否可以升级
  33. -- params:
  34. -- 无
  35. -- return:
  36. -- 成功返回True, 失败返回False以及失败的原因
  37. function Installer:preInstall()
  38. -- 这里我们需要考虑那些因数?
  39. -- 硬件版本号 ?
  40. -- 原有软件的版本号?
  41. --
  42. local board = Global.Hardware.board;
  43. local hwproduct;
  44. local hwchannel;
  45. local hwversion;
  46. local hwfunction;
  47.  
  48. print(string.format("Checking hardware information,board name:%s version:%s",
  49. board.name, board.version));
  50. -- if(board.name ~= "DVRxx04HF-X-4H") then
  51. -- return false, "Invalid board";
  52. -- end
  53.  
  54. --升级程序直接从硬件中取值。意义如下
  55. --hwproduct取值如下: 2 -- LB; 3 -- LBN; 4 -- LB_ATM; 5 -- GBE; 6 -- LK; 7 -- LS
  56. --hwproduct取值如下: 2 -- IPC4X5; 3 -- A6; 4 -- A8; 5 -- IPVM;
  57. --hwchannel取值如下: x -- x chans
  58. --hwfunction取值如下: 0 -- AUDIO; 1 -- MATRIX; 3 -- LOOP
  59.  
  60. if(mtd.getinfo)then
  61. hwproduct,hwchannel,hwversion,hwfunction = mtd.getinfo();
  62. print(string.format("Checking hardware id info: product = %x; channel = %x; version = %x; function = %x",
  63. hwproduct,hwchannel,hwversion,hwfunction));
  64. if((hwproduct ~= 3) and (hwproduct ~= 4)) then
  65. print(string.format("product not match"));
  66. return false, "Invalid board";
  67. end
  68. end
  69.  
  70. -- 这里我们需要校验不同板本的板子程序是否可以通用,
  71. -- 如目前LB 1.22的与 LB 2.00的板子就不能通用
  72. -- if(board.version ~= "1.22") then
  73. -- print(string.format("XXXXXXXXXXXX"));
  74. -- return false, "Invalid board version";
  75. -- end
  76.  
  77. local vendor = Global.Vendor;
  78.  
  79. -- if(vendor.Name ~= 'General_N6' and vendor.Name ~= 'DAHUA') then
  80. -- return false, "Invalid vendor";
  81. -- end
  82.  
  83. return true;
  84. end
  85.  
  86. -- 升级完成后的处理,如控制系统重启
  87. -- params:
  88. -- 无
  89. -- return:
  90. -- 无
  91. function Installer:postInstall()
  92. end
  93.  
  94. -- 升级Flash分区,对于不同的应用,升级的处理可能不一样
  95. -- params :
  96. -- part : 表格,包含分区的起始位置以及结束位置
  97. -- filename : 在升级包中的文件名
  98. -- return : 无
  99. function Installer:updatePart(part, filename)
  100. local myfile = self.ZipArchive:open(filename);
  101. -- 如果该文件打不开,则不需要对此部分进行升级
  102. if(not myfile) then
  103. print(string.format("%s not exist", filename));
  104. return ;
  105. end
  106.  
  107. local addr = part.baseAddr;
  108. local endAddr= part.endAddr;
  109. local data;
  110. local fldata;
  111.  
  112. -- 跳过前面64字节的头,在新的升级程序版本中不需要对此进行校验
  113. myfile:seek("set", 64);
  114. while(addr < endAddr) do
  115. fldata = mtd.read(addr,flashSectorSize);
  116. data = myfile:read(flashSectorSize); -- 读入一块Flash扇区大小的数据
  117.  
  118. -- if (fldata and data and (fldata ~= data)) then
  119. -- 当fldata为空的时候为老的程序,直接擦除
  120.  
  121. if(data) then
  122. if((not fldata) or (data and (fldata ~= data))) then
  123. mtd.erase(addr);
  124. mtd.write(addr, data);
  125. end
  126. self:notify();
  127. addr = addr + flashSectorSize;
  128. else
  129. addr = endAddr;
  130. end
  131. end
  132.  
  133. myfile:close();
  134. end
  135.  
  136. function Installer:InstallPlayer(filename)
  137. local myfile = self.ZipArchive:open(filename);
  138.  
  139. -- 如果该文件打不开,则不需要对此部分进行升级
  140. if(not myfile) then
  141. return ;
  142. end
  143.  
  144. --
  145. -- TODO:
  146. -- 读入自动播放器的内容,通过IDE接口写入到硬盘
  147. --
  148. end
  149.  
  150. -- 在这里控制整个升级过程
  151. -- params:
  152. -- 无
  153. -- return:
  154. -- 成功返回True,失败返回Flase以及错误原因
  155. function Installer:execute()
  156. --[[
  157. 分区配置信息表,来自知识库 "Flash 分区规划"
  158. 0xa0000000 - 0xa0040000 256K armboot u-boot
  159. 0xa0060000 - 0xa0460000 4096K kernel + root romfs
  160. 0xa0460000 - 0xa0a60000 6144K application + modules user
  161. 0xa0a60000 - 0xa0c60000 1536K web web
  162. 0xa0c60000 - 0xa0e60000 2560K slave:romfs + kernel + pcidriver slave
  163. 0xa0e60000 - 0xa0e80000 128K custom custom
  164. 0xa0e80000 - 0xa0ec0000 256K logo logo
  165. 0xa0ec0000 - 0xa0f40000 1024K config
  166. 0xa0f40000 - 0xa1000000 1024K config1
  167. ]]
  168.  
  169. local flashPartions =
  170. {
  171. boot = { baseAddr = 0xa0000000 , endAddr = 0xa0040000 },
  172. rootfs = { baseAddr = 0xa0060000 , endAddr = 0xa0CE0000 },
  173. web = { baseAddr = 0xa0CE0000 , endAddr = 0xa0E60000 },
  174. custom = { baseAddr = 0xa0E60000 , endAddr = 0xa0E80000 },
  175. logo = { baseAddr = 0xa0E80000 , endAddr = 0xa0EC0000 },
  176. config = { baseAddr = 0xa0EC0000 , endAddr = 0xa0f40000 },
  177. config1 = { baseAddr = 0xa0f40000 , endAddr = 0xa1000000 },
  178. }
  179.  
  180. -- self.ZipArchive 这个变量由外部程序设置,如果没有设置程序不应该运行到这里
  181. assert(self.ZipArchive);
  182. local zfile = self.ZipArchive;
  183.  
  184. local ret, info = self:preInstall();
  185. if(not ret) then
  186. return false, info;
  187. end
  188.  
  189. -- 计算要升级的文件大小以及打印升级文件清单
  190. local TotalSize = 0;
  191. print("==>Files in archive");
  192. for file in zfile:files() do
  193. print(file.filename);
  194. TotalSize = TotalSize + file.uncompressed_size;
  195. end
  196. self.TotalSize = TotalSize; -- 总的文件大小
  197. mtd.init();
  198. self:updatePart(flashPartions["boot"], "u-boot.bin.img");
  199. --mtd.saveenv();
  200. self:updatePart(flashPartions["rootfs"], "romfs-x.cramfs.img");
  201. --self:updatePart(flashPartions["user"], "user-x.cramfs.img");
  202. self:updatePart(flashPartions["web"], "web-x.cramfs.img");
  203. --self:updatePart(flashPartions["slave"], "slave-x.cramfs.img");
  204. self:updatePart(flashPartions["custom"], "custom-x.cramfs.img");
  205. self:updatePart(flashPartions["logo"], "logo-x.cramfs.img");
  206. --self:InstallPlayer("autoplayer.bin");
  207. self:postInstall();
  208. print("==>Upgrade finished.");
  209. return true;
  210. end
  211.  
  212. return Installer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement