From ae431d56387c051b1381dded64cf7119158ce638 Mon Sep 17 00:00:00 2001 From: Armijn Hemel Date: Thu, 27 Apr 2023 19:02:58 +0200 Subject: [PATCH 1/7] add specification for Reolink firmware files --- firmware/reolink.ksy | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 firmware/reolink.ksy diff --git a/firmware/reolink.ksy b/firmware/reolink.ksy new file mode 100644 index 000000000..4ab900b65 --- /dev/null +++ b/firmware/reolink.ksy @@ -0,0 +1,64 @@ +meta: + id: reolink + title: Reolink firmware update + license: GPL-3.0 + endian: le + encoding: UTF-8 +doc-ref: + - https://github.com/hn/reolink-camera/blob/master/unpack-novatek-firmware.pl +seq: + - id: header + type: header + - id: sections + type: section + repeat: expr + repeat-expr: num_sections + - id: partitions + type: partition + repeat: expr + repeat-expr: num_sections +instances: + first_section: + pos: header._sizeof + type: section + num_sections: + value: first_section.ofs_section / (64 + 76) +types: + header: + seq: + - id: magic + contents: [0x13, 0x59, 0x72, 0x32] + - id: crc + size: 4 + - id: board + size: 4 + section: + seq: + - id: name + size: 32 + type: strz + - id: version + size: 24 + - id: ofs_section + type: u4 + - id: len_section + type: u4 + instances: + section: + io: _root._io + pos: ofs_section + size: len_section + partition: + seq: + - id: name + size: 32 + type: strz + - id: ofs_partition + type: u4 + - id: destination + size: 32 + type: strz + - id: unknown + size: 4 + - id: len_partition + type: u4 From 580c839d1cbae0408f61d59825ec8bf5203eb65e Mon Sep 17 00:00:00 2001 From: Armijn Hemel Date: Thu, 27 Apr 2023 22:40:11 +0200 Subject: [PATCH 2/7] reolink: correctly compute the number of sections (also subtract the size of the header) --- firmware/reolink.ksy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/reolink.ksy b/firmware/reolink.ksy index 4ab900b65..5d2ade7e9 100644 --- a/firmware/reolink.ksy +++ b/firmware/reolink.ksy @@ -22,7 +22,7 @@ instances: pos: header._sizeof type: section num_sections: - value: first_section.ofs_section / (64 + 76) + value: (first_section.ofs_section - header._sizeof ) / (64 + 76) types: header: seq: From 67c1df4d431b55143993ae42752f9bb877d4e4eb Mon Sep 17 00:00:00 2001 From: Armijn Hemel Date: Thu, 27 Apr 2023 22:48:41 +0200 Subject: [PATCH 3/7] reolink: clarify license, crc --- firmware/reolink.ksy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/reolink.ksy b/firmware/reolink.ksy index 5d2ade7e9..67b261aad 100644 --- a/firmware/reolink.ksy +++ b/firmware/reolink.ksy @@ -1,7 +1,7 @@ meta: id: reolink title: Reolink firmware update - license: GPL-3.0 + license: GPL-3.0-only endian: le encoding: UTF-8 doc-ref: @@ -28,7 +28,7 @@ types: seq: - id: magic contents: [0x13, 0x59, 0x72, 0x32] - - id: crc + - id: crc32 size: 4 - id: board size: 4 From 6f8979362185639fbedde9a8971abdf014f203f4 Mon Sep 17 00:00:00 2001 From: Armijn Hemel Date: Thu, 27 Apr 2023 23:01:58 +0200 Subject: [PATCH 4/7] reolink: do not hardcode sizes of partition and section when computing the number of sections --- firmware/reolink.ksy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/reolink.ksy b/firmware/reolink.ksy index 67b261aad..1c84aa68e 100644 --- a/firmware/reolink.ksy +++ b/firmware/reolink.ksy @@ -22,7 +22,7 @@ instances: pos: header._sizeof type: section num_sections: - value: (first_section.ofs_section - header._sizeof ) / (64 + 76) + value: (first_section.ofs_section - header._sizeof) / (sizeof
+ sizeof) types: header: seq: From db0f096b8f400334ec121a89e12be717441049aa Mon Sep 17 00:00:00 2001 From: Armijn Hemel Date: Tue, 2 May 2023 13:03:33 +0200 Subject: [PATCH 5/7] reolink: add support for 64 bit files --- firmware/reolink.ksy | 66 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/firmware/reolink.ksy b/firmware/reolink.ksy index 1c84aa68e..5736d1cb0 100644 --- a/firmware/reolink.ksy +++ b/firmware/reolink.ksy @@ -8,9 +8,17 @@ doc-ref: - https://github.com/hn/reolink-camera/blob/master/unpack-novatek-firmware.pl seq: - id: header - type: header + type: + switch-on: is_64 + cases: + true: header64 + false: header32 - id: sections - type: section + type: + switch-on: is_64 + cases: + false: section32 + true: section64 repeat: expr repeat-expr: num_sections - id: partitions @@ -18,21 +26,45 @@ seq: repeat: expr repeat-expr: num_sections instances: - first_section: - pos: header._sizeof - type: section + header_crc32: + pos: 4 + type: u4 + is_64: + value: header_crc32 == 0 num_sections: - value: (first_section.ofs_section - header._sizeof) / (sizeof
+ sizeof) + value: header.as.num_sections types: - header: + header32: seq: - id: magic contents: [0x13, 0x59, 0x72, 0x32] - id: crc32 - size: 4 + type: u4 - id: board size: 4 - section: + instances: + first_section: + io: _root._io + pos: sizeof + type: section32 + num_sections: + value: (first_section.ofs_section - sizeof) / (sizeof + sizeof) + header64: + seq: + - id: magic + contents: [0x13, 0x59, 0x72, 0x32, 0x00, 0x00, 0x00, 0x00] + - id: crc32 + type: u8 + - id: board + size: 8 + instances: + first_section: + io: _root._io + pos: sizeof + type: section64 + num_sections: + value: (first_section.ofs_section - sizeof) / (sizeof + sizeof) + section32: seq: - id: name size: 32 @@ -48,6 +80,22 @@ types: io: _root._io pos: ofs_section size: len_section + section64: + seq: + - id: name + size: 32 + type: strz + - id: version + size: 24 + - id: ofs_section + type: u8 + - id: len_section + type: u8 + instances: + section: + io: _root._io + pos: ofs_section + size: len_section partition: seq: - id: name From be6e4bac9bea87757310f1230b7879f311dfdc19 Mon Sep 17 00:00:00 2001 From: Armijn Hemel Date: Tue, 2 May 2023 14:04:09 +0200 Subject: [PATCH 6/7] reolink: change license (sync with upstream source), change doc-ref --- firmware/reolink.ksy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/firmware/reolink.ksy b/firmware/reolink.ksy index 5736d1cb0..39203af1d 100644 --- a/firmware/reolink.ksy +++ b/firmware/reolink.ksy @@ -1,11 +1,11 @@ meta: id: reolink title: Reolink firmware update - license: GPL-3.0-only + license: MIT endian: le encoding: UTF-8 doc-ref: - - https://github.com/hn/reolink-camera/blob/master/unpack-novatek-firmware.pl + - https://github.com/vmallet/pakler/blob/acbf084b/pakler/__init__.py seq: - id: header type: @@ -103,10 +103,10 @@ types: type: strz - id: ofs_partition type: u4 - - id: destination + - id: mtd size: 32 type: strz - - id: unknown + - id: start_address size: 4 - id: len_partition type: u4 From 8be72c84a16ee404e480c1a66daf38aa2a329a23 Mon Sep 17 00:00:00 2001 From: Armijn Hemel Date: Tue, 2 May 2023 16:34:12 +0200 Subject: [PATCH 7/7] reolink: change id, add file-extension --- firmware/reolink.ksy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/reolink.ksy b/firmware/reolink.ksy index 39203af1d..45a603133 100644 --- a/firmware/reolink.ksy +++ b/firmware/reolink.ksy @@ -1,6 +1,7 @@ meta: - id: reolink + id: reolink_pak title: Reolink firmware update + file-extension: pak license: MIT endian: le encoding: UTF-8