mbox series

[v1,0/6] Add Rockchip IDB device

Message ID 1cf06b47-4f0d-2207-8135-3a48826520f0@gmail.com (mailing list archive)
Headers show
Series Add Rockchip IDB device | expand

Message

Johan Jonker July 5, 2022, 1:04 p.m. UTC
From: Johan Jonker <jbx6244@gmail.com>

Add Rockchip IDB device for U-boot.

On Rockchip SoCs with a NAND as boot device the information data base (IDB) loaded
by the boot ROM is stored at the beginning of several erase blocks.
Rewriting NAND blocks makes them wear out, so some spare blocks and a writing strategy
are required. A closed source usbplug uses block: 2,3,4,5,6 for example.
Block 0 and 1 is in use for other data.
For compatible reasons this device follows this approach in line with other
Rockchip products and modules for now.

The Rockchip boot ROM requires a particular file format for booting from NAND:

  It starts with 512-byte (IDB sector 0), RC4 encoded header and is aligned to NAND page size.
  Rockchip fills sector 1,2 and 3 here with more data structures, but that is not required
  by the boot ROM. It just makes it easier to identify the IDB date and version.

  Then 2KB pieces (4 x 512 byte sectors) of spl and tpl data aligned to the NAND page size in a
  fixed pattern with empty pages.

Size of spl and tpl must be aligned to 2KB.
Empty NAND pages/sectors not in use should fill with 0xFF padding to increase NAND durability.

Create a IDB image for the flash tools below with:

#### For RK30 with NAND only ####

printf "RK30" > tplspl.bin
dd if=u-boot-tpl.bin >> tplspl.bin
truncate -s %2048 tplspl.bin
truncate -s %2048 u-boot-spl.bin
./mkimage -v -n rk3066 -T rksd -d ./tplspl.bin:./u-boot-spl.bin out

#### For other Rockchip SoCs with NAND ####

./mkimage -v -n rk3188 -T rksd -d ./u-boot-tpl.bin:./u-boot-spl.bin out

or if more data structures for IDB sector 1, 2 (RC4) and 3 (RC4) are needed then use a custom
image tool as mainline only has basic support for IDB sector 0.

In order to transfer data from a host (PC) via USB existing methods are used.
This driver creates an GPT EFI block driver to work with the
U-boot commands "rockusb" and "ums".
IDB data is inserted 'on the fly' as if it were a normal disk in blocks with 512 byte.
Changing disk parameters is not allowed.

The IDB device driver looks for block driver sector 64 to start with and calculates the IDB size.
When the last sector is received it erases a NAND block and writes IDB sectors to NAND in a pattern.
Written data is verified. If not identical that NAND erase block is freed.
As last thing the remaining IDB blocks are scanned and made available for reading.

Normal U-boot operation contains 2 steps:

1 - start IDB device
2 - start USB gadget (rockusb or ums)

U-boot IDB commands:

idb start - start IDB device
idb stop  - stop IDB blk device
idb info  - show IDB device info

Host (PC) tool commands combinations that work:

U-boot					linux
rockusb 0 idb 0
					upgrade_tool pl
					upgrade_tool wl 64 upgrade_tool_wl_64.bin
					upgrade_tool rl 64 512 upgrade_tool_rl_64_512.bin
					upgrade_tool rd

					rkdeveloptool ppt
					rkdeveloptool wlx loader1 rkdeveloptool_wlx_loader1.bin
					rkdeveloptool wl 64 rkdeveloptool_wl_64.bin
					rkdeveloptool rl 64 512 rkdeveloptool_rl_64_512.bin
					rkdeveloptool rd

					rkflashtool w 64 512 < rkflashtool_w_64_512.bin
					rkflashtool r 64 512 > rkflashtool_r_64_512.bin

ums 0 idb 0
					dd if=ums_0_idb_0_wr.bin of=/dev/sda1
					dd if=/dev/sda1 of=ums_0_idb_0_rd.bin

Tested with:
  MK808 rk3066

Not tested:
  nfc type V8, V9

TODO:
  Looking for advice on what needs to be done to make it fit for mainline. Thanks!

  This is placed in the mach-rockchip directory,
  so we can re-use/combine the source with a usbplug or RK NAND FTL driver
  with no MTD frame work bloatware ;) in a Makefile.

  IDB header V2

  Writing strategy improvement

  etc, etc

Johan Jonker (6):
  rockchip: block: add Rockchip IDB block device
  rockchip: spl: allow more boot devices
  rockchip: rk3066: add Rockchip IDB block device as boot action
  arm: dts: rockchip: sync rk3066/rk3188 DT files from Linux
  arm: dts: rockchip: enable nfc node in spl for rk3066 mk808
  rockchip: configs: mk808: add idb configs

 arch/arm/dts/rk3066a-mk808-u-boot.dtsi |    8 +
 arch/arm/dts/rk3066a-mk808.dts         |   18 +
 arch/arm/dts/rk3066a.dtsi              |    3 +-
 arch/arm/dts/rk3188-radxarock.dts      |    3 +-
 arch/arm/dts/rk3188.dtsi               |   24 +-
 arch/arm/dts/rk3xxx-u-boot.dtsi        |    4 +
 arch/arm/mach-rockchip/Kconfig         |   12 +
 arch/arm/mach-rockchip/Makefile        |    1 +
 arch/arm/mach-rockchip/rk3066/rk3066.c |   11 +
 arch/arm/mach-rockchip/rockchip_idb.c  | 1694 ++++++++++++++++++++++++
 arch/arm/mach-rockchip/spl.c           |    5 +-
 configs/mk808_defconfig                |    4 +
 drivers/block/blk-uclass.c             |    2 +
 include/blk.h                          |    1 +
 include/dm/uclass-id.h                 |    1 +
 include/efi_loader.h                   |    4 +
 lib/efi_loader/efi_device_path.c       |   30 +
 17 files changed, 1812 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/mach-rockchip/rockchip_idb.c

Comments

Michael Nazzareno Trimarchi July 8, 2022, 8:58 a.m. UTC | #1
Hi Johan

On Tue, Jul 5, 2022 at 3:04 PM Johan Jonker <jbx6244@gmail.com> wrote:
>
> From: Johan Jonker <jbx6244@gmail.com>
>
> Add Rockchip IDB device for U-boot.
>
> On Rockchip SoCs with a NAND as boot device the information data base (IDB) loaded
> by the boot ROM is stored at the beginning of several erase blocks.
> Rewriting NAND blocks makes them wear out, so some spare blocks and a writing strategy
> are required. A closed source usbplug uses block: 2,3,4,5,6 for example.
> Block 0 and 1 is in use for other data.
> For compatible reasons this device follows this approach in line with other
> Rockchip products and modules for now.
>
> The Rockchip boot ROM requires a particular file format for booting from NAND:
>
>   It starts with 512-byte (IDB sector 0), RC4 encoded header and is aligned to NAND page size.
>   Rockchip fills sector 1,2 and 3 here with more data structures, but that is not required

I suggest starting to split on what is mandatory and what is optional
here. If possible remove CamelCase
definition of variables. Try to split the first patches in small chunk
so it's easy to discuss a bit more

>   by the boot ROM. It just makes it easier to identify the IDB date and version.
>

Looks like this is rockchip specific. As far as I understand, all the
exposed information can be written from rockchip closed/source
tools. I don't have a rockchip board with Nand to test. Rather prefer
to go with some initial an minimalistic approach and see how look like

In nxp we have only a small tool in uboot able to program the nand. Do
you think that same approach is possible in rockchip?

Michael


>   Then 2KB pieces (4 x 512 byte sectors) of spl and tpl data aligned to the NAND page size in a
>   fixed pattern with empty pages.
>
> Size of spl and tpl must be aligned to 2KB.
> Empty NAND pages/sectors not in use should fill with 0xFF padding to increase NAND durability.
>
> Create a IDB image for the flash tools below with:
>
> #### For RK30 with NAND only ####
>
> printf "RK30" > tplspl.bin
> dd if=u-boot-tpl.bin >> tplspl.bin
> truncate -s %2048 tplspl.bin
> truncate -s %2048 u-boot-spl.bin
> ./mkimage -v -n rk3066 -T rksd -d ./tplspl.bin:./u-boot-spl.bin out
>
> #### For other Rockchip SoCs with NAND ####
>
> ./mkimage -v -n rk3188 -T rksd -d ./u-boot-tpl.bin:./u-boot-spl.bin out
>
> or if more data structures for IDB sector 1, 2 (RC4) and 3 (RC4) are needed then use a custom
> image tool as mainline only has basic support for IDB sector 0.
>
> In order to transfer data from a host (PC) via USB existing methods are used.
> This driver creates an GPT EFI block driver to work with the
> U-boot commands "rockusb" and "ums".
> IDB data is inserted 'on the fly' as if it were a normal disk in blocks with 512 byte.
> Changing disk parameters is not allowed.
>
> The IDB device driver looks for block driver sector 64 to start with and calculates the IDB size.
> When the last sector is received it erases a NAND block and writes IDB sectors to NAND in a pattern.
> Written data is verified. If not identical that NAND erase block is freed.
> As last thing the remaining IDB blocks are scanned and made available for reading.
>
> Normal U-boot operation contains 2 steps:
>
> 1 - start IDB device
> 2 - start USB gadget (rockusb or ums)
>
> U-boot IDB commands:
>
> idb start - start IDB device
> idb stop  - stop IDB blk device
> idb info  - show IDB device info
>
> Host (PC) tool commands combinations that work:
>
> U-boot                                  linux
> rockusb 0 idb 0
>                                         upgrade_tool pl
>                                         upgrade_tool wl 64 upgrade_tool_wl_64.bin
>                                         upgrade_tool rl 64 512 upgrade_tool_rl_64_512.bin
>                                         upgrade_tool rd
>
>                                         rkdeveloptool ppt
>                                         rkdeveloptool wlx loader1 rkdeveloptool_wlx_loader1.bin
>                                         rkdeveloptool wl 64 rkdeveloptool_wl_64.bin
>                                         rkdeveloptool rl 64 512 rkdeveloptool_rl_64_512.bin
>                                         rkdeveloptool rd
>
>                                         rkflashtool w 64 512 < rkflashtool_w_64_512.bin
>                                         rkflashtool r 64 512 > rkflashtool_r_64_512.bin
>
> ums 0 idb 0
>                                         dd if=ums_0_idb_0_wr.bin of=/dev/sda1
>                                         dd if=/dev/sda1 of=ums_0_idb_0_rd.bin
>
> Tested with:
>   MK808 rk3066
>
> Not tested:
>   nfc type V8, V9
>
> TODO:
>   Looking for advice on what needs to be done to make it fit for mainline. Thanks!
>
>   This is placed in the mach-rockchip directory,
>   so we can re-use/combine the source with a usbplug or RK NAND FTL driver
>   with no MTD frame work bloatware ;) in a Makefile.
>
>   IDB header V2
>
>   Writing strategy improvement
>
>   etc, etc
>
> Johan Jonker (6):
>   rockchip: block: add Rockchip IDB block device
>   rockchip: spl: allow more boot devices
>   rockchip: rk3066: add Rockchip IDB block device as boot action
>   arm: dts: rockchip: sync rk3066/rk3188 DT files from Linux
>   arm: dts: rockchip: enable nfc node in spl for rk3066 mk808
>   rockchip: configs: mk808: add idb configs
>
>  arch/arm/dts/rk3066a-mk808-u-boot.dtsi |    8 +
>  arch/arm/dts/rk3066a-mk808.dts         |   18 +
>  arch/arm/dts/rk3066a.dtsi              |    3 +-
>  arch/arm/dts/rk3188-radxarock.dts      |    3 +-
>  arch/arm/dts/rk3188.dtsi               |   24 +-
>  arch/arm/dts/rk3xxx-u-boot.dtsi        |    4 +
>  arch/arm/mach-rockchip/Kconfig         |   12 +
>  arch/arm/mach-rockchip/Makefile        |    1 +
>  arch/arm/mach-rockchip/rk3066/rk3066.c |   11 +
>  arch/arm/mach-rockchip/rockchip_idb.c  | 1694 ++++++++++++++++++++++++
>  arch/arm/mach-rockchip/spl.c           |    5 +-
>  configs/mk808_defconfig                |    4 +
>  drivers/block/blk-uclass.c             |    2 +
>  include/blk.h                          |    1 +
>  include/dm/uclass-id.h                 |    1 +
>  include/efi_loader.h                   |    4 +
>  lib/efi_loader/efi_device_path.c       |   30 +
>  17 files changed, 1812 insertions(+), 13 deletions(-)
>  create mode 100644 arch/arm/mach-rockchip/rockchip_idb.c
>
> --
> 2.20.1
>


--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
michael@amarulasolutions.com