Skip to content

Commit

Permalink
Hard-code BCT page/block sizes on t18x/t19x
Browse files Browse the repository at this point in the history
The page and block size fields are in the encrypted
section of the BCT on t18x/t19x platforms, so we can't
use them for determining how to update the BCT.
The two sizes vary depending on the boot device (eMMC
or SPI flash), but otherwise don't change, so just
use the known values.

Back-ported from commit cfde4e1.

Signed-off-by: Matt Madison <[email protected]>
  • Loading branch information
madisongh committed Nov 30, 2020
1 parent c1b59e4 commit 613cb37
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions bct.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define bct_h__
/* Copyright (c) 2020 Matthew Madison */

int bct_update_valid_t18x(void *cur_bct, void *cand_bct, unsigned int *block_size, unsigned int *page_size);
int bct_update_valid_t19x(void *cur_bct, void *cand_bct, unsigned int *block_size, unsigned int *page_size);
int bct_update_valid_t18x(void *cur_bct, void *cand_bct);
int bct_update_valid_t19x(void *cur_bct, void *cand_bct);

#endif /* bct_h__ */
6 changes: 1 addition & 5 deletions bct_t18x.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
* bct_update_valid_t18x
*/
int
bct_update_valid_t18x (void *cur_bct, void *cand_bct,
unsigned int *block_size,
unsigned int *page_size)
bct_update_valid_t18x (void *cur_bct, void *cand_bct)
{
NvBootConfigTable *cur = cur_bct;
NvBootConfigTable *cand = cand_bct;
Expand All @@ -25,10 +23,8 @@ bct_update_valid_t18x (void *cur_bct, void *cand_bct,
return 0;
if (cur->BlockSizeLog2 != cand->BlockSizeLog2)
return 0;
*block_size = (1U << cur->BlockSizeLog2);
if (cur->PageSizeLog2 != cand->PageSizeLog2)
return 0;
*page_size = (1U << cur->PageSizeLog2);

return 1;

Expand Down
6 changes: 1 addition & 5 deletions bct_t19x.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
* bct_update_valid_t19x
*/
int
bct_update_valid_t19x (void *cur_bct, void *cand_bct,
unsigned int *block_size,
unsigned int *page_size)
bct_update_valid_t19x (void *cur_bct, void *cand_bct)
{
NvBootConfigTable *cur = cur_bct;
NvBootConfigTable *cand = cand_bct;
Expand All @@ -25,10 +23,8 @@ bct_update_valid_t19x (void *cur_bct, void *cand_bct,
return 0;
if (cur->BlockSizeLog2 != cand->BlockSizeLog2)
return 0;
*block_size = (1U << cur->BlockSizeLog2);
if (cur->PageSizeLog2 != cand->PageSizeLog2)
return 0;
*page_size = (1U << cur->PageSizeLog2);

return 1;

Expand Down
24 changes: 16 additions & 8 deletions tegra-bootloader-update.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
Expand Down Expand Up @@ -65,6 +66,7 @@ static size_t contentbuf_size;
static uint8_t *contentbuf, *slotbuf;
static int bct_updated;
static tegra_soctype_t soctype = TEGRA_SOCTYPE_INVALID;
static bool spiboot_platform;

static void
print_usage (void)
Expand Down Expand Up @@ -131,8 +133,12 @@ set_bootdev_writeable_status (const char *bootdev, int make_writeable)
* Special handling for writing the BCT. Content to be
* written expected to be present in contentbuf.
*
* A BCT slot is 0xE00 = 3584 bytes.
* A block is 16KiB and holds multiple slots.
* For tegra186/tegra194 platforms only.
*
* A block is 16KiB or 32KiB and holds multiple slots;
* each slot is an even number of "pages" in size, where
* the page size is 512 bytes for eMMC devices and 2KiB for
* SPI flash.
* The Tegra bootrom can handle up to 63 blocks, but
* in practice, only block 0 slots 0 & 1, and block 1 slot 0
* are used.
Expand All @@ -142,15 +148,15 @@ set_bootdev_writeable_status (const char *bootdev, int make_writeable)
*
*/
static int
update_bct (int bootfd, void *curbct, struct update_entry_s *ent)
update_bct (int bootfd, void *curbct, void *newbct, struct update_entry_s *ent)
{
ssize_t n, total, remain;
unsigned int block_size = 16384;
unsigned int page_size = 512;
unsigned int block_size = (spiboot_platform ? 32768 : 16384);
unsigned int page_size = (spiboot_platform ? 2048 : 512);
int i;

if ((soctype == TEGRA_SOCTYPE_186 && !bct_update_valid_t18x(slotbuf, curbct, &block_size, &page_size)) ||
(soctype == TEGRA_SOCTYPE_194 && !bct_update_valid_t19x(slotbuf, curbct, &block_size, &page_size))) {
if ((soctype == TEGRA_SOCTYPE_186 && !bct_update_valid_t18x(curbct, newbct)) ||
(soctype == TEGRA_SOCTYPE_194 && !bct_update_valid_t19x(curbct, newbct))) {
printf("[FAIL]\n");
fprintf(stderr, "Error: validation check failed for BCT update\n");
return -1;
Expand Down Expand Up @@ -230,7 +236,7 @@ maybe_update_bootpart (int bootfd, struct update_entry_s *ent, int is_bct)
}

if (is_bct)
return update_bct(bootfd, contentbuf, ent);
return update_bct(bootfd, slotbuf, contentbuf, ent);

if (lseek(bootfd, ent->part->first_lba * 512, SEEK_SET) == (off_t) -1) {
printf("[FAIL]\n");
Expand Down Expand Up @@ -466,6 +472,8 @@ main (int argc, char * const argv[])
return 1;
}

spiboot_platform = memcmp(bup_boot_device(bupctx), "/dev/mtd", 8) == 0;

gptctx = gpt_init(bup_gpt_device(bupctx), 512);
if (gptctx == NULL) {
perror("boot sector GPT");
Expand Down

0 comments on commit 613cb37

Please sign in to comment.