Skip to content

Commit

Permalink
Merge branch pull request #11 into aspeed-dev-v2019.04
Browse files Browse the repository at this point in the history
Change-Id: I558d5a04f25c77da71b9ef210e4f37ecd0c49dc1
  • Loading branch information
ChiaweiW committed Jul 28, 2022
2 parents 64d46a4 + aad8f35 commit 64e8c66
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 62 deletions.
32 changes: 16 additions & 16 deletions arch/arm/dts/ast2600.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@
#interrupt-cells = <1>;

reg = <0x80 0x80 0xC00 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -809,7 +809,7 @@
#interrupt-cells = <1>;

reg = <0x100 0x80 0xC20 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 111 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -822,7 +822,7 @@
#interrupt-cells = <1>;

reg = <0x180 0x80 0xC40 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 112 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -834,7 +834,7 @@
#interrupt-cells = <1>;

reg = <0x200 0x40 0xC60 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -846,7 +846,7 @@
#interrupt-cells = <1>;

reg = <0x280 0x80 0xC80 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -858,7 +858,7 @@
#interrupt-cells = <1>;

reg = <0x300 0x40 0xCA0 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -870,7 +870,7 @@
#interrupt-cells = <1>;

reg = <0x380 0x80 0xCC0 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 116 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -882,7 +882,7 @@
#interrupt-cells = <1>;

reg = <0x400 0x80 0xCE0 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 117 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -894,7 +894,7 @@
#interrupt-cells = <1>;

reg = <0x480 0x80 0xD00 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 118 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -906,7 +906,7 @@
#interrupt-cells = <1>;

reg = <0x500 0x80 0xD20 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -919,7 +919,7 @@
#interrupt-cells = <1>;

reg = <0x580 0x80 0xD40 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -932,7 +932,7 @@
#interrupt-cells = <1>;

reg = <0x600 0x80 0xD60 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 121 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -945,7 +945,7 @@
#interrupt-cells = <1>;

reg = <0x680 0x80 0xD80 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 122 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -958,7 +958,7 @@
#interrupt-cells = <1>;

reg = <0x700 0x80 0xDA0 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -971,7 +971,7 @@
#interrupt-cells = <1>;

reg = <0x780 0x80 0xDC0 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 124 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand All @@ -984,7 +984,7 @@
#interrupt-cells = <1>;

reg = <0x800 0x80 0xDE0 0x20>;
compatible = "aspeed,ast2600-i2c";
compatible = "aspeed,ast2600-i2c-bus";
bus-frequency = <100000>;
interrupts = <GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&scu ASPEED_CLK_APB2>;
Expand Down
7 changes: 2 additions & 5 deletions cmd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -616,13 +616,10 @@ menu "Device access commands"

config CMD_OTP
depends on ASPEED_AST2600
depends on SHA256 && SHA384 && SHA512
bool "ASPEED otp program"
select SHA512_ALGO
select SHA512
select SHA384
select SHA256
select HASH
select RSA
select ASPEED_ACRY
default y

config CMD_RNG
Expand Down
63 changes: 24 additions & 39 deletions cmd/otp.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ struct otpstrap_status {
};

struct otpkey_type {
int value;
int key_type;
int order;
int need_id;
char information[110];
int value: 4;
int key_type: 4;
int order: 1;
int need_id: 1;
char *information;
};

struct otp_pro_sts {
Expand Down Expand Up @@ -305,33 +305,6 @@ static int get_rid_num(u32 *rid)
return rid_num;
}

static void sb_sha256(u8 *src, u32 len, u8 *digest_ret)
{
sha256_context ctx;

sha256_starts(&ctx);
sha256_update(&ctx, src, len);
sha256_finish(&ctx, digest_ret);
}

static void sb_sha384(u8 *src, u32 len, u8 *digest_ret)
{
sha512_context ctx;

sha384_starts(&ctx);
sha384_update(&ctx, src, len);
sha384_finish(&ctx, digest_ret);
}

static void sb_sha512(u8 *src, u32 len, u8 *digest_ret)
{
sha512_context ctx;

sha512_starts(&ctx);
sha512_update(&ctx, src, len);
sha512_finish(&ctx, digest_ret);
}

static u32 chip_version(void)
{
u32 revid0, revid1;
Expand Down Expand Up @@ -1912,18 +1885,30 @@ static int otp_check_scu_image(struct otp_image_layout *image_layout, u32 *scu_p
return OTP_SUCCESS;
}

static void do_hash(const void *data, int data_len, const char *algo_name, uint8_t *value)
{
struct hash_algo *algo;

if (hash_lookup_algo(algo_name, &algo)) {
debug("Unsupported hash alogrithm\n");
return;
}

algo->hash_func_ws(data, data_len, value, algo->chunk_size);
}

static int otp_verify_image(u8 *src_buf, u32 length, u8 *digest_buf, int version)
{
u8 digest_ret[48];
int digest_len;

switch (version) {
case 1:
sb_sha256(src_buf, length, digest_ret);
do_hash(src_buf, length, "sha256", digest_ret);
digest_len = 32;
break;
case 2:
sb_sha384(src_buf, length, digest_ret);
do_hash(src_buf, length, "sha384", digest_ret);
digest_len = 48;
break;
default:
Expand Down Expand Up @@ -2549,13 +2534,13 @@ static int sb_sha(struct sb_info *si, u8 *sec_image, u32 sign_image_size, u8 *di
printf("otp verify does not support SHA224\n");
return OTP_FAILURE;
case 256:
sb_sha256(sec_image, sign_image_size, digest_ret);
do_hash(sec_image, sign_image_size, "sha256", digest_ret);
break;
case 384:
sb_sha384(sec_image, sign_image_size, digest_ret);
do_hash(sec_image, sign_image_size, "sha384", digest_ret);
break;
case 512:
sb_sha512(sec_image, sign_image_size, digest_ret);
do_hash(sec_image, sign_image_size, "sha512", digest_ret);
break;
default:
printf("SHA Algorithm is invalid\n");
Expand Down Expand Up @@ -2642,9 +2627,9 @@ static int otp_verify_boot_image(phys_addr_t addr)
int i;
int pass = 0;

ret = uclass_get_device_by_driver(UCLASS_MOD_EXP, DM_GET_DRIVER(aspeed_acry), &mod_exp_dev);
ret = uclass_get_device(UCLASS_MOD_EXP, 0, &mod_exp_dev);
if (ret) {
printf("RSA engine: Can't find aspeed_acry\n");
printf("RSA: Can't find RSA driver\n");
return OTP_FAILURE;
}

Expand Down
3 changes: 2 additions & 1 deletion drivers/i2c/aspeed_i2c_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static int aspeed_i2c_global_probe(struct udevice *dev)

reset_deassert(&i2c_global->reset);

if (i2c_global->version == AST2600_I2C_GLOBAL) {
if (IS_ENABLED(SYS_I2C_AST2600) &&
i2c_global->version == AST2600_I2C_GLOBAL) {
writel(AST2600_GLOBAL_INIT, i2c_global->regs +
AST2600_I2CG_CTRL);
writel(I2CCG_DIV_CTRL, i2c_global->regs +
Expand Down
2 changes: 1 addition & 1 deletion drivers/i2c/ast2600_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static const struct dm_i2c_ops ast2600_i2c_ops = {
};

static const struct udevice_id ast2600_i2c_ids[] = {
{ .compatible = "aspeed,ast2600-i2c" },
{ .compatible = "aspeed,ast2600-i2c-bus" },
{},
};

Expand Down

0 comments on commit 64e8c66

Please sign in to comment.