@@ -8,7 +8,7 @@ use crate::alloc::string::ToString;
88use alloc:: string:: String ;
99use core:: convert:: TryInto ;
1010
11- use crate :: ccgx:: binary:: { CCG5_PD_LEN , CCG6_PD_LEN } ;
11+ use crate :: ccgx:: binary:: { CCG5_PD_LEN , CCG6_PD_LEN , CCG8_PD_LEN } ;
1212use crate :: ec_binary:: EC_LEN ;
1313use crate :: util;
1414
@@ -29,26 +29,25 @@ pub fn find_bios_version(data: &[u8]) -> Option<BiosCapsule> {
2929 let needle = b"$BVDT" ;
3030 let found = util:: find_sequence ( data, needle) ?;
3131
32+ // One of: GFW30, HFW3T, HFW30, IFR30, KFM30, JFP30, LFK30, IFGA3, IFGP6, LFR20, LFSP0
3233 let platform_offset = found + 0xA + needle. len ( ) - 1 ;
33- let platform = std:: str:: from_utf8 ( & data[ platform_offset..platform_offset + 4 ] )
34+ let platform = std:: str:: from_utf8 ( & data[ platform_offset..platform_offset + 5 ] )
3435 . map ( |x| x. to_string ( ) )
3536 . ok ( ) ?;
3637
37- let ver_offset = found + 0xE + needle. len ( ) - 1 ;
38- let version = std:: str:: from_utf8 ( & data[ ver_offset..ver_offset + 4 ] )
38+ let ver_offset = found + 0x10 + needle. len ( ) - 1 ;
39+ let version = std:: str:: from_utf8 ( & data[ ver_offset..ver_offset + 5 ] )
3940 . map ( |x| x. to_string ( ) )
4041 . ok ( ) ?;
4142
4243 Some ( BiosCapsule { platform, version } )
4344}
4445
4546pub fn find_ec_in_bios_cap ( data : & [ u8 ] ) -> Option < & [ u8 ] > {
46- let needle = b"_IFLASH_EC_IMG_" ;
47- let found_iflash = util:: find_sequence ( data, needle) ?;
48- // The actual EC binary is a few bytes after `_IFLASH_EC_IMG_`.
49- // Just earch for the first 4 bytes that seem to appear in all EC images.
50- let found = util:: find_sequence ( & data[ found_iflash..] , & [ 0x10 , 0x00 , 0x00 , 0xf7 ] ) ?;
51- Some ( & data[ found_iflash + found..found_iflash + found + EC_LEN ] )
47+ let needle = b"$_IFLASH_EC_IMG_" ;
48+ let found = util:: find_sequence ( data, needle) ?;
49+ let ec_offset = found + 0x9 + needle. len ( ) - 1 ;
50+ Some ( & data[ ec_offset..ec_offset + EC_LEN ] )
5251}
5352
5453pub fn find_pd_in_bios_cap ( data : & [ u8 ] ) -> Option < & [ u8 ] > {
@@ -57,10 +56,13 @@ pub fn find_pd_in_bios_cap(data: &[u8]) -> Option<&[u8]> {
5756 // they're the same version
5857 let ccg5_needle = & [ 0x00 , 0x20 , 0x00 , 0x20 , 0x11 , 0x00 ] ;
5958 let ccg6_needle = & [ 0x00 , 0x40 , 0x00 , 0x20 , 0x11 , 0x00 ] ;
59+ let ccg8_needle = & [ 0x00 , 0x80 , 0x00 , 0x20 , 0xAD , 0x0C ] ;
6060 if let Some ( found_pd1) = util:: find_sequence ( data, ccg5_needle) {
6161 Some ( & data[ found_pd1..found_pd1 + CCG5_PD_LEN ] )
6262 } else if let Some ( found_pd1) = util:: find_sequence ( data, ccg6_needle) {
6363 Some ( & data[ found_pd1..found_pd1 + CCG6_PD_LEN ] )
64+ } else if let Some ( found_pd1) = util:: find_sequence ( data, ccg8_needle) {
65+ Some ( & data[ found_pd1..found_pd1 + CCG8_PD_LEN ] )
6466 } else {
6567 None
6668 }
0 commit comments