Commit Graph

1012 Commits

Author SHA1 Message Date
Joseph Chen eb89f0a81d lib: avb: add partition slot append interface
Dump current slot information is helpful.

Change-Id: I872c29b9a67860703951a4e88e9549be17b94eed
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-11-04 15:43:46 +08:00
Joseph Chen 5704c899ed fdtdec: support pack "kern.dtb" to the end of u-boot.bin
- It provides a way to promise kernel dtb can be loaded successfully
  even when the image is damaged.
- This makes developers easily to add what they what just like a "U-Boot" dtb.
- The kern.dtb file is pack into the end of u-boot.bin while ./dts/kern.dtb
  is exist.

Change-Id: I93a36a9c65ea8719e5610cdcbcc7708e5337c53f
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-11-04 14:53:45 +08:00
Joseph Chen bcf005ba08 lib: sysmem: no need to increase alloc size when base is 0
Change-Id: Ia716956e1a0e980330d6a7f7eb6c89f91e133ddf
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-11-04 10:23:52 +08:00
Joseph Chen d65bf0c630 lib: sysmem: fix alloc failed at 0x0 address
The 0x0 address is usually allocated by 32-bit uncompressed kernel
and this alloc action is just a peek. Due to LMB core doesn't support
alloc at 0x0 address, we have to alloc the memblk backword a few bytes.

This patch is mainly to avoid fail message from sysmem/LMB.

Change-Id: I894ae2252a30a7690d10899484266191dfb12d15
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-10-31 16:39:43 +08:00
Jason Zhu 69fdc5969f lib: avb: update and modify the avb library
The commit point is updated to google external/avb/
which commit point is 868db2a514bbb02e166fb55b1592b27de8c9680c.

Change-Id: I10f7c0ac356a7666b518b62e59ccb62277668578
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-09-20 08:50:37 +08:00
Jason Zhu c2bb0fd141 lib: avb: print the permanent attribute certificate is exist or not
Change-Id: I10775dd06a6fb1bfdddcfda37fe2e1178c3fde21
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-09-18 10:34:40 +08:00
Joseph Chen 2227535d49 lib: add sha512 support
Porting from: https://tls.mbed.org/sha-512-source-code.

Update and follow sha1/256.c function name and coding style.

Change-Id: Idbe70b71e54e0e56a88aac5ec306c75fb2237f4f
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-08-02 10:34:33 +08:00
Joseph Chen acffe33271 lib: sysmem: add sysmem_alloc_by_name() interface
Change-Id: I9e2fd6d99fdc487396dd9619dc54567bcd2ba242
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-07-22 14:23:50 +08:00
Joseph Chen 50226c8f95 lib: sysmem: optimise alloc policy
- Allow request region alloc within the first invisiable region reserved by
  bidram when request region has flags M_ATTR_IGNORE_INVISIBLE. This is a
  workaround for some firmware memory layout, eg: on RK3308-AArch32, the ATF
  region is 0~1M(same as RK3308-AArch64), but the kernel would like to alloc
  at 0x00058000.

- Always make kernel reserved-memory alloc successfully and check overlap
  with invisible and sysmem allocated regions in sysmem_overflow_check()
  before bootm. This makes alloc policy more easier.

Change-Id: I533c710a6e69bd930befda441b9ec64415e3f408
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-07-22 14:23:50 +08:00
Joseph Chen fc7ff0f015 lib: bidram: add bidram_reserved_is_overlap() interface
Check if the region is overlap with reserved regions.

Change-Id: Ifd9b6a4438dcf954b7e48930e31d0c6cd5d1274c
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-07-22 14:23:49 +08:00
Hisping Lin b9a7e756c4 lib: optee_client: change the condition for eMMC devices
1.dev_desc->if_type == IF_TYPE_MMC for SD and eMMC device,
  dev_desc->devnum == 1 is SD devices,
  dev_desc->devnum == 0 is eMMC devices
2.SD devices do not have rpmb
3.we prefer to use rpmb for eMMC devices, use security
  partition for nand or SD devices

Change-Id: Ifc21bd4da7c3ee91e2ecc845c343182c78d52dc1
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-07-15 17:06:52 +08:00
Hisping Lin 0202ee8aef lib: optee_client: vboot enable if read bootflag == 1 for rk3288
Change-Id: Ic59341a3bd386a5d05cc501a6841556a6375572a
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-07-15 14:33:40 +08:00
Jason Zhu 3120d9d50e avb: do not use lastboot if enable CONFIG_ANDROID_AVB
The avb process have verify next level firmware to ensure its
availability. So there is no need to support lastboot in avb
process.

Change-Id: I1623a2bd93c54802ce0067cad7061ade6cc56313
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-07-09 16:38:02 +08:00
Alexey Brodkin 28386b6dc6 UPSTREAM: lib: Add hexdump
Often during debugging session it's very interesting to see
what data we were dealing with. For example what we write or read
to/from memory or peripherals.

This change introduces functions that allow to dump binary
data with one simple function invocation like:
------------------->8----------------
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len);
------------------->8----------------

which gives us the following:
------------------->8----------------
00000000: f2 b7 c9 88 62 61 75 64 72 61 74 65 3d 31 31 35  ....baudrate=115
00000010: 32 30 30 00 62 6f 6f 74 61 72 67 73 3d 63 6f 6e  200.bootargs=con
00000020: 73 6f 6c 65 3d 74 74 79 53 33 2c 31 31 35 32 30  sole=ttyS3,11520
00000030: 30 6e 38 00 62 6f 6f 74 64 65 6c 61 79 3d 33 00  0n8.bootdelay=3.
00000040: 62 6f 6f 74 66 69 6c 65 3d 75 49 6d 61 67 65 00  bootfile=uImage.
00000050: 66 64 74 63 6f 6e 74 72 6f 6c 61 64 64 72 3d 39  fdtcontroladdr=9
00000060: 66 66 62 31 62 61 30 00 6c 6f 61 64 61 64 64 72  ffb1ba0.loadaddr
00000070: 3d 30 78 38 32 30 30 30 30 30 30 00 73 74 64 65  =0x82000000.stde
00000080: 72 72 3d 73 65 72 69 61 6c 30 40 65 30 30 32 32  rr=serial0@e0022
00000090: 30 30 30 00 73 74 64 69 6e 3d 73 65 72 69 61 6c  000.stdin=serial
000000a0: 30 40 65 30 30 32 32 30 30 30 00 73 74 64 6f 75  0@e0022000.stdou
000000b0: 74 3d 73 65 72 69 61 6c 30 40 65 30 30 32 32 30  t=serial0@e00220
000000c0: 30 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00  00..............
...
------------------->8----------------

Source of hexdump.c was copied from Linux kernel v4.7-rc2.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Anatolij Gustschin <agust@denx.de>
Cc: Mario Six <mario.six@gdsys.cc>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
Cc: Stefan Roese <sr@denx.de>

Change-Id: I038b41f51d45d1b853da499578bf8ef384a63730
Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
(cherry picked from commit f8c987f8f127f867d96ca74bcd1fcb11d8265b67)
2019-07-05 19:33:39 +08:00
Jason Zhu 63a580aed3 lib: avb: the rsa_key.c is used when enable CONFIG_ROCKCHIP_CRYPTO_V1
Change-Id: If266df70d0969d5a3556e505f39b853cf818a338
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-07-03 09:34:10 +08:00
Jason Zhu c46b3f6d96 lib: add stdlib.c
Since we need to realize standard library function other than use them
with gcc tool chain in U-Boot. So add standard library function here.

Change-Id: I10009c5bbe31fabacd929df3c44218ae9c6a885f
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-07-01 19:17:50 +08:00
Hisping Lin 266906806d lib: optee_client: init rpmb before find_mmc_device
Change-Id: I1f2c3d76c9015f1a59822314df5e92b6355c7827
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-06-26 11:23:32 +08:00
Joseph Chen 2c66f6f37e lib: sysmem: add sysmem overflow check support
Change-Id: Ifcb6e8cd59656b133f56115d104a1bba017c7c1b
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-06-26 11:23:12 +08:00
Joseph Chen 556bbbe436 lib: sysmem: add M_ATTR_CACHELINE_ALIGN support
If alloc buffer for storage read/write should be aligned to
cacheline size, please add the M_ATTR_CACHELINE_ALIGN flag
for this region.

Change-Id: I1e5d46405ddacfadd1cdb4670f943996d9b66426
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-06-26 11:23:03 +08:00
Yifeng Zhao e91ae64f65 lib: rockchip: nand: modify udevice_id to compatible with NAND driver include FTL
Modify the opensource nandc driver to compatible with
the NAND driver include FTL,which used udevice_id
"rockchip,rk-nandc".

Change-Id: I67b9beb43b9935f88c98802f6df3507248324a12
Signed-off-by: Yifeng Zhao <zyf@rock-chips.com>
2019-06-25 11:23:21 +08:00
Jason Zhu 4a7c178034 lib: avb: change the hardware rsa verified interface
Change-Id: Id42cf3a829a35514b75f3c5990ce7e00b94f712e
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-06-24 18:31:36 +08:00
Hisping Lin d47d99649e lib: optee_client: v1 add security partition offset when backup data
Change-Id: I331b95c1df8c0124568aad5ee7351bc270946af6
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-06-05 12:30:21 +08:00
Hisping Lin e8c34540a6 lib: optee_client: v2 add security partition offset when backup data
Change-Id: I9abbef68e56c0b2870426e91138bb110240ed69c
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-06-05 12:30:21 +08:00
Joseph Chen 598774ec05 lib: sysmem: add optimization for input base and M_ATTR_PEEK
- handle the case: the input base is 0;
- ignore the head region which can't visible for M_ATTR_PEEK;

Change-Id: I2c3609b9457a5e2e429e849228301bfee0e4c9b0
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-28 20:30:36 +08:00
Joseph Chen 89151b4aad lib: avb: use sysmem alloc to load image
Using malloc buffer to load image makes CONFIG_SYS_MALLOC_LEN must be
large enough, sysmem alloc is a better way.

Change-Id: I24e2b86c53b8d3307c0d155fc37cb499c321e1c6
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-22 15:30:20 +08:00
Joseph Chen 661cbb0b92 lib: sysmem: goto out when alloc failed
Change-Id: I8f6fd82f7367c49596475a88bafd19137e2f2f7c
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-15 11:02:14 +08:00
Joseph Chen 3bee194f53 lib: sysmem: add sysmem_can_alloc() interface
Check if the region can be sysmem allocated.

Change-Id: I26a524c1597bee65ab1282da5ec373b9603866ba
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-07 19:46:37 +08:00
Joseph Chen f6e1530165 lib: sysmem: support avb android memblk sysmem alloc
Because avb android image usually needs a large memory buffer,
always alloc avb android memblk right after U-Boot stack is a
better choice to avoid memblk overlap with others.

Since we have overflow protect magic for U-Boot stack, so we add
a pad(4KB) between them.

Change-Id: I72655d022f7e82f1ed9fbb381424d04bc86ccf6a
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-07 19:46:37 +08:00
Joseph Chen dcb404a677 lib: sysmem: add sysmem_alloc() interface
Change-Id: I3ae1fe618ba1bb9c7924bb9816884eb26927dc1e
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-07 19:46:37 +08:00
Joseph Chen efda1f1db3 lib: sysmem: support M_ATTR_PEEK for memblk
- always return successful for M_ATTR_PEEK;
- add code comments;

Change-Id: I3c7f939ac61d8da5948978de4e70f17576748c91
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-07 17:08:36 +08:00
Hisping Lin efb93541fe lib: optee_client: add module name in print func
Change-Id: I6cdcb0870bf5a3915009421e5c8b09584ac2bb6c
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-04-29 11:09:18 +08:00
Jason Zhu 4f2523c3a0 lib: avb: load full partition if allow verification error
Change-Id: I506676512a46ec09d6c617f555f735a24fc4a594
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-04-29 11:08:08 +08:00
Jason Zhu 813227ad54 lib: avb: add init ab metadata interface
Change-Id: Ifad6c8ca70568c2dc8eea0a4ead23e3e7a2a0e74
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-04-29 11:05:35 +08:00
Joseph Chen 305d8903e0 lib: sysmem: improve kernel reserved-memory alloc
- If the region is out of avaiable dram bank, return success;
- region can override allocated memblk with attr M_ATTR_OVERLAP;

Change-Id: I02171cdb51462e9cec3dd955ae3e0aaaa0ee7afd
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-04-03 10:29:03 +08:00
Joseph Chen 2cb995bc2e lib: sysmem: allow alloc subset of an allocated memblk
Change-Id: I171c5978faf6fc1b3e95cc46c55a2adfe6df0176
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-29 18:29:19 +08:00
Joseph Chen 356575c3e2 lib: bidram: handle only-one dram bank available situation
LMB default init lmb->reserved.region[0] as zero.

Change-Id: Ib46d9630581bb3a03c5846288b16ae805e3e6944
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-29 18:29:19 +08:00
Hisping Lin b86137850e lib: optee_client: change condition for file exist
file not exist if ret < 0, file exist if ret >=0

Change-Id: I1a70b0a41773f03d552c5f6cda82b745d6e81421
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-03-28 14:46:42 +08:00
Joseph Chen a90f2861de lib: sysmem: fix NULL attr.name
Change-Id: I93744c28668d1533ec2bcdaafc9198d8557284a1
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-27 08:59:47 +08:00
Joseph Chen 483d049321 lib: introduce bidram for GD board bi_dram[] memory management
Some platform provides more than one dram banks and reserved firmware
regions (eg. ATF, OP-TEE, etc) by pre-loader dynamically. It means
there are memory holes in board dram layout. What's more, U-Boot will
reserved regions at the late bootflow(eg. firmware reserved for AMP).

So we introduce bidram mechanism to manage GD board bi_dram[], which
provides a way to easily manage memory holes and update bi_dram[]. It
dpends on LMB which provides a good algorithm to manage memory blocks.

What's different from sysmem?
- bidram manage and pass the avaliable memory blocks to kernel;
- sysmem is only for U-Boot memory management to avoid ram overlap,
  it doesn't matter about kernel avaliable memory.

Change-Id: I697cbb80bdc961e4ad5ab94548e2dc93feefde6f
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-26 11:04:33 +08:00
Joseph Chen 6e15146eff lib: sysmem: refactor code
- import memblk id to manage memory blocks;
- change "sysmem_property" to generic "memblock";
- use alloc instead of reserve for all memory blocks;
- clean up and fix some logic;
- add U-Boot cmd for sysmem;

Change-Id: I614223ce3bf97a7b3566412a9d1864fb30b68fd8
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-26 11:04:33 +08:00
Joseph Chen ee561e345b lib: avb: AVB_VBMETA_PUBLIC_KEY_VALIDATE select CONSOLE_DISABLE_CTRLC
Clean coding style by the way.

Change-Id: Ib614175e9ea7ceebc49030235b66d82adc57d3a0
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-20 15:08:14 +08:00
Hisping Lin b4a0434fc9 lib: optee_client: do not init RK FS if security not exist
Change-Id: I91e780448cee7884c7477cb0b5720f962b2df00d
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-03-15 15:28:38 +08:00
Hisping Lin 472ddf73a4 lib: optee_client: add support for power-off protection
Change-Id: I4babcc1989563a3c707a1cac7e93069031f033dd
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-03-15 15:28:38 +08:00
Keerthy e217fe3cbd lib: fdtdec: fdtdec_get_addr_size_fixed remove checks
With 8 bytes addressing even on 32 bit machines these checks
are no longer valid. Remove them.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
(cherry picked from commit f51f6715a5013f37620c38f0430e21d4736e235a)
Signed-off-by: Andy Yan <andy.yan@rock-chips.com>

Change-Id: I07d143dbd4dfeff1ce99d081d1279c4f70fa4e8f
2019-03-12 14:40:07 +08:00
Jason Zhu 74b485fb2b fastboot: delete write perm-attr hash if use pre-loader pub_key
Since we use the pre-loader public key to verify permanent attribute, then
we do not need to write permanent attribute hash to otp & efuse.

Change-Id: Ic5e19fed2fc9405ab5bc7504dd930fd5f02d847c
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-08 18:12:14 +08:00
Jason Zhu 65f0143b26 lib: avb: verify the perm attr by root public key
Change-Id: I7e06152a21325ffcd785223952fe8ffaff4d5f08
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-08 15:32:09 +08:00
Jason Zhu 1f670f7cc9 lib: avb: get public key by atags
Change-Id: I0d77229585263e81e8be4f5c67a02080c07b0e55
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-08 15:32:09 +08:00
Jason Zhu 9b83ce70a9 lib: avb: add get&set perm-attr cer
Change-Id: I89d3a30f43659ae8c9d107ede5db1590b022440d
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-08 15:32:09 +08:00
Hisping Lin f4e1db9544 lib: optee_client: add judgment of return value
Change-Id: If616f89ffb2c3ea30afb7bced56a1ca28b1232b2
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-03-06 18:44:39 +08:00
Jason Zhu 7cca3dd4d7 lib: avb: support last boot
Change-Id: I803e3deda068be34061a302c27009db5e444f290
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-06 17:16:13 +08:00
Jason Zhu 4454e90b43 lib: avb: change the output memssage I/O
Since the stderr is not used in uboot, use printf to print the
message.

Change-Id: Ib522609e783acf8f407e2f9fb3805b553c543cba
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-06 17:16:13 +08:00
Joseph Chen 727ebf6de1 lib: sysmem: alloc base and size must be 4-byte aligned
Change-Id: Icf59ee6522f2e0793605b03b0bcf05b58585069f
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-04 09:21:58 +08:00
Joseph Chen 0a53d515e6 lib: initcall: add system total boot time debug
Change-Id: I3d4cd151acf699b25c9caab0452e40fddb6c31e1
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-02-25 09:59:46 +08:00
Joseph Chen 595f057c4e lib: Kconfig: set SYS_STACK_SIZE 2MB size
128KB maybe not enough at sometimes.

Change-Id: I06746b98e005955d4b88904c04ed0af753db6acf
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-02-25 09:59:46 +08:00
Joseph Chen 2c9d117912 sysmem: fdt: reserve more CONFIG_SYS_FDT_PAD size for fdt
Sometimes, framework or user would call fdt_increase_size() to update
fdt size, it's better reserve more space to avoid sysmem gives the fdt
region overflow report.

The CONFIG_SYS_FDT_PAD default value is sync with bootm framework
in: common/image-fdt.c

Change-Id: I363e9a4182e13b1628a76666acd8272d25db659d
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-02-19 14:37:36 +08:00
Joseph Chen 3befe43d90 lib: sysmem: ignore sysmem reserve warning
Change-Id: I970da1456388f825a351dc26d725bb3ba10d41a4
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-02-19 09:10:17 +08:00
Hisping Lin 68ba937304 lib: optee_client: recover original partition after error
1.switch to RPMB partition when call init rpmb
2.switch to original partition when call finish rpmb
3.it will not switch to original partition when error
  occurred, we should recover original partition after error

Change-Id: I41927e82fb2db690058a809f008ca1f59d334011
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-02-14 19:58:09 +08:00
Hisping Lin df99e5808c cmd: add test case for secure storage
1.mmc testsecurestorage to test secure storage
2.test secure storage in rpmb and test secure storage in
  security partition when use emmc
3.test secure storage in security partition when use nand

Change-Id: Id6f72893c002c5040cb1790051c9685911878df7
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-02-14 19:58:09 +08:00
Joseph Chen 7f28cbb61e lib: Kconfig: add CONFIG_SYS_STACK_SIZE
Change-Id: I37cb4ffea5ef6aa2475a3ca7a87f58f23fcff76a
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-02-13 09:03:59 +08:00
Jason Zhu 564654eb9c lib: optee_client: add read&wite permanent attributes certificate
Change-Id: I83321afcf9d89b0cde0bcc78f1f02c847f85a115
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-01-28 20:42:54 +08:00
Joseph Chen ffa8f8b76e lib: introduce sysmem for permanent memory management
U-Boot provides MALLOC for runtime temporary memory management and
LMB for bootm memory management. There is not a mechanism for permanent
memory management. so that the memory blocks are easy to overlap with
each other.

What does permanent memory mean ?
 - The memory can't be touched by U-Boot(ATF/OPTEE/SHM/kernel-reserved, etc);
 - The memory occupied even in kernel, such as some firmware load buffer;

This patch introduces sysmem to do permanent memory management, which
implements base on LMB. It provides memory block (pool):
 - init;
 - add;
 - alloc;
 - free;
 - reserve;
 - stat;
 - overflow check;

Here is an example for RK3399 sysmem boot stat(assume the "fdt" region is Overflow)
called by sysmem_dump_all():

sysmem_dump_all:
    ------------------------------------------------------
    memory.rgn[0].base     = 0x00000000
                 .size     = 0x00000000
    memory.rgn[1].base     = 0x00200000
                 .size     = 0x08200000
    memory.rgn[2].base     = 0x0a200000
                 .size     = 0x75e00000

    memory.total           = 0x7e000000 (2016 MiB. 0 KiB)
    ------------------------------------------------------
    reserved.rgn[0].name   = "ATF"
                   .base   = 0x00000000
                   .size   = 0x00100000
    reserved.rgn[1].name   = "PSTORE/ATAGS/SHM"
                   .base   = 0x00100000
                   .size   = 0x00100000
    reserved.rgn[2].name   = "OP-TEE"
                   .base   = 0x08400000
                   .size   = 0x01e00000
    reserved.rgn[3].name   = "U-Boot"
                   .base   = 0x71be03c0
                   .size   = 0x0e41fc40
    reserved.rgn[4].name   = "secure-memory@20000000"
                   .base   = 0x20000000
                   .size   = 0x10000000

    reserved.total         = 0x2041fc40 (516 MiB. 127 KiB)
    ------------------------------------------------------
    allocated.rgn[0].name  = "fdt"      (Overflow)
                    .base  = 0x01f00000
                    .size  = 0x00009704
    allocated.rgn[1].name  = "kernel"
                    .base  = 0x0027c000
                    .size  = 0x0129da04
    allocated.rgn[2].name  = "ramdisk"
                    .base  = 0x0a200000
                    .size  = 0x001e6c04

    allocated.total        = 0x0148dd0c (20 MiB. 567 KiB)
    ------------------------------------------------------
    LMB.reserved[0].base   = 0x00000000
                   .size   = 0x00200000
    LMB.reserved[1].base   = 0x0027c000
                   .size   = 0x0129da04
    LMB.reserved[2].base   = 0x01f00000
                   .size   = 0x00009704
    LMB.reserved[3].base   = 0x08400000
                   .size   = 0x01fe6c04
    LMB.reserved[4].base   = 0x20000000
                   .size   = 0x10000000
    LMB.reserved[5].base   = 0x71be03c0
                   .size   = 0x0e41fc40

    reserved.core.total    = 0x218ad94c (536 MiB. 694 KiB)
    ------------------------------------------------------

Change-Id: If63b7abed2cdd3c054719511fcceed733ddf606d
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-01-24 15:33:12 +08:00
Jian Qiu c2ba77d93f lib: optee_client: Extract keymaster CA module
Extract keymaster CA module from OpteeClientInterface
refactoring code for keymaster reads and writes form caller module

Change-Id: I1069fce0d29d9d9815f71e7f3b4d231754382acd
Signed-off-by: Jian Qiu <qiujian@rock-chips.com>
2019-01-18 09:09:34 +08:00
Tony Xu dfbf26e839 lib: optee_client: move keybox code to write_keybox.c
Change-Id: Ifcd9962a8b802ee2bcbdbd0e88effb4485e5963a
Signed-off-by: Tony Xu <tony.xu@rock-chips.com>
2019-01-16 18:10:16 +08:00
Jason Zhu ee9d343315 lib: avb: fix fail to read PIK minimum
Do not update the PIK version if it is equal to the value in the storage,
otherwise the error may occur in power failure test.

Change-Id: Ia478d9b404de3982b4de5b185e15d181b37f5fd9
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-01-16 17:59:46 +08:00
Hisping Lin aa04de65ce lib: optee_client: optimizing print information
Change-Id: I37e6dc56b8eb46bc6d0a2c12bbd4c329d35ca687
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2019-01-10 18:24:41 +08:00
Joseph Chen b2a1587371 lib: avb: add more help info for AVB_VBMETA_PUBLIC_KEY_VALIDATE
Change-Id: I2c63850244983144a6b5ac8303f1debc7a37cb2a
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-01-03 09:53:29 +08:00
Hisping Lin 40f13eb771 lib: optee_clientApi: write table when verify table fail
Change-Id: I38d055945da5bf183e34588a08d8964c2d810f5f
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-12-29 14:39:42 +08:00
Masahiro Yamada 0e00a84cde UPSTREAM: libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>
Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
  include/libfdt.h         -> include/linux/libfdt.h
  include/libfdt_env.h     -> include/linux/libfdt_env.h

and replaces include directives:
  #include <libfdt.h>      -> #include <linux/libfdt.h>
  #include <libfdt_env.h>  -> #include <linux/libfdt_env.h>

Change-Id: I6c0f7e50e8b571106627f25ddac008a62bd2994e
Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2018-12-24 17:20:37 +08:00
Masahiro Yamada 02f12fd1d3 UPSTREAM: libfdt: migrate libfdt.h to a wrapper + U-Boot own code
There is tons of code duplication between lib/libfdt/libfdt.h and
scripts/dtc/libfdt/libfdt.h.  Evacuate the U-Boot own code to
include/libfdt.h and remove lib/libfdt/libfdt.h.

For host tools, <libfdt.h> should include scripts/dtc/libfdt/libfdt.h,
which is already suitable for user-space.

For compiling U-Boot, <linux/libfdt.h> should be included because we
need a different libfdt_env.h .

Change-Id: I61a718a3fecb9f316cf3ddbac7c125394532a9c5
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2018-12-24 17:20:37 +08:00
Masahiro Yamada 4e2c3b8c76 UPSTREAM: libfdt: migrate fdt_rw.c to a wrapper of scripts/dtc/libfdt/fdt_rw.c
The only difference between scripts/dtc/libfdt/fdt_rw.c and
lib/libfdt/fdt_rw.c is fdt_remove_unused_strings().

It is only used by fdtgrep, so we do not need to compile it for U-Boot
image.  Move it to tools/libfdt/fdw_rw.c so that lib/libfdt/fdt_rw.c
can be a wrapper of scripts/dtc/libfdt/fdt_rw.c.

Change-Id: I6e2578d4bfdf75438d3aa1cb51f270f34527d37d
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2018-12-24 17:20:37 +08:00
Kever Yang 260eab1873 rockchip: video: use common API instead of private
We can use fdtdec_get_is_enabled() instead of fdt_device_is_available().

Change-Id: I7aa03ed82f83fc72206659889a4f7f095dc66b36
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2018-12-24 17:20:37 +08:00
Joseph Chen caed6b4f82 rockchip: make avb boot flow uninterruptable
- only allow "boot_android" as bootcmd;
- enter rockusb or fastboot when boot failed;
- don't allow ctrl+c to enter hush;

Change-Id: I7a67f4b738ed78370f19fe2c8c920a5abc104b4b
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-12-12 11:00:47 +08:00
Joseph Chen a349065b9f avb: Kconfig: add config AVB_VBMETA_PUBLIC_KEY_VALIDATE
Change-Id: I2f9c74a8427874066e1bb7ac7b774a0fb3befba9
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-12-12 11:00:47 +08:00
Joseph Chen 36ba3f8d39 lib: initcall: add time cost verbose
This is more helpful than bootstage timing record since it
is quite possible for every developer to enable inicall
verbose for debug and find abnormal time cost as early as
possible.

It looks like:
  initcall: 000000000061015c
                                                                  #   183 us
  initcall: 000000000ff3e614
                                                                  #     0 us
  initcall: 000000000ff3e408
                                                                  #     0 us
  initcall: 00000000006105fc (relocated to 000000000ff3e5fc)
                                                                  #  6401 us
  initcall: 0000000000610420 (relocated to 000000000ff3e420)
                                                                  #     1 us
  initcall: 0000000000604444 (relocated to 000000000ff32444)
                                                                  #     5 us
Change-Id: Ib59f3e5052f921d0046a6fa73cbfb968000fd34e
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-12-10 15:13:19 +08:00
Hisping Lin d8100d74a0 lib: optee_client: remove widevine ta from uboot
Change-Id: I9e6e4d6743d0a8e9787c2b01e535d920d4f93008
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-12-06 09:17:57 +08:00
Tony Xu 1e8c0e44aa Attestation key: write attestation key to secure storage
Split attestation key into AttestationKey.ec and AttestationKey.rsa,
then write to secure storage.

Change-Id: I8e00d602c4174a002e6ecad2e4cfa846f32a681f
Signed-off-by: Tony Xu <tony.xu@rock-chips.com>
2018-11-21 10:11:40 +08:00
Hisping Lin 9983001913 lib: optee_client: remove keymaster ta from uboot
keymaster ta is too large, so we change store data
to static ta and remove keymaster ta

Change-Id: Icdb694138caf005d2cb2821714a8526d0391b18b
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-11-13 11:51:51 +08:00
Hisping Lin 099b8ebcd1 lib: optee_client: fix bug for security partition not find
bug make error R&W when security partition is not defined

Change-Id: Iddf840d3f9c090292e58f73492c20f84e4b3b4ea
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-10-30 09:12:33 +08:00
Jian Qiu 4711f91491 lib: optee_client: Reduce keymaster ta size
Change-Id: I2a82e33f92123ba29e6fb456b4e6b35312620e64
Signed-off-by: Jian Qiu <qiujian@rock-chips.com>
2018-10-26 08:54:06 +08:00
Tony Xu f18b06fb49 lib: optee_clientApi: Optimze the function write_keybox_to_secure_storage
Change-Id: Icb88355494eb23c9403fc078adb5f2f46c4a870c
Signed-off-by: Tony Xu <tony.xu@rock-chips.com>
2018-10-16 09:22:57 +08:00
Joseph Chen bcf5a32a7c lib: gzip: lower the message when parse header
Change-Id: Iedd2cbefac99fb17256770dc334741b9e760c449
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-10-07 15:37:50 +08:00
Hisping Lin bdf50261ca lib: optee_client: search security partition once
Change-Id: I4f3fbdb1e319e5b200225353a2d945bebd888f8c
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-09-11 09:52:43 +08:00
Hisping Lin f01cc52bce lib: optee_client: speed up secure store
use R&W multi blocks and cache used flag to
speed up secure store.

Change-Id: Ib534fa33e1bb03006ed3b85992d1d48b5fe36f39
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-09-05 09:23:55 +08:00
Jason Zhu 7c1937d6d1 lib: avb: change judgement value when read from rpmb
If the item is not existent, trust will return TEE_ERROR_GENERIC
TEE_ERROR_NO_DATA and TEE_ERROR_ITEM_NOT_FOUND. We initialize
the item when return these value.

TEST: fastboot getvar at-vboot-state

ERROR: avb-perm-attr-set=0
avb-locked=
avb-unlock-disabled=

Change-Id: Ie1b4e1ce7d1dc419a0af11e5701b0130f2f7f553
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-08-17 11:41:20 +08:00
Jason Zhu 615e0cde57 lib: avb: fix bug HANG in fastboot getvar at-vboot-state
Bug: Run 'fastboot getvar at-vboot-state', then HANG
in the fastboot without any message.

Cause: The fastboot can not decide the vboot size when
the return information size of vboot state is larger
than the VBOOT_STATE_SIZE. This makes the device will not
response to console.

Solution: 1. Enlarge VBOOT_STATE_SIZE. The max size of
vboot state may be 862, so define VBOOT_STATE_SIZE
to 1000.
2. Use snprintf to get the info.

Change-Id: I2d0fda76ca9034c596993ab27a02cbf2fa550977
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-08-17 11:41:20 +08:00
tony.xu a7df48681a load keybox to secure storage thtough u-boot: u-boot->ca->ta
Change-Id: Ifdf237ec235c791565d2da1b5881df2f1499d422
Signed-off-by: tony.xu <tony.xu@rock-chips.com>
2018-08-15 15:29:43 +08:00
Hisping Lin d156c9ff6f lib: optee_client: v2 client support compile to 32 bits
Change-Id: I25cbbe486016cbe6fb1a6eff440bb7efab46a4c6
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-08-07 10:48:14 +08:00
Joseph Chen bff338f2e6 lib: optee client: printf content end with "\n".
Change-Id: I9a2f503c4e6b3c1f0c117f93fc2f2d429d43dfbc
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-07-14 19:17:01 +08:00
Andy Yan 008aee876a boot_android: add runtime compatible for un/compressed kernel image
This patch add auto parse the compress format of kernel image.
Then decompress the compressed kernel image for arm64, as for
arm32 zImage, we only need to load it to a higher memory, then
the kernel will handle the decompress itself.

Test on RK3308 AARCH64 mode (Cortex A35 816 MHZ) boot with eMMC:

------------------------------------------------------------------
Format    |  Size(Byte) | Ratio | Decomp time(ms) | Boot time(ms) |
-------------------------------------------------------------------
Image     | 7720968     |       |                 |     488       |
-------------------------------------------------------------------
Image.lz4 | 4119448     | 53%   |       59        |     455       |
-------------------------------------------------------------------
Image.lzo | 3858322     | 49%   |       141       |     536       |
-------------------------------------------------------------------
Image.gz  | 3529108     | 45%   |       222       |     609       |
-------------------------------------------------------------------
Image.bz2 | 3295914     | 42%   |       2940      |               |
-------------------------------------------------------------------
Image.lzma| 2683750     | 34%   |                 |               |
-------------------------------------------------------------------

Note: the boot time is counted from first ddr init log to first Kernel log.

Change-Id: I73b12ec944fbc8238b0e061a37e2f31aa3093231
Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
2018-07-14 11:39:04 +08:00
Hisping Lin d5d77aebb0 lib: optee_client: modify macro in Kconfig
CONFIG_OPTEE_ALWAYS_USE_SECURITY_PARTITION is support
for OPTEE_V1

Change-Id: Ic83d06a08a1d409905dcc61e0f7346ab23261b0c
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-07-14 11:37:57 +08:00
Jason Zhu 6651d4c0fb dev_desc: judge dev_desc whether NULL or not before use it
Change-Id: I9d0e2d207a143a02949fbdff2d9ad39f154e4f3e
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-07-04 09:31:05 +08:00
Jason Zhu 8d0db1d983 lib: avb: implement the function get_random()
Use the function get_timer to get the random
seed. Then the seed is used by function srand
to initialize the random data.

Change-Id: Iaae6a17d22b8e85fb4d4b6c6247cd11003b64eea
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-06-14 11:04:46 +08:00
Jason Zhu ab608f806e lib: avb: update avb source code
according to google lib avb
commit id: 44e07124afb1f46af0d745d83481f49c482900b1

Change-Id: Ie59a7265699e3e6b1673bb64da6d1c7a1e7b6201
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-06-13 10:50:36 +08:00
Jason Zhu 57c7f8fe0d lib: avb: support generate unlock challenge
Change-Id: Ia21746ec2bc729fd92ca7ea7a3320dfcbd4dd238
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-06-13 10:50:36 +08:00
Jason Zhu 83ab7b4937 lib: avb: rk: add authenticated unlock interface
Change-Id: Ib2aa1ac07d25f14aa08fc759ec99b6ba64d6abef
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-06-13 10:50:36 +08:00
Hisping Lin cb49af8fa6 lib: optee_client: Change param when get share memory config
Change-Id: I572bf900af26b2c2dcfce23e912b95aa729d786b
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-06-13 08:31:59 +08:00
Hisping Lin 981b79162b lib: optee_client: get share memory config to init
Change-Id: I92fff248650ff239e050fb058ee095e9bed231c6
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-06-06 09:19:41 +08:00
Hisping Lin f303baf0d8 lib: optee_client: optee os v1 support multi file system
Change-Id: I78487659e9fb5b9f2b5d468d587cd00756fdb98c
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-06-06 09:19:41 +08:00
Hisping Lin 58737b30a2 lib: optee_client: update keymaster TA
compile form keymaster 8.0/develop commit:ddd71dca
Features:
	ddd71dca ta: support emmc/nand storage for keymaster & gatekeeper
	2692c551 Update export-user_ta/ to support dual filesystems
	bc288722 keymaster: uboot write data overwrite

Change-Id: I51b84f62db15bd4825035089dbb6ee38d11d4cac
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-06-06 09:19:41 +08:00
Hisping Lin d30aacafd1 lib: optee_client: updata keymaster TA
compile form keymaster 8.1/develop-next commit:9d05fa8a
Features:
	9d05fa8a keymaster: uboot write data delete old obj
	ff399cf0 ta keymaster: fix null point input panic
	186df0e4 keymaster & gatekeeper: rk3326 use partition storage

Change-Id: Id15168f8782d4ab3680b9a424f8eee3843b6aa45
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
2018-04-27 17:01:21 +08:00