@@ -118,7 +118,11 @@ int disk_open(int drv)
118118 uint32_t i ;
119119 uint32_t n_parts = 0 ;
120120 uint32_t gpt_lba = 0 ;
121+ uint32_t chunk = 0 ;
122+ uint64_t array_addr = 0 ;
123+ uint64_t bytes_left = 0 ;
121124 uint8_t sector [GPT_SECTOR_SIZE ] XALIGNED (4 );
125+ struct gpt_crc32_ctx part_crc ;
122126
123127 if ((drv < 0 ) || (drv >= MAX_DISKS )) {
124128 wolfBoot_printf ("Attempting to access invalid drive %d\r\n" , drv );
@@ -162,35 +166,32 @@ int disk_open(int drv)
162166 wolfBoot_printf ("Valid GPT partition table\r\n" );
163167 wolfBoot_printf ("Max number of partitions: %d\r\n" , ptable .n_part );
164168
165- {
166- struct gpt_crc32_ctx part_crc ;
167- uint64_t array_addr = ptable .start_array * GPT_SECTOR_SIZE ;
168- uint64_t bytes_left = (uint64_t )ptable .n_part * ptable .array_sz ;
169-
170- gpt_crc32_init (& part_crc );
171- while (bytes_left > 0 ) {
172- uint32_t chunk = GPT_SECTOR_SIZE ;
173-
174- if (bytes_left < chunk ) {
175- chunk = (uint32_t )bytes_left ;
176- }
177-
178- r = disk_read (drv , array_addr , chunk , sector );
179- if (r < 0 ) {
180- Drives [drv ].is_open = 0 ;
181- return -1 ;
182- }
183-
184- gpt_crc32_update (& part_crc , sector , chunk );
185- array_addr += chunk ;
186- bytes_left -= chunk ;
169+ array_addr = ptable .start_array * GPT_SECTOR_SIZE ;
170+ bytes_left = (uint64_t )ptable .n_part * ptable .array_sz ;
171+
172+ gpt_crc32_init (& part_crc );
173+ while (bytes_left > 0 ) {
174+ chunk = GPT_SECTOR_SIZE ;
175+
176+ if (bytes_left < chunk ) {
177+ chunk = (uint32_t )bytes_left ;
187178 }
188179
189- if ( gpt_crc32_final ( & part_crc ) != ptable . part_crc ) {
190- wolfBoot_printf ( "Invalid GPT partition entry array CRC\r\n" );
180+ r = disk_read ( drv , array_addr , chunk , sector );
181+ if ( r < 0 ) {
191182 Drives [drv ].is_open = 0 ;
192183 return -1 ;
193184 }
185+
186+ gpt_crc32_update (& part_crc , sector , chunk );
187+ array_addr += chunk ;
188+ bytes_left -= chunk ;
189+ }
190+
191+ if (gpt_crc32_final (& part_crc ) != ptable .part_crc ) {
192+ wolfBoot_printf ("Invalid GPT partition entry array CRC\r\n" );
193+ Drives [drv ].is_open = 0 ;
194+ return -1 ;
194195 }
195196
196197 n_parts = ptable .n_part ;
0 commit comments