diff --git a/gwsettings.cc b/gwsettings.cc index 1b00c2f..cbbde8e 100644 --- a/gwsettings.cc +++ b/gwsettings.cc @@ -17,7 +17,6 @@ * */ -#include #include #include "nonvoldef.h" #include "gwsettings.h" diff --git a/profiledef.c b/profiledef.c index e438ce7..85e75fd 100644 --- a/profiledef.c +++ b/profiledef.c @@ -132,7 +132,37 @@ struct bcm2_profile bcm2_profiles[] = { .pretty = "Netgear CG3000", .pssig = 0xa0f7, .spaces = { - { .name = "ram" }, + { + .name = "ram", + .min = 0x80000000, + .size = 256 * 1024 * 1024, + .parts = { + { "bootloader", 0x83f80000, 0x020000 }, + } + }, + { + .name = "nvram", + .size = 1 * 1024 * 1024, + .parts = { + { "bootloader", 0x00000, 0x10000 }, + { "permnv", 0x10000, 0x10000, "perm" }, + { "vennv", 0x20000, 0x10000 }, + { "vennv2", 0x30000, 0x10000 }, + { "dynnv", 0xc0000, 0x40000, "dyn" }, + }, + }, + { + .name = "flash", + .size = 128 * 1024 * 1024, + .parts = { + { "linuxapps", 0x0000000, 0x1f40000, "image3e" }, + { "image1", 0x1f40000, 0x0900000 }, + { "image2", 0x2840000, 0x0900000 }, + { "linux", 0x3140000, 0x0480000, "image3" }, + { "linuxkfs", 0x35c0000, 0x4800000, "" }, + { "dhtml", 0x7dc0000, 0x0240000 }, + } + }, }, }, { diff --git a/util.h b/util.h index e167675..7bda930 100644 --- a/util.h +++ b/util.h @@ -19,8 +19,6 @@ #ifndef BCM2UTILS_UTIL_H #define BCM2UTILS_UTIL_H -#include -#include #include #include #include @@ -34,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -195,16 +194,19 @@ template T align_right(const T& num, size_t alignment) return num + (rem ? alignment - rem : 0); } -template typename T::value_type crc_generic(const void* buf, size_t size) -{ - T crc; - crc.process_bytes(buf, size); - return crc.checksum(); -} - inline uint16_t crc16_ccitt(const void* buf, size_t size) { - return crc_generic(buf, size); + uint16_t crc = 0xffff; + const uint8_t *p = static_cast(buf); + + while (size--) { + crc ^= static_cast(*p++) << 8; + for (int i = 0; i < 8; ++i) { + crc = (crc & 0x8000) ? (crc << 1) ^ 0x1021 : crc << 1; + } + } + + return crc; } inline uint16_t crc16_ccitt(const std::string& buf) @@ -212,7 +214,16 @@ inline uint16_t crc16_ccitt(const std::string& buf) inline uint32_t crc32(const std::string& buf) { - return crc_generic(buf.data(), buf.size()); + uint32_t crc = 0xffffffff; + + for (uint8_t byte : buf) { + crc ^= byte; + for (int i = 0; i < 8; ++i) { + crc = (crc & 1) ? (crc >> 1) ^ 0xedb88320 : crc >> 1; + } + } + + return crc ^ 0xffffffff; } class mstimer @@ -242,24 +253,45 @@ std::string transform(const std::string& str, std::function f); std::string escape(std::string str, bool escape_quote = false); +template inline T bswap(T n) +{ + typename std::make_unsigned::type u = n; + typename std::make_unsigned::type r = 0; + + for (size_t i = 0; i < sizeof(T); ++i) { + r = (r << 8) | (u & 0xff); + u >>= 8; + } + + return static_cast(r); +} + template inline T be_to_h(T n) { - return boost::endian::big_to_native(n); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + return bswap(n); +#else + return n; +#endif } template inline T le_to_h(T n) { - return boost::endian::little_to_native(n); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + return n; +#else + return bswap(n); +#endif } template inline T h_to_be(T n) { - return boost::endian::native_to_big(n); + return be_to_h(n); } template inline T h_to_le(T n) { - return boost::endian::native_to_little(n); + return le_to_h(n); } template using sp = std::shared_ptr;