110-wrt350nv2_support.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. --- a/nslu2_image.cc
  2. +++ b/nslu2_image.cc
  3. @@ -54,28 +54,44 @@ namespace NSLU2Image {
  4. int &address, int &length) {
  5. address = image.tellg();
  6. length = buffer_length;
  7. - if (address+length > NSLU2Protocol::FlashSize)
  8. - length = NSLU2Protocol::FlashSize-address;
  9. + if (address+length > EndAddress)
  10. + length = EndAddress-address;
  11. if (length > 0)
  12. SafeRead(&image, buffer, length, "image (read)");
  13. }
  14. + virtual void GetBoundaries(int &start, int &end)
  15. + {
  16. + start = BaseAddress;
  17. + end = EndAddress;
  18. + }
  19. +
  20. /* Rewind to the start of the image (or the Kernel if not
  21. * doing a complete reprogram).
  22. */
  23. virtual void Rewind(void) {
  24. - SafeSeek(&image, reprogram ? 0 : NSLU2Protocol::BaseAddress,
  25. + SafeSeek(&image, reprogram ? 0 : BaseAddress,
  26. "image (seek)");
  27. }
  28. private:
  29. + int BaseAddress;
  30. + int EndAddress;
  31. +
  32. /* Validate that this really is an image file. */
  33. void Validate(const char *i) {
  34. char signature[8];
  35. SafeSeek(&image, -8, i, std::ios::end);
  36. SafeRead(&image, signature, 8, i);
  37. - if (memcmp(signature, "eRcOmM", 6) != 0)
  38. +
  39. + if (memcmp(signature, "eRcOmM", 6) == 0) {
  40. + BaseAddress = NSLU2Protocol::BaseAddress;
  41. + EndAddress = NSLU2Protocol::FlashSize;
  42. + } else if (memcmp(signature + 1, "sErCoMm", 7) == 0) {
  43. + BaseAddress = 0;
  44. + EndAddress = NSLU2Protocol::FlashSize - 0x40000;
  45. + } else
  46. throw NSLU2Image::FileError(DataError, i, 0);
  47. }
  48. @@ -93,6 +109,12 @@ namespace NSLU2Image {
  49. virtual ~SynthesiseImage() {
  50. }
  51. + void GetBoundaries(int &start, int &end)
  52. + {
  53. + start = NSLU2Protocol::BaseAddress;
  54. + end = NSLU2Protocol::FlashSize;
  55. + }
  56. +
  57. /* Get the next block of bytes, returns an address and length, false if
  58. * there is a problem.
  59. */
  60. --- a/nslu2_image.h
  61. +++ b/nslu2_image.h
  62. @@ -35,6 +35,8 @@ namespace NSLU2Image {
  63. virtual ~Image() {
  64. }
  65. + virtual void GetBoundaries(int &start, int &end) = 0;
  66. +
  67. /* Get the next block of bytes, returns an address and length.
  68. */
  69. virtual void GetBytes(char *buffer, size_t buffer_length,
  70. --- a/nslu2_upgrade.cc
  71. +++ b/nslu2_upgrade.cc
  72. @@ -95,7 +95,7 @@ namespace NSLU2Upgrade {
  73. class RealDoUpgrade : public DoUpgrade {
  74. public:
  75. - RealDoUpgrade(Wire *w, Progress *p, bool r) :
  76. + RealDoUpgrade(Wire *w, Progress *p, bool r, int start, int end) :
  77. wire(w), progress(p), sequenceError(-1), reprogram(r),
  78. lastType(NSLU2Protocol::InvalidType) {
  79. if (reprogram) {
  80. @@ -105,6 +105,8 @@ namespace NSLU2Upgrade {
  81. NSLU2Protocol::UpgradeStartPacket packet(seq);
  82. wire->Send(packet.PacketBuffer(), packet.PacketLength());
  83. }
  84. + BaseAddress = start;
  85. + EndAddress = end;
  86. }
  87. virtual ~RealDoUpgrade() {
  88. @@ -205,8 +207,8 @@ namespace NSLU2Upgrade {
  89. };
  90. - DoUpgrade *DoUpgrade::MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram) {
  91. - return new RealDoUpgrade(wire, progress, reprogram);
  92. + DoUpgrade *DoUpgrade::MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram, int start, int end) {
  93. + return new RealDoUpgrade(wire, progress, reprogram, start, end);
  94. }
  95. };
  96. @@ -421,13 +423,18 @@ void NSLU2Upgrade::RealDoUpgrade::Upgrad
  97. /* Simple upgrade programs only the addresses beyound BaseAddress,
  98. * reprogram overwrites the whole flash.
  99. */
  100. - if (!reprogram && address < NSLU2Protocol::BaseAddress) {
  101. + if (!reprogram && address < BaseAddress) {
  102. length += address;
  103. - if (length <= NSLU2Protocol::BaseAddress)
  104. + if (length <= BaseAddress)
  105. return; /* nothing to do. */
  106. - address = NSLU2Protocol::BaseAddress;
  107. + address = BaseAddress;
  108. length -= address;
  109. }
  110. + if (!reprogram && address + length > EndAddress) {
  111. + if (address >= EndAddress)
  112. + return; /* nothing to do. */
  113. + length -= EndAddress - address;
  114. + }
  115. #if 1
  116. /* Skip blocks of 255 valued bytes - the erase clears the flash to this
  117. @@ -495,11 +502,11 @@ void NSLU2Upgrade::RealDoUpgrade::Verify
  118. Finish();
  119. /* Verify never verifies anything below BaseAddress. */
  120. - if (address < NSLU2Protocol::BaseAddress) {
  121. + if (address < BaseAddress) {
  122. length += address;
  123. - if (length <= NSLU2Protocol::BaseAddress)
  124. + if (length <= BaseAddress)
  125. return; /* nothing to do. */
  126. - address = NSLU2Protocol::BaseAddress;
  127. + address = BaseAddress;
  128. length -= address;
  129. }
  130. --- a/nslu2_upgrade.h
  131. +++ b/nslu2_upgrade.h
  132. @@ -206,6 +206,8 @@ namespace NSLU2Upgrade {
  133. class DoUpgrade {
  134. public:
  135. + int BaseAddress;
  136. + int EndAddress;
  137. virtual ~DoUpgrade() {
  138. }
  139. @@ -228,7 +230,7 @@ namespace NSLU2Upgrade {
  140. virtual void Reboot(void) = 0;
  141. /* Reboot the NSLU2. */
  142. - static DoUpgrade *MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram);
  143. + static DoUpgrade *MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram, int start, int end);
  144. /* Instantiate a real DoUpgrade, returns NULL if the object
  145. * cannot be instantiated.
  146. *
  147. --- a/upslug2.cc
  148. +++ b/upslug2.cc
  149. @@ -21,8 +21,8 @@
  150. class ProgressBar : public UpSlug2::CharacterProgressBar<80> {
  151. public:
  152. - ProgressBar(bool reprogram, const unsigned char *t) :
  153. - UpSlug2::CharacterProgressBar<80>(reprogram, 64),
  154. + ProgressBar(bool reprogram, const unsigned char *t, int start, int end) :
  155. + UpSlug2::CharacterProgressBar<80>(reprogram, 64, start, end),
  156. target(t), displayed(false), ticker(0) {
  157. }
  158. @@ -95,7 +95,7 @@ private:
  159. else if (seen == -1) {
  160. seen = 0;
  161. if (!reprogram)
  162. - sent -= NSLU2Protocol::BaseAddress;
  163. + sent -= NSLU2Protocol::FlashSize - (EndAddress - BaseAddress);
  164. } else
  165. sent -= seen;
  166. @@ -423,7 +423,7 @@ int main(int argc, char **argv) {
  167. { 0, 0, 0, 0 }
  168. };
  169. - do switch (getopt_long(argc, argv, "he:d:t:f:vUni:Ck:r:R:j:p:P:T:F:E:", options, 0)) {
  170. + do switch (getopt_long(argc, argv, "he:d:t:f:vUni:Ck:r:R:j:op:P:T:F:E:", options, 0)) {
  171. case -1: if (optind < argc) {
  172. std::fprintf(stderr, "%s: unrecognised option\n", argv[optind]);
  173. std::exit(1);
  174. @@ -523,16 +523,22 @@ done:
  175. if (mac && got_kernel) {
  176. Pointer<NSLU2Upgrade::Wire> wire(NSLU2Upgrade::Wire::MakeWire(device, fromMac, mac, euid));
  177. - ProgressBar progress(reprogram, mac);
  178. + int BaseAddress = NSLU2Protocol::BaseAddress;
  179. + int EndAddress = NSLU2Protocol::FlashSize;
  180. if (full_image) { /* complete image. */
  181. /* The full image case allows a complete reprogram. */
  182. + NSLU2Image::Image *image_p;
  183. Pointer<NSLU2Image::Image> image(
  184. NSLU2Image::Image::MakeImage(
  185. reprogram, full_image));
  186. + image_p = image.p;
  187. + image_p->GetBoundaries(BaseAddress, EndAddress);
  188. + ProgressBar progress(reprogram, mac, BaseAddress, EndAddress);
  189. Pointer<NSLU2Upgrade::DoUpgrade> upgrade(
  190. NSLU2Upgrade::DoUpgrade::MakeDoUpgrade(
  191. - wire.p, &progress, reprogram));
  192. + wire.p, &progress, reprogram,
  193. + BaseAddress, EndAddress));
  194. progress.FirstDisplay();
  195. Upgrade(upgrade.p, image.p, no_upgrade, no_verify);
  196. progress.EndDisplay();
  197. @@ -551,9 +557,11 @@ done:
  198. fis_payload,
  199. product_id, protocol_id,
  200. firmware_version, extra_version));
  201. + ProgressBar progress(reprogram, mac, BaseAddress, EndAddress);
  202. Pointer<NSLU2Upgrade::DoUpgrade> upgrade(
  203. NSLU2Upgrade::DoUpgrade::MakeDoUpgrade(
  204. - wire.p, &progress, false));
  205. + wire.p, &progress, false,
  206. + BaseAddress, EndAddress));
  207. progress.FirstDisplay();
  208. Upgrade(upgrade.p, image.p, no_upgrade, no_verify);
  209. progress.EndDisplay();
  210. --- a/upslug2_progress.h
  211. +++ b/upslug2_progress.h
  212. @@ -161,15 +161,19 @@ namespace UpSlug2 {
  213. Timedout, /* *: timeout on a sent packet for this address. */
  214. NumberOfStates
  215. } Status;
  216. -
  217. + int BaseAddress;
  218. + int EndAddress;
  219. +
  220. /* reprogram says whether this is a full reprogram (the entire
  221. * flash will be erased) or not (the leading, RedBoot, SysConf
  222. * partitions are not erased).
  223. * resolution should be about 6 for a command line (character)
  224. * progress bar and 8 for a GUI (pixel) progress bar.
  225. */
  226. - ProgressBar(bool r) :
  227. + ProgressBar(bool r, int start, int end) :
  228. reprogram(r), timeout(false), retransmit(false), status(Init) {
  229. + BaseAddress = start;
  230. + EndAddress = end;
  231. }
  232. /* lowWaterMark..(highWaterMark-1) bytes are in state 'st',
  233. @@ -179,8 +183,8 @@ namespace UpSlug2 {
  234. /* These initial settings cover the majority of cases
  235. * correctly.
  236. */
  237. - lowWaterMark = reprogram ? 0 : NSLU2Protocol::BaseAddress;
  238. - highWaterMark = status >= st ? NSLU2Protocol::FlashSize-1 : 0;
  239. + lowWaterMark = reprogram ? 0 : BaseAddress;
  240. + highWaterMark = status >= st ? EndAddress-1 : 0;
  241. switch (st) {
  242. case Init:
  243. /* Everything has an initial value... */
  244. @@ -286,9 +290,9 @@ namespace UpSlug2 {
  245. */
  246. template <int characters> class CharacterProgressBar : public ProgressBar {
  247. public:
  248. - CharacterProgressBar(bool reprogram, int n, const char ind[NumberOfStates] = 0) :
  249. + CharacterProgressBar(bool reprogram, int n, int start, int end, const char ind[NumberOfStates] = 0) :
  250. numberOfCharacters(n > characters || n < 1 ? characters : n),
  251. - ProgressBar(reprogram) {
  252. + ProgressBar(reprogram, start, end) {
  253. if (ind)
  254. std::memcpy(indicators, ind, NumberOfStates);
  255. else