Author: titmuss
Date: Fri Jan 2 10:02:34 2009
New Revision: 3664
URL: http://svn.slimdevices.com?rev=3664&root=Jive&view=rev
Log:
Bug: N/A
Description:
Port changes r3560,r3652 to trunk.
Modified:
7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua
7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua
Modified:
7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua?rev=3664&root=Jive&r1=3663&r2=3664&view=diff
==============================================================================
---
7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua
(original)
+++
7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeMTD.lua
Fri Jan 2 10:02:34 2009
@@ -32,6 +32,7 @@
_mtd = {},
_size = {},
_checksum = "",
+ _boardVersion = "",
})
return obj
@@ -50,6 +51,13 @@
callback(false, "UPDATE_DOWNLOAD", "")
+ -- parse the board revision
+ t, err = self:parseCpuInfo()
+ if not t then
+ log:warn("parseCpuInfo failed")
+ return nil, err
+ end
+
-- parse the flash devices
t, err = self:parseMtd()
if not t then
@@ -57,15 +65,6 @@
return nil, err
end
- -- parse the kernel version
- self._zImageExtraVersion = "zImage-P7"
- self._mtd[self._zImageExtraVersion] = self._mtd["zImage"]
- t, err = self:parseVersion()
- if not t then
- log:warn("parseVersion failed")
- return nil, err
- end
-
-- disable VOL+ on boot
t, err = self:fw_setenv({ sw7 = "" })
if not t then
@@ -74,7 +73,7 @@
end
-- erase flash
- t, err = self:flashErase(self._zImageExtraVersion)
+ t, err = self:flashErase("zImage")
if not t then
log:warn("flash kernel failed")
return nil, err
@@ -96,7 +95,7 @@
callback(false, "UPDATE_VERIFY")
-- checksum kernel
- t, err = self:checksum(self._zImageExtraVersion)
+ t, err = self:checksum("zImage")
if not t then
log:warn("flash checksum failed")
return nil, err
@@ -187,6 +186,9 @@
elseif action == "checksum" then
-- store checksum
self._checksum = self._checksum .. chunk
+
+ elseif action == "board.version" then
+ self._boardVersion = self._boardVersion
.. chunk
end
return 1
@@ -209,9 +211,9 @@
if type(chunk) == "table" then
-- new file
- if chunk.filename == self._zImageExtraVersion
then
+ if string.match(chunk.filename, "^zImage") then
-- kernel
- part = self._zImageExtraVersion
+ part = "zImage"
elseif chunk.filename == "root.cramfs" then
-- cramfs
@@ -221,6 +223,9 @@
-- md5 checksums
action = "checksum"
+ elseif chunk.filename == "board.version" then
+ action = "board.version"
+
else
action = nil
end
@@ -228,6 +233,11 @@
-- open file handle
if part ~= nil then
+ if not self:verifyPlatformRevision() then
+ self.sinkErr = "Incompatible
firmware"
+ return nil
+ end
+
action = "store"
length = 0
@@ -244,6 +254,56 @@
-- should never get here
return nil
end
+end
+
+
+-- utility function to parse /dev/cpuinfo
+function parseCpuInfo(self)
+ local fh, err = io.open("/proc/cpuinfo")
+ if fh == nil then
+ return fh, err
+ end
+
+ while true do
+ local line = fh:read()
+ if line == nil then
+ break
+ end
+
+ if string.match(line, "Hardware") then
+ self._platform = string.lower(string.match(line,
".+:%s+([^%s]+)"))
+ elseif string.match(line, "Revision") then
+ self._revision = tonumber(string.match(line,
".+:%s+([^%s]+)"))
+ end
+
+ end
+ fh:close()
+
+ return 1
+end
+
+
+function verifyPlatformRevision(self)
+ for platform, revision in string.gmatch(self._boardVersion,
"(%a+):(%d+)") do
+ platform = string.lower(platform)
+ revision = tonumber(revision)
+
+ if string.match(platform, self._platform)
+ and revision == self._revision then
+ return true
+ end
+ end
+
+ -- backwards compatibility for initial jive boards
+ if self._boardVersion == ""
+ and self._platform == "jive"
+ and self._revision == 0 then
+ return true
+ end
+
+ log:warn("Firmware is not compatible with ", self._platform, ":",
self._revision)
+
+ return false
end
@@ -303,36 +363,6 @@
end
--- parse kernel extraversion
-function parseVersion(self)
-
- local fh, err = io.open("/proc/version")
- if fh == nil then
- return fh, err
- end
-
- local version = fh:read("*all")
- fh:close()
-
- local extraversion = string.match(version, "Linux version
[%d%.]+(%-[^%s]+)") or ""
-
- -- backwards compatibility
- if extraversion == "-P4" then
- extraversion = ""
- end
-
- log:info("extraversion=", extraversion)
-
- -- select kernel to use
- self._zImageExtraVersion = "zImage" .. extraversion
- self._mtd[self._zImageExtraVersion] = self._mtd["zImage"]
-
- Task:yield(true)
-
- return 1
-end
-
-
-- update bootloader environment
function fw_setenv(self, variables)
local cmd = { "/usr/sbin/fw_setenv" }
@@ -410,16 +440,16 @@
end
Task:yield(true)
end
-
- if self.sinkErr then
- log:info("sinkErr=", self.sinkErr)
- return false, self.sinkErr
- end
-
- return true
else
return false, "Unsupported url scheme"
end
+
+ if self.sinkErr then
+ log:info("sinkErr=", self.sinkErr)
+ return false, self.sinkErr
+ end
+
+ return true
end
Modified:
7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua?rev=3664&root=Jive&r1=3663&r2=3664&view=diff
==============================================================================
---
7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua
(original)
+++
7.4/trunk/squeezeplay/src/squeezeplay_squeezeos/share/applets/SetupFirmwareUpgrade/UpgradeUBI.lua
Fri Jan 2 10:02:34 2009
@@ -32,6 +32,7 @@
_file = {},
_size = {},
_checksum = "",
+ _boardVersion = "",
})
return obj
@@ -51,6 +52,13 @@
function _upgrade(self)
self._callback(false, "UPDATE_DOWNLOAD", "")
+
+ -- parse the board revision
+ t, err = self:parseCpuInfo()
+ if not t then
+ log:warn("parseCpuInfo failed")
+ return nil, err
+ end
-- remove old image
self:rmvol("kernel_bak")
@@ -96,6 +104,48 @@
end
+-- utility function to parse /dev/cpuinfo
+function parseCpuInfo(self)
+ local fh, err = io.open("/proc/cpuinfo")
+ if fh == nil then
+ return fh, err
+ end
+
+ while true do
+ local line = fh:read()
+ if line == nil then
+ break
+ end
+
+ if string.match(line, "Hardware") then
+ self._platform = string.lower(string.match(line,
".+:%s+([^%s]+)"))
+ elseif string.match(line, "Revision") then
+ self._revision = tonumber(string.match(line,
".+:%s+([^%s]+)"))
+ end
+
+ end
+ fh:close()
+
+ return 1
+end
+
+
+function verifyPlatformRevision(self)
+ for platform, revision in string.gmatch(self._boardVersion,
"(%a+):(%d+)") do
+ platform = string.lower(platform)
+ revision = tonumber(revision)
+
+ if string.match(platform, self._platform)
+ and revision == self._revision then
+ return true
+ end
+ end
+
+ log:warn("Firmware is not compatible with ", self._platform, ":",
self._revision)
+
+ return false
+ end
+
-- utility function to parse /dev/mtd
function parseMtd(self)
local mtd = {}
@@ -174,6 +224,10 @@
elseif _action == "checksum" then
-- store checksum
self._checksum = self._checksum .. chunk
+
+ elseif _action == "board.version" then
+ self._boardVersion = self._boardVersion .. chunk
+
end
return 1
end
@@ -195,6 +249,11 @@
local filename = chunk.filename
if string.match(filename, "^zImage") then
+ if not self:verifyPlatformRevision() then
+ self.sinkErr = "Incompatible firmware"
+ return nil
+ end
+
_action = "store"
_fhsink, err = self:updatevol("kernel_upg",
filename, chunk.uncompressed_size)
if not _fhsink then
@@ -202,6 +261,11 @@
end
elseif filename == "root.cramfs" then
+ if not self:verifyPlatformRevision() then
+ self.sinkErr = "Incompatible firmware"
+ return nil
+ end
+
_action = "store"
_fhsink = self:updatevol("cramfs_upg",
filename, chunk.uncompressed_size)
if not _fhsink then
@@ -210,6 +274,9 @@
elseif filename == "upgrade.md5" then
_action = "checksum"
+
+ elseif chunk.filename == "board.version" then
+ _action = "board.version"
else
-- ignore file
@@ -279,12 +346,12 @@
end
Task:yield(true)
end
-
- if self.sinkErr then
- error(self.sinkErr, 0)
- end
else
error("Unsupported url scheme", 0)
+ end
+
+ if self.sinkErr then
+ error(self.sinkErr, 0)
end
end
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins