[PATCH] arm: k3: Consolidate and silence k3_fit_atf.sh call
From: Jan Kiszka Signed-off-by: Jan Kiszka --- arch/arm/mach-k3/config.mk | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/arm/mach-k3/config.mk b/arch/arm/mach-k3/config.mk index f6b63db349..f7afef610c 100644 --- a/arch/arm/mach-k3/config.mk +++ b/arch/arm/mach-k3/config.mk @@ -48,22 +48,23 @@ ALL-y += tiboot3.bin endif ifdef CONFIG_ARM64 + ifeq ($(CONFIG_TI_SECURE_DEVICE),y) SPL_ITS := u-boot-spl-k3_HS.its -$(SPL_ITS): FORCE - IS_HS=1 \ - $(srctree)/tools/k3_fit_atf.sh \ - $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST))) > $@ - +$(SPL_ITS): export IS_HS=1 ALL-y += tispl.bin_HS else SPL_ITS := u-boot-spl-k3.its -$(SPL_ITS): FORCE +ALL-y += tispl.bin +endif + +quiet_cmd_k3_mkits = MKITS $@ +cmd_k3_mkits = \ $(srctree)/tools/k3_fit_atf.sh \ $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST))) > $@ -ALL-y += tispl.bin -endif +$(SPL_ITS): FORCE + $(call cmd,k3_mkits) endif else -- 2.26.2
[PATCH] Makefile: Silence relocate-rela call
From: Jan Kiszka Signed-off-by: Jan Kiszka --- Makefile | 14 -- 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index e3c18d8c39..6d2f5bc091 100644 --- a/Makefile +++ b/Makefile @@ -872,12 +872,14 @@ endif # do the relocation). ifneq ($(CONFIG_STATIC_RELA),) # $(1) is u-boot ELF, $(2) is u-boot bin, $(3) is text base -DO_STATIC_RELA = \ - start=$$($(NM) $(1) | grep __rel_dyn_start | cut -f 1 -d ' '); \ - end=$$($(NM) $(1) | grep __rel_dyn_end | cut -f 1 -d ' '); \ - tools/relocate-rela $(2) $(3) $$start $$end +quiet_cmd_static_rela = RELOC $@ +cmd_static_rela = \ + start=$$($(NM) $(2) | grep __rel_dyn_start | cut -f 1 -d ' '); \ + end=$$($(NM) $(2) | grep __rel_dyn_end | cut -f 1 -d ' '); \ + tools/relocate-rela $(3) $(4) $$start $$end else -DO_STATIC_RELA = +quiet_cmd_static_rela = +cmd_static_rela = endif # Always append ALL so that arch config.mk's can add custom ones @@ -1284,7 +1286,7 @@ endif u-boot-nodtb.bin: u-boot FORCE $(call if_changed,objcopy) - $(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE)) + $(call cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) $(BOARD_SIZE_CHECK) u-boot.ldr:u-boot -- 2.26.2
RE: [PATCH v4 1/4] fu540: prci: add request and free clock handlers
Hi Bin, > -Original Message- > From: Sagar Kadam > Sent: Thursday, June 25, 2020 10:17 AM > To: Bin Meng > Cc: U-Boot Mailing List ; Rick Chen > ; Lukasz Majewski ; Jagan Teki > ; Pragnesh Patel > ; Anup Patel ; Simon > Glass ; Sean Anderson > Subject: RE: [PATCH v4 1/4] fu540: prci: add request and free clock handlers > > Hi Bin, > > > -Original Message- > > From: Bin Meng > > Sent: Thursday, June 25, 2020 4:51 AM > > To: Sagar Kadam > > Cc: U-Boot Mailing List ; Rick Chen > > ; Lukasz Majewski ; Jagan Teki > > ; Pragnesh Patel > > ; Anup Patel ; Simon > > Glass ; Sean Anderson > > Subject: Re: [PATCH v4 1/4] fu540: prci: add request and free clock > > handlers > > > > [External Email] Do not click links or attachments unless you > > recognize the sender and know the content is safe > > > > Hi Sagar, > > > > On Wed, Jun 24, 2020 at 6:58 PM Sagar Kadam > > wrote: > > > > > > Hi Bin, > > > > > > > -Original Message- > > > > From: Bin Meng > > > > Sent: Wednesday, June 24, 2020 6:50 AM > > > > To: Sagar Kadam > > > > Cc: U-Boot Mailing List ; Rick Chen > > > > ; Lukasz Majewski ; Jagan > Teki > > > > ; Pragnesh Patel > > > > ; Anup Patel ; > > Simon > > > > Glass ; Sean Anderson > > > > Subject: Re: [PATCH v4 1/4] fu540: prci: add request and free > > > > clock > > handlers > > > > > > > > [External Email] Do not click links or attachments unless you > > > > recognize > > the > > > > sender and know the content is safe > > > > > > > > Hi Sagar, > > > > > > > > On Sun, Jun 21, 2020 at 9:10 PM Sagar Shrikant Kadam > > > > wrote: > > > > > > > > > > Add clk_request handler to check if a valid clock is requested. > > > > > Here clk_free handler is added for debug purpose which will > > > > > display details of clock passed to clk_free. > > > > > > > > > > Signed-off-by: Sagar Shrikant Kadam > > > > > Reviewed-by: Pragnesh Patel > > > > > --- > > > > > drivers/clk/sifive/fu540-prci.c | 21 + > > > > > 1 file changed, 21 insertions(+) > > > > > > > > > > diff --git a/drivers/clk/sifive/fu540-prci.c > > > > > b/drivers/clk/sifive/fu540-prci.c index fe6e0d4..9a9ff6b 100644 > > > > > --- a/drivers/clk/sifive/fu540-prci.c > > > > > +++ b/drivers/clk/sifive/fu540-prci.c > > > > > @@ -686,6 +686,25 @@ static ulong > > > > > sifive_fu540_prci_set_rate(struct > > clk > > > > *clk, ulong rate) > > > > > return rate; > > > > > } > > > > > > > > > > +static int sifive_fu540_prci_clk_request(struct clk *clk) { > > > > > + debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk- > >dev, > > > > > + clk->id); > > > > > + > > > > > + if (clk->id >= ARRAY_SIZE(__prci_init_clocks)) > > > > > + return -EINVAL; > > > > > + > > > > > + return 0; > > > > > +} > > > > > + > > > > > +static int sifive_fu540_prci_clk_free(struct clk *clk) { > > > > > + debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk- > >dev, > > > > > + clk->id); > > > > > + > > > > > + return 0; > > > > > +} > > > > > > > > It seems these 2 routines do not actually do anything? Is this for > > debugging > > > > purposes? > > > > > > > The sifive_fu540_prci_clk_request will check if the clock requested > > > is valid > > or not. > > > While the sifive_fu540_prci_clk_free function is just for debug. > > > Is it ok if I retain these in V5 or you have some other thought here. > > > > > > > OK, but I suspect the parameter check in > > sifive_fu540_prci_clk_request() is not necessary too as currently the > > codes work well. > > > > Ok. In that case I will than drop the check in sifive_fu540_prci_clk_request() > and just keep the debug info. > > Thanks & BR, > Sagar > Missed to add: I had referred to other reference driver's and thought of keeping it. So I'll drop this patch in V5 as it is not much value addition here. Sorry for the confusion Thanks & BR, Sagar > > Regards, > > Bin
RE: [PATCH v4 1/4] fu540: prci: add request and free clock handlers
Hi Bin, > -Original Message- > From: Bin Meng > Sent: Thursday, June 25, 2020 4:51 AM > To: Sagar Kadam > Cc: U-Boot Mailing List ; Rick Chen > ; Lukasz Majewski ; Jagan Teki > ; Pragnesh Patel > ; Anup Patel ; Simon > Glass ; Sean Anderson > Subject: Re: [PATCH v4 1/4] fu540: prci: add request and free clock handlers > > [External Email] Do not click links or attachments unless you recognize the > sender and know the content is safe > > Hi Sagar, > > On Wed, Jun 24, 2020 at 6:58 PM Sagar Kadam > wrote: > > > > Hi Bin, > > > > > -Original Message- > > > From: Bin Meng > > > Sent: Wednesday, June 24, 2020 6:50 AM > > > To: Sagar Kadam > > > Cc: U-Boot Mailing List ; Rick Chen > > > ; Lukasz Majewski ; Jagan Teki > > > ; Pragnesh Patel > > > ; Anup Patel ; > Simon > > > Glass ; Sean Anderson > > > Subject: Re: [PATCH v4 1/4] fu540: prci: add request and free clock > handlers > > > > > > [External Email] Do not click links or attachments unless you recognize > the > > > sender and know the content is safe > > > > > > Hi Sagar, > > > > > > On Sun, Jun 21, 2020 at 9:10 PM Sagar Shrikant Kadam > > > wrote: > > > > > > > > Add clk_request handler to check if a valid clock is requested. > > > > Here clk_free handler is added for debug purpose which will display > > > > details of clock passed to clk_free. > > > > > > > > Signed-off-by: Sagar Shrikant Kadam > > > > Reviewed-by: Pragnesh Patel > > > > --- > > > > drivers/clk/sifive/fu540-prci.c | 21 + > > > > 1 file changed, 21 insertions(+) > > > > > > > > diff --git a/drivers/clk/sifive/fu540-prci.c > > > > b/drivers/clk/sifive/fu540-prci.c index fe6e0d4..9a9ff6b 100644 > > > > --- a/drivers/clk/sifive/fu540-prci.c > > > > +++ b/drivers/clk/sifive/fu540-prci.c > > > > @@ -686,6 +686,25 @@ static ulong sifive_fu540_prci_set_rate(struct > clk > > > *clk, ulong rate) > > > > return rate; > > > > } > > > > > > > > +static int sifive_fu540_prci_clk_request(struct clk *clk) { > > > > + debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, > > > > + clk->id); > > > > + > > > > + if (clk->id >= ARRAY_SIZE(__prci_init_clocks)) > > > > + return -EINVAL; > > > > + > > > > + return 0; > > > > +} > > > > + > > > > +static int sifive_fu540_prci_clk_free(struct clk *clk) { > > > > + debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, > > > > + clk->id); > > > > + > > > > + return 0; > > > > +} > > > > > > It seems these 2 routines do not actually do anything? Is this for > debugging > > > purposes? > > > > > The sifive_fu540_prci_clk_request will check if the clock requested is valid > or not. > > While the sifive_fu540_prci_clk_free function is just for debug. > > Is it ok if I retain these in V5 or you have some other thought here. > > > > OK, but I suspect the parameter check in > sifive_fu540_prci_clk_request() is not necessary too as currently the > codes work well. > Ok. In that case I will than drop the check in sifive_fu540_prci_clk_request() and just keep the debug info. Thanks & BR, Sagar > Regards, > Bin
[PATCH v4 13/14] dtoc: update dtb_platdata to support cd-gpios
Currently dtoc does not support the property cd-gpios used to declare the gpios for card detect in mmc. This patch adds support to cd-gpios property. Signed-off-by: Walter Lozano --- tools/dtoc/dtb_platdata.py | 16 ++-- tools/dtoc/test_dtoc.py| 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index f6579fd655..25ed7f50eb 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -258,7 +258,7 @@ class DtbPlatdata(object): Return: Number of argument cells is this is a phandle, else None """ -if prop.name in ['clocks']: +if prop.name in ['clocks', 'cd-gpios']: if not isinstance(prop.value, list): prop.value = [prop.value] val = prop.value @@ -278,11 +278,14 @@ class DtbPlatdata(object): if not target: raise ValueError("Cannot parse '%s' in node '%s'" % (prop.name, node_name)) -prop_name = '#clock-cells' -cells = target.props.get(prop_name) +cells = None +for prop_name in ['#clock-cells', '#gpio-cells']: +cells = target.props.get(prop_name) +if cells: +break if not cells: -raise ValueError("Node '%s' has no '%s' property" % -(target.name, prop_name)) +raise ValueError("Node '%s' has no cells property" % +(target.name)) num_args = fdt_util.fdt32_to_cpu(cells.value) max_args = max(max_args, num_args) args.append(num_args) @@ -652,7 +655,8 @@ class DtbPlatdata(object): # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx) self.buf('void dm_populate_phandle_data(void) {\n') for l in self._links: -self.buf('\t%s = DM_GET_DEVICE(%s);\n' % (l['var_node'], l['dev_name'])) +self.buf('\t%s = DM_GET_DEVICE(%s);\n' % + (l['var_node'], l['dev_name'])) self.buf('}\n') self.out(''.join(self.get_buf())) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 209542c849..67ca9a8da1 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -485,7 +485,7 @@ void dm_populate_phandle_data(void) { output = tools.GetOutputFilename('output') with self.assertRaises(ValueError) as e: self.run_test(['struct'], dtb_file, output) -self.assertIn("Node 'phandle-target' has no '#clock-cells' property", +self.assertIn("Node 'phandle-target' has no cells property", str(e.exception)) def test_aliases(self): -- 2.20.1
[PATCH v4 10/14] dtoc: extend dtoc to use struct driver_info when linking nodes
In the current implementation, when dtoc parses a dtb to generate a struct platdata it converts the information related to linked nodes as pointers to struct platdata of destination nodes. By doing this, it makes difficult to get pointer to udevices created based on these information. This patch extends dtoc to use struct driver_info when populating information about linked nodes, which makes it easier to later get the devices created. In this context, reimplement functions like clk_get_by_index_platdata() which made use of the previous approach. Signed-off-by: Walter Lozano --- drivers/clk/clk-uclass.c| 11 ++- drivers/misc/irq-uclass.c | 10 ++- drivers/mmc/ftsdc010_mci.c | 2 +- drivers/mmc/rockchip_dw_mmc.c | 2 +- drivers/mmc/rockchip_sdhci.c| 2 +- drivers/ram/rockchip/sdram_rk3399.c | 2 +- drivers/spi/rk_spi.c| 2 +- include/clk.h | 4 +- tools/dtoc/dtb_platdata.py | 26 ++- tools/dtoc/test_dtoc.py | 104 10 files changed, 100 insertions(+), 65 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 71878474eb..412f26cd29 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -25,17 +25,16 @@ static inline const struct clk_ops *clk_dev_ops(struct udevice *dev) #if CONFIG_IS_ENABLED(OF_CONTROL) # if CONFIG_IS_ENABLED(OF_PLATDATA) -int clk_get_by_index_platdata(struct udevice *dev, int index, - struct phandle_1_arg *cells, struct clk *clk) +int clk_get_by_driver_info(struct udevice *dev, struct phandle_1_arg *cells, + struct clk *clk) { int ret; - if (index != 0) - return -ENOSYS; - ret = uclass_get_device(UCLASS_CLK, 0, &clk->dev); + ret = device_get_by_driver_info((struct driver_info *)cells->node, + &clk->dev); if (ret) return ret; - clk->id = cells[0].arg[0]; + clk->id = cells->arg[0]; return 0; } diff --git a/drivers/misc/irq-uclass.c b/drivers/misc/irq-uclass.c index 61aa10e465..3c38681108 100644 --- a/drivers/misc/irq-uclass.c +++ b/drivers/misc/irq-uclass.c @@ -63,17 +63,15 @@ int irq_read_and_clear(struct irq *irq) } #if CONFIG_IS_ENABLED(OF_PLATDATA) -int irq_get_by_index_platdata(struct udevice *dev, int index, - struct phandle_1_arg *cells, struct irq *irq) +int irq_get_by_driver_info(struct udevice *dev, + struct phandle_1_arg *cells, struct irq *irq) { int ret; - if (index != 0) - return -ENOSYS; - ret = uclass_get_device(UCLASS_IRQ, 0, &irq->dev); + ret = device_get_by_driver_info(cells->node, &irq->dev); if (ret) return ret; - irq->id = cells[0].arg[0]; + irq->id = cells->arg[0]; return 0; } diff --git a/drivers/mmc/ftsdc010_mci.c b/drivers/mmc/ftsdc010_mci.c index 9c15eb36d6..efa92d48be 100644 --- a/drivers/mmc/ftsdc010_mci.c +++ b/drivers/mmc/ftsdc010_mci.c @@ -437,7 +437,7 @@ static int ftsdc010_mmc_probe(struct udevice *dev) chip->priv = dev; chip->dev_index = 1; memcpy(priv->minmax, dtplat->clock_freq_min_max, sizeof(priv->minmax)); - ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->clk); + ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->clk); if (ret < 0) return ret; #endif diff --git a/drivers/mmc/rockchip_dw_mmc.c b/drivers/mmc/rockchip_dw_mmc.c index ac710324c8..80432ddbbc 100644 --- a/drivers/mmc/rockchip_dw_mmc.c +++ b/drivers/mmc/rockchip_dw_mmc.c @@ -120,7 +120,7 @@ static int rockchip_dwmmc_probe(struct udevice *dev) priv->minmax[0] = 40; /* 400 kHz */ priv->minmax[1] = dtplat->max_frequency; - ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->clk); + ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->clk); if (ret < 0) return ret; #else diff --git a/drivers/mmc/rockchip_sdhci.c b/drivers/mmc/rockchip_sdhci.c index b440996b26..b073f1a08d 100644 --- a/drivers/mmc/rockchip_sdhci.c +++ b/drivers/mmc/rockchip_sdhci.c @@ -46,7 +46,7 @@ static int arasan_sdhci_probe(struct udevice *dev) host->name = dev->name; host->ioaddr = map_sysmem(dtplat->reg[0], dtplat->reg[1]); max_frequency = dtplat->max_frequency; - ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &clk); + ret = clk_get_by_driver_info(dev, dtplat->clocks, &clk); #else max_frequency = dev_read_u32_default(dev, "max-frequency", 0); ret = clk_get_by_index(dev, 0, &clk); diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c index d69ef01d08..87ec25f893 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @
[PATCH v4 12/14] arm: dts: include gpio nodes for card detect
Several MMC drivers use GPIO for card detection with cd-gpios property in the MMC node pointing to a GPIO node. However, as U-Boot tries to save space by keeping only required nodes using u-boot* properties, several devices tree result in having only in the MMC node but not the GPIO node associated to cd-gpios. This patch, fixes several ocurrence of this issue. Signed-off-by: Walter Lozano --- arch/arm/dts/da850-evm-u-boot.dtsi| 4 arch/arm/dts/da850-lcdk-u-boot.dtsi | 4 arch/arm/dts/rk3288-u-boot.dtsi | 4 arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi | 2 +- arch/arm/dts/rk3288-veyron-u-boot.dtsi| 11 +++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 arch/arm/dts/rk3288-veyron-u-boot.dtsi diff --git a/arch/arm/dts/da850-evm-u-boot.dtsi b/arch/arm/dts/da850-evm-u-boot.dtsi index d9afc5edf4..d588628641 100644 --- a/arch/arm/dts/da850-evm-u-boot.dtsi +++ b/arch/arm/dts/da850-evm-u-boot.dtsi @@ -39,3 +39,7 @@ &spi1 { u-boot,dm-spl; }; + +&gpio { + u-boot,dm-spl; +}; diff --git a/arch/arm/dts/da850-lcdk-u-boot.dtsi b/arch/arm/dts/da850-lcdk-u-boot.dtsi index b372d06ca9..d50775c173 100644 --- a/arch/arm/dts/da850-lcdk-u-boot.dtsi +++ b/arch/arm/dts/da850-lcdk-u-boot.dtsi @@ -28,3 +28,7 @@ &serial2 { u-boot,dm-spl; }; + +&gpio { + u-boot,dm-spl; +}; diff --git a/arch/arm/dts/rk3288-u-boot.dtsi b/arch/arm/dts/rk3288-u-boot.dtsi index 6d31735362..51b6e018bd 100644 --- a/arch/arm/dts/rk3288-u-boot.dtsi +++ b/arch/arm/dts/rk3288-u-boot.dtsi @@ -43,3 +43,7 @@ &noc { u-boot,dm-pre-reloc; }; + +&gpio7 { + u-boot,dm-pre-reloc; +}; diff --git a/arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi b/arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi index eccc069368..251fbdee71 100644 --- a/arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi +++ b/arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi @@ -3,7 +3,7 @@ * Copyright 2015 Google, Inc */ -#include "rk3288-u-boot.dtsi" +#include "rk3288-veyron-u-boot.dtsi" &dmc { rockchip,pctl-timing = <0x215 0xc8 0x0 0x35 0x26 0x2 0x70 0x2000d diff --git a/arch/arm/dts/rk3288-veyron-u-boot.dtsi b/arch/arm/dts/rk3288-veyron-u-boot.dtsi new file mode 100644 index 00..899fe6e7a0 --- /dev/null +++ b/arch/arm/dts/rk3288-veyron-u-boot.dtsi @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright 2015 Google, Inc + */ + +#include "rk3288-u-boot.dtsi" + +&gpio7 { + u-boot,dm-pre-reloc; +}; + -- 2.20.1
[PATCH v4 11/14] dm: doc: update of-plat with new phandle support
Update documentation to reflect the new phandle support when OF_PLATDATA is used. Now phandles are implemented as pointers to U_BOOT_DEVICE, which makes it possible to get a pointer to the actual device. Signed-off-by: Walter Lozano --- doc/driver-model/of-plat.rst | 24 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst index 376d4409a5..1e3fad137b 100644 --- a/doc/driver-model/of-plat.rst +++ b/doc/driver-model/of-plat.rst @@ -69,9 +69,8 @@ strictly necessary. Notable problems include: - Correct relations between nodes are not implemented. This means that parent/child relations (like bus device iteration) do not work yet. Some phandles (those that are recognised as such) are converted into - a pointer to platform data. This pointer can potentially be used to - access the referenced device (by searching for the pointer value). - This feature is not yet implemented, however. + a pointer to struct driver_info. This pointer can be used to access + the referenced device. How it works @@ -146,10 +145,10 @@ and the following device declaration: .clock_freq_min_max = {0x61a80, 0x8f0d180}, .vmmc_supply= 0xb, .num_slots = 0x1, -.clocks = {{&dtv_clock_controller_at_ff76, 456}, - {&dtv_clock_controller_at_ff76, 68}, - {&dtv_clock_controller_at_ff76, 114}, - {&dtv_clock_controller_at_ff76, 118}}, +.clocks = {{NULL, 456}, + {NULL, 68}, + {NULL, 114}, + {NULL, 118}}, .cap_mmc_highspeed = true, .disable_wp = true, .bus_width = 0x4, @@ -164,6 +163,13 @@ and the following device declaration: .platdata_size = sizeof(dtv_dwmmc_at_ff0c), }; +void dm_populate_phandle_data(void) { +dtv_dwmmc_at_ff0c.clocks[0].node = DM_GET_DEVICE(clock_controller_at_ff76); +dtv_dwmmc_at_ff0c.clocks[1].node = DM_GET_DEVICE(clock_controller_at_ff76); +dtv_dwmmc_at_ff0c.clocks[2].node = DM_GET_DEVICE(clock_controller_at_ff76); +dtv_dwmmc_at_ff0c.clocks[3].node = DM_GET_DEVICE(clock_controller_at_ff76); +} + The device is then instantiated at run-time and the platform data can be accessed using: @@ -329,7 +335,9 @@ prevents them being used inadvertently. All usage must be bracketed with #if CONFIG_IS_ENABLED(OF_PLATDATA). The dt-platdata.c file contains the device declarations and is is built in -spl/dt-platdata.c. +spl/dt-platdata.c. It additionally contains the definition of +dm_populate_phandle_data() which is responsible of filling the phandle +information by adding references to U_BOOT_DEVICE by using DM_GET_DEVICE The beginnings of a libfdt Python module are provided. So far this only implements a subset of the features. -- 2.20.1
[PATCH v4 09/14] sandbox: Move section u_boot_list to make it RW
In order to be able to update data in u_boot_list, move this section to make it RW. Signed-off-by: Walter Lozano --- arch/sandbox/cpu/u-boot-spl.lds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/u-boot-spl.lds b/arch/sandbox/cpu/u-boot-spl.lds index de65b01b33..c60eb109b1 100644 --- a/arch/sandbox/cpu/u-boot-spl.lds +++ b/arch/sandbox/cpu/u-boot-spl.lds @@ -20,4 +20,4 @@ SECTIONS __bss_start = .; } -INSERT BEFORE .data; +INSERT AFTER .data; -- 2.20.1
[PATCH v4 14/14] dtoc: add test for cd-gpios
Add a test for dtoc taking into account the cd-gpios property. Signed-off-by: Walter Lozano --- tools/dtoc/dtoc_test_phandle_cd_gpios.dts | 42 ++ tools/dtoc/test_dtoc.py | 67 +++ 2 files changed, 109 insertions(+) create mode 100644 tools/dtoc/dtoc_test_phandle_cd_gpios.dts diff --git a/tools/dtoc/dtoc_test_phandle_cd_gpios.dts b/tools/dtoc/dtoc_test_phandle_cd_gpios.dts new file mode 100644 index 00..241743e73e --- /dev/null +++ b/tools/dtoc/dtoc_test_phandle_cd_gpios.dts @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2020 Collabora Ltd. + */ + +/dts-v1/; + +/ { + phandle: phandle-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <0>; + #gpio-cells = <0>; + }; + + phandle_1: phandle2-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <1>; + #gpio-cells = <1>; + }; + phandle_2: phandle3-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <2>; + #gpio-cells = <2>; + }; + + phandle-source { + u-boot,dm-pre-reloc; + compatible = "source"; + cd-gpios = <&phandle &phandle_1 11 &phandle_2 12 13 &phandle>; + }; + + phandle-source2 { + u-boot,dm-pre-reloc; + compatible = "source"; + cd-gpios = <&phandle>; + }; +}; diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 67ca9a8da1..3c8e343b1f 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -466,6 +466,73 @@ U_BOOT_DEVICE(phandle_source2) = { void dm_populate_phandle_data(void) { \tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target); } +''', data) + +def test_phandle_cd_gpio(self): +"""Test that phandle targets are generated when unsing cd-gpios""" +dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts') +output = tools.GetOutputFilename('output') +dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True) +with open(output) as infile: +data = infile.read() +self._CheckStrings(C_HEADER + ''' +static struct dtd_target dtv_phandle_target = { +\t.intval\t\t\t= 0x0, +}; +U_BOOT_DEVICE(phandle_target) = { +\t.name\t\t= "target", +\t.platdata\t= &dtv_phandle_target, +\t.platdata_size\t= sizeof(dtv_phandle_target), +}; + +static struct dtd_target dtv_phandle2_target = { +\t.intval\t\t\t= 0x1, +}; +U_BOOT_DEVICE(phandle2_target) = { +\t.name\t\t= "target", +\t.platdata\t= &dtv_phandle2_target, +\t.platdata_size\t= sizeof(dtv_phandle2_target), +}; + +static struct dtd_target dtv_phandle3_target = { +\t.intval\t\t\t= 0x2, +}; +U_BOOT_DEVICE(phandle3_target) = { +\t.name\t\t= "target", +\t.platdata\t= &dtv_phandle3_target, +\t.platdata_size\t= sizeof(dtv_phandle3_target), +}; + +static struct dtd_source dtv_phandle_source = { +\t.cd_gpios\t\t= { +\t\t\t{NULL, {}}, +\t\t\t{NULL, {11}}, +\t\t\t{NULL, {12, 13}}, +\t\t\t{NULL, {}},}, +}; +U_BOOT_DEVICE(phandle_source) = { +\t.name\t\t= "source", +\t.platdata\t= &dtv_phandle_source, +\t.platdata_size\t= sizeof(dtv_phandle_source), +}; + +static struct dtd_source dtv_phandle_source2 = { +\t.cd_gpios\t\t= { +\t\t\t{NULL, {}},}, +}; +U_BOOT_DEVICE(phandle_source2) = { +\t.name\t\t= "source", +\t.platdata\t= &dtv_phandle_source2, +\t.platdata_size\t= sizeof(dtv_phandle_source2), +}; + +void dm_populate_phandle_data(void) { +\tdtv_phandle_source.cd_gpios[0].node = DM_GET_DEVICE(phandle_target); +\tdtv_phandle_source.cd_gpios[1].node = DM_GET_DEVICE(phandle2_target); +\tdtv_phandle_source.cd_gpios[2].node = DM_GET_DEVICE(phandle3_target); +\tdtv_phandle_source.cd_gpios[3].node = DM_GET_DEVICE(phandle_target); +\tdtv_phandle_source2.cd_gpios[0].node = DM_GET_DEVICE(phandle_target); +} ''', data) def test_phandle_bad(self): -- 2.20.1
[PATCH v4 08/14] core: extend struct driver_info to point to device
Currently when creating an U_BOOT_DEVICE entry a struct driver_info is declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its struct driver_info. This patch extends struct driver_info adding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its struct driver_info. Signed-off-by: Walter Lozano --- drivers/core/device.c | 26 +++--- drivers/core/root.c | 4 include/dm/device.h | 15 +++ include/dm/platdata.h | 14 ++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index a0ad080aaf..4f8c97a195 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, { struct driver *drv; uint platdata_size = 0; + int ret; drv = lists_driver_lookup_name(info->name); if (!drv) @@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, #if CONFIG_IS_ENABLED(OF_PLATDATA) platdata_size = info->platdata_size; #endif - return device_bind_common(parent, drv, info->name, - (void *)info->platdata, 0, ofnode_null(), platdata_size, - devp); + ret = device_bind_common(parent, drv, info->name, +(void *)info->platdata, 0, ofnode_null(), +platdata_size, devp); + if (ret) + return ret; +#if CONFIG_IS_ENABLED(OF_PLATDATA) + info->dev = *devp; +#endif + + return ret; } static void *alloc_priv(int size, uint flags) @@ -727,6 +735,18 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp) return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); } +#if CONFIG_IS_ENABLED(OF_PLATDATA) +int device_get_by_driver_info(const struct driver_info *info, + struct udevice **devp) +{ + struct udevice *dev; + + dev = info->dev; + + return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); +} +#endif + int device_find_first_child(const struct udevice *parent, struct udevice **devp) { if (list_empty(&parent->child_head)) { diff --git a/drivers/core/root.c b/drivers/core/root.c index c9ee56478a..2643ef68a7 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -346,6 +346,10 @@ int dm_init_and_scan(bool pre_reloc_only) { int ret; +#if CONFIG_IS_ENABLED(OF_PLATDATA) + dm_populate_phandle_data(); +#endif + ret = dm_init(IS_ENABLED(CONFIG_OF_LIVE)); if (ret) { debug("dm_init() failed: %d\n", ret); diff --git a/include/dm/device.h b/include/dm/device.h index 2cfe10766f..f5738a0cee 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -538,6 +538,21 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp); */ int device_get_global_by_ofnode(ofnode node, struct udevice **devp); +/** + * device_get_by_driver_info() - Get a device based on driver_info + * + * Locates a device by its struct driver_info, by using its reference which + * is updated during the bind process. + * + * The device is probed to activate it ready for use. + * + * @info: Struct driver_info + * @devp: Returns pointer to device if found, otherwise this is set to NULL + * @return 0 if OK, -ve on error + */ +int device_get_by_driver_info(const struct driver_info *info, + struct udevice **devp); + /** * device_find_first_child() - Find the first child of a device * diff --git a/include/dm/platdata.h b/include/dm/platdata.h index c972fa6936..cab93b071b 100644 --- a/include/dm/platdata.h +++ b/include/dm/platdata.h @@ -22,12 +22,14 @@ * @name: Driver name * @platdata: Driver-specific platform data * @platdata_size: Size of platform data structure + * @dev: Device created from this structure data */ struct driver_info { const char *name; const void *platdata; #if CONFIG_IS_ENABLED(OF_PLATDATA) uint platdata_size; + struct udevice *dev; #endif }; @@ -43,4 +45,16 @@ struct driver_info { #define U_BOOT_DEVICES(__name) \ ll_entry_declare_list(struct driver_info, __name, driver_info) +/* Get a pointer to a given driver */ +#define DM_GET_DEVICE(__name) \ + ll_entry_get(struct driver_info, __name, driver_info) + +/** + * dm_populate_phandle_data() - Populates phandle data in platda + * + * This populates phandle data with an U_BOOT_DEVICE entry get by + * DM_GET_DEVICE. The implementation of this function will be done + * by dtoc when parsing dtb. + */ +void dm_populate_phandle_data(void); #endif -- 2.20.1
[PATCH v4 03/14] core: add support for U_BOOT_DRIVER_ALIAS
Currently when using OF_PLATDATA the binding between devices and drivers is done trying to match the compatible string in the node with a driver name. However, usually a single driver supports multiple compatible strings which causes that only devices which its compatible string matches a driver name get bound. To overcome this issue, this patch adds the U_BOOT_DRIVER_ALIAS macro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc could be improve to look for the driver name based on its alias when it populates the U_BOOT_DEVICE entry. Signed-off-by: Walter Lozano --- drivers/clk/at91/pmc.c| 2 ++ drivers/gpio/mxs_gpio.c | 2 ++ drivers/gpio/sandbox.c| 2 ++ drivers/i2c/rk_i2c.c | 2 ++ drivers/mmc/mxsmmc.c | 1 + drivers/mmc/rockchip_dw_mmc.c | 3 +++ drivers/mtd/spi/sf_probe.c| 2 ++ drivers/pinctrl/nxp/pinctrl-mxs.c | 2 ++ drivers/pinctrl/pinctrl-at91.c| 2 ++ drivers/power/pmic/rk8xx.c| 2 ++ drivers/serial/ns16550.c | 4 drivers/spi/mxs_spi.c | 2 ++ drivers/spi/rk_spi.c | 2 ++ include/dm/device.h | 7 +++ 14 files changed, 35 insertions(+) diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c index 1fede16a0c..793a506d27 100644 --- a/drivers/clk/at91/pmc.c +++ b/drivers/clk/at91/pmc.c @@ -30,6 +30,8 @@ U_BOOT_DRIVER(atmel_at91rm9200_pmc) = { .of_match = at91_pmc_match, }; +U_BOOT_DRIVER_ALIAS(atmel_at91rm9200_pmc, atmel_at91sam9260_pmc) + /*-*/ int at91_pmc_core_probe(struct udevice *dev) diff --git a/drivers/gpio/mxs_gpio.c b/drivers/gpio/mxs_gpio.c index e43484d13a..bcdf08c255 100644 --- a/drivers/gpio/mxs_gpio.c +++ b/drivers/gpio/mxs_gpio.c @@ -309,4 +309,6 @@ U_BOOT_DRIVER(fsl_imx23_gpio) = { .ofdata_to_platdata = mxs_ofdata_to_platdata, #endif }; + +U_BOOT_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio) #endif /* DM_GPIO */ diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index ff46d3c8d1..8923e54867 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -253,6 +253,8 @@ U_BOOT_DRIVER(sandbox_gpio) = { .ops= &gpio_sandbox_ops, }; +U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias) + /* pincontrol: used only to check GPIO pin configuration (pinmux command) */ struct sb_pinctrl_priv { diff --git a/drivers/i2c/rk_i2c.c b/drivers/i2c/rk_i2c.c index eceef80e70..e76c087b1d 100644 --- a/drivers/i2c/rk_i2c.c +++ b/drivers/i2c/rk_i2c.c @@ -492,3 +492,5 @@ U_BOOT_DRIVER(rockchip_rk3066_i2c) = { .priv_auto_alloc_size = sizeof(struct rk_i2c), .ops= &rockchip_i2c_ops, }; + +U_BOOT_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c) diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 35c336b499..afa95e57ee 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -724,4 +724,5 @@ U_BOOT_DRIVER(fsl_imx23_mmc) = { .platdata_auto_alloc_size = sizeof(struct mxsmmc_platdata), }; +U_BOOT_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc) #endif /* CONFIG_DM_MMC */ diff --git a/drivers/mmc/rockchip_dw_mmc.c b/drivers/mmc/rockchip_dw_mmc.c index ef75367b3e..ac710324c8 100644 --- a/drivers/mmc/rockchip_dw_mmc.c +++ b/drivers/mmc/rockchip_dw_mmc.c @@ -178,6 +178,9 @@ U_BOOT_DRIVER(rockchip_rk3288_dw_mshc) = { .platdata_auto_alloc_size = sizeof(struct rockchip_mmc_plat), }; +U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc) +U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc) + #ifdef CONFIG_PWRSEQ static int rockchip_dwmmc_pwrseq_set_power(struct udevice *dev, bool enable) { diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 1b44cc68c6..97fa22a4b3 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -180,4 +180,6 @@ U_BOOT_DRIVER(jedec_spi_nor) = { .ops= &spi_flash_std_ops, }; +U_BOOT_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16) + #endif /* CONFIG_DM_SPI_FLASH */ diff --git a/drivers/pinctrl/nxp/pinctrl-mxs.c b/drivers/pinctrl/nxp/pinctrl-mxs.c index bd434667b1..da6b95acc5 100644 --- a/drivers/pinctrl/nxp/pinctrl-mxs.c +++ b/drivers/pinctrl/nxp/pinctrl-mxs.c @@ -190,3 +190,5 @@ U_BOOT_DRIVER(fsl_imx23_pinctrl) = { .priv_auto_alloc_size = sizeof(struct mxs_pinctrl_priv), .ops = &mxs_pinctrl_ops, }; + +U_BOOT_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl) diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c index 0cc35042f5..b40ff8c823 100644 --- a/drivers/pinctrl/pinctrl-at91.c +++ b/drivers/pinctrl/pinctrl-at91.c @@ -525,3 +525,5 @@ U_BOOT_DRIVER(atmel_sama5d3_pinctrl) = { .priv_auto_alloc_size = sizeof(struct at91_pinctrl_priv), .ops = &at91_pinctrl_ops, }; + +U_BOOT_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl) diff --git a/drivers/power/pmi
[PATCH v4 07/14] core: drop const for struct driver_info
In order to prepare for a new support of phandle when OF_PLATDATA is used drop the const for struct driver_info as this struct will need to be updated on runtime. Signed-off-by: Walter Lozano --- drivers/core/device.c| 2 +- drivers/core/root.c | 2 +- include/dm/device-internal.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 0157bb1fe0..a0ad080aaf 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -246,7 +246,7 @@ int device_bind_ofnode(struct udevice *parent, const struct driver *drv, } int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, - const struct driver_info *info, struct udevice **devp) + struct driver_info *info, struct udevice **devp) { struct driver *drv; uint platdata_size = 0; diff --git a/drivers/core/root.c b/drivers/core/root.c index 14df16c280..c9ee56478a 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -25,7 +25,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const struct driver_info root_info = { +static struct driver_info root_info = { .name = "root_driver", }; diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index 294d6c1810..5145fb4e14 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -81,7 +81,7 @@ int device_bind_with_driver_data(struct udevice *parent, * @return 0 if OK, -ve on error */ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, - const struct driver_info *info, struct udevice **devp); + struct driver_info *info, struct udevice **devp); /** * device_ofdata_to_platdata() - Read platform data for a device -- 2.20.1
[PATCH v4 04/14] dtoc: add support to scan drivers
Currently dtoc scans dtbs to convert them to struct platdata and to generate U_BOOT_DEVICE entries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry. In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names and aliases. This allows to generate U_BOOT_DEVICE entries using valid driver names and rise a warning in the case a name is not valid. Signed-off-by: Walter Lozano --- tools/dtoc/dtb_platdata.py | 91 -- tools/dtoc/test_dtoc.py| 33 ++ 2 files changed, 120 insertions(+), 4 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index bc0de426a9..ae8674d85c 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sys from dtoc import fdt @@ -143,6 +145,11 @@ class DtbPlatdata(object): _aliases: Dict that hold aliases for compatible strings key: First compatible string declared in a node value: List of additional compatible strings declared in a node +_drivers: List of valid driver names found in drivers/ +_driver_aliases: Dict that holds aliases for driver names +key: Driver alias declared with +U_BOOT_DRIVER_ALIAS(driver_alias, driver_name) +value: Driver name declared with U_BOOT_DRIVER(driver_name) """ def __init__(self, dtb_fname, include_disabled): self._fdt = None @@ -152,6 +159,38 @@ class DtbPlatdata(object): self._outfile = None self._lines = [] self._aliases = {} +self._drivers = [] +self._driver_aliases = {} + +def get_normalized_compat_name(self, node): +"""Get a node's normalized compat name + +Returns a valid driver name by retrieving node's first compatible +string as a C identifier and performing a check against _drivers +and a lookup in driver_aliases printing a warning in case of failure. + +Args: +node: Node object to check +Return: +Tuple: +Driver name associated with the first compatible string +List of C identifiers for all the other compatible strings +(possibly empty) +In case of no match found, the return will be the same as +get_compat_name() +""" +compat_c, aliases_c = get_compat_name(node) +if compat_c not in self._drivers: +compat_c_old = compat_c +compat_c = self._driver_aliases.get(compat_c) +if not compat_c: +print('WARNING: the driver %s was not found in the driver list' + % (compat_c_old)) +compat_c = compat_c_old +else: +aliases_c = [compat_c_old] + aliases_c + +return compat_c, aliases_c def setup_output(self, fname): """Set up the output destination @@ -246,6 +285,49 @@ class DtbPlatdata(object): return PhandleInfo(max_args, args) return None +def scan_driver(self, fn): +"""Scan a driver file to build a list of driver names and aliases + +This procedure will populate self._drivers and self._driver_aliases + +Args +fn: Driver filename to scan +""" +with open(fn) as fd: +buff = fd.read() + +# The following re will search for driver names declared as +# U_BOOT_DRIVER(driver_name) +drivers = re.findall('U_BOOT_DRIVER\((.*)\)', buff) + +for driver in drivers: +self._drivers.append(driver) + +# The following re will search for driver aliases declared as +# U_BOOT_DRIVER_ALIAS(alias, driver_name) +driver_aliases = re.findall('U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', +buff) + +for alias in driver_aliases: # pragma: no cover +if len(alias) != 2: +continue +self._driver_aliases[alias[1]] = alias[0] + +def scan_drivers(self): +"""Scan the driver folders to build a list of driver names and aliases + +This procedure will populate self._drivers and self._driver_aliases + +""" +basedir = sys.argv[0].replace('tools/dtoc/dtoc', '') +if basedir == '': +basedir = './' +for (dirpath, dirnames, filenames) in os.walk(basedir): +for fn in filenames: +if not fn.endswith('.c'): +continue +self.scan_driver(dirpath + '/' + fn) +
[PATCH v4 05/14] dtoc: add option to disable warnings
As dtoc now performs checks for valid driver names, when running dtoc tests several warnings arise as these tests don't use valid driver names. This patch adds an option to disable those warning, which is only intended for running tests. Signed-off-by: Walter Lozano --- tools/dtoc/dtb_platdata.py | 13 ++-- tools/dtoc/dtoc_test_invalid_driver.dts | 15 tools/dtoc/test_dtoc.py | 91 + 3 files changed, 85 insertions(+), 34 deletions(-) create mode 100644 tools/dtoc/dtoc_test_invalid_driver.dts diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index ae8674d85c..d0cd4bf9bd 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -141,6 +141,7 @@ class DtbPlatdata(object): _valid_nodes: A list of Node object with compatible strings _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) +_warning_disabled: true to disable warnings about driver names not found _lines: Stashed list of output lines for outputting in the future _aliases: Dict that hold aliases for compatible strings key: First compatible string declared in a node @@ -151,12 +152,13 @@ class DtbPlatdata(object): U_BOOT_DRIVER_ALIAS(driver_alias, driver_name) value: Driver name declared with U_BOOT_DRIVER(driver_name) """ -def __init__(self, dtb_fname, include_disabled): +def __init__(self, dtb_fname, include_disabled, warning_disabled): self._fdt = None self._dtb_fname = dtb_fname self._valid_nodes = None self._include_disabled = include_disabled self._outfile = None +self._warning_disabled = warning_disabled self._lines = [] self._aliases = {} self._drivers = [] @@ -184,8 +186,9 @@ class DtbPlatdata(object): compat_c_old = compat_c compat_c = self._driver_aliases.get(compat_c) if not compat_c: -print('WARNING: the driver %s was not found in the driver list' - % (compat_c_old)) +if not self._warning_disabled: +print('WARNING: the driver %s was not found in the driver list' + % (compat_c_old)) compat_c = compat_c_old else: aliases_c = [compat_c_old] + aliases_c @@ -634,7 +637,7 @@ class DtbPlatdata(object): nodes_to_output.remove(node) -def run_steps(args, dtb_file, include_disabled, output): +def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False): """Run all the steps of the dtoc tool Args: @@ -646,7 +649,7 @@ def run_steps(args, dtb_file, include_disabled, output): if not args: raise ValueError('Please specify a command: struct, platdata') -plat = DtbPlatdata(dtb_file, include_disabled) +plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled) plat.scan_drivers() plat.scan_dtb() plat.scan_tree() diff --git a/tools/dtoc/dtoc_test_invalid_driver.dts b/tools/dtoc/dtoc_test_invalid_driver.dts new file mode 100644 index 00..914ac3e899 --- /dev/null +++ b/tools/dtoc/dtoc_test_invalid_driver.dts @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2017 Google, Inc + */ + +/dts-v1/; + +/ { + spl-test { + u-boot,dm-pre-reloc; + compatible = "invalid"; + }; +}; diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 91fc9d77f3..ae3ec509c1 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -12,6 +12,7 @@ tool. import collections import os import struct +import sys import unittest from dtoc import dtb_platdata @@ -101,6 +102,10 @@ class TestDtoc(unittest.TestCase): print('Failures written to /tmp/binman.{expected,actual}') self.assertEquals(expected, actual) + +def run_test(self, args, dtb_file, output): +dtb_platdata.run_steps(args, dtb_file, False, output, True) + def test_name(self): """Test conversion of device tree names to C identifiers""" self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) @@ -154,12 +159,12 @@ class TestDtoc(unittest.TestCase): """Test output from a device tree file with no nodes""" dtb_file = get_dtb_file('dtoc_test_empty.dts') output = tools.GetOutputFilename('output') -dtb_platdata.run_steps(['struct'], dtb_file, False, output) +self.run_test(['struct'], dtb_file, output) with open(output) as infile: lines = infile.read().splitlines() self.assertEqual(HEADER.splitlines(), lines) -dtb_platdata.run_steps(['platdata'], dtb_file, False, output) +self.run_test(['platdata'], dtb_file, output
[PATCH v4 06/14] dm: doc: update of-plat with the support for driver aliases
Update the documentation with the support for driver aliases using U_BOOT_DRIVER_ALIAS. Signed-off-by: Walter Lozano --- doc/driver-model/of-plat.rst | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst index 034a68bb4e..376d4409a5 100644 --- a/doc/driver-model/of-plat.rst +++ b/doc/driver-model/of-plat.rst @@ -183,6 +183,17 @@ via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a it to a valid name for C) is needed, so a dedicated driver is required for each 'compatible' string. +In order to make this a bit more flexible U_BOOT_DRIVER_ALIAS macro can be +used to declare an alias for a driver name, typically a 'compatible' string. +This macro produces no code, but it is by dtoc tool. + +During the build process dtoc parses both U_BOOT_DRIVER and U_BOOT_DRIVER_ALIAS +to build a list of valid driver names and driver aliases. If the 'compatible' +string used for a device does not not match a valid driver name, it will be +checked against the list of driver aliases in order to get the right driver +name to use. If in this step there is no match found a warning is issued to +avoid run-time failures. + Where a node has multiple compatible strings, a #define is used to make them equivalent, e.g.: @@ -269,7 +280,7 @@ For example: }; U_BOOT_DRIVER(mmc_drv) = { -.name = "vendor_mmc", /* matches compatible string */ +.name = "mmc_drv", .id = UCLASS_MMC, .of_match = mmc_ids, .ofdata_to_platdata = mmc_ofdata_to_platdata, @@ -278,6 +289,7 @@ For example: .platdata_auto_alloc_size = sizeof(struct mmc_platdata), }; +U_BOOT_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */ Note that struct mmc_platdata is defined in the C file, not in a header. This is to avoid needing to include dt-structs.h in a header file. The idea is to -- 2.20.1
[PATCH v4 02/14] dtoc: add missing code comments
Add missing information about internal class members in order to make the code easier to follow. Signed-off-by: Walter Lozano --- tools/dtoc/dtb_platdata.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index ecfe0624d1..bc0de426a9 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -140,6 +140,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future +_aliases: Dict that hold aliases for compatible strings +key: First compatible string declared in a node +value: List of additional compatible strings declared in a node """ def __init__(self, dtb_fname, include_disabled): self._fdt = None -- 2.20.1
[PATCH v4 01/14] drivers: rename drivers to match compatible string
When using OF_PLATDATA, the bind process between devices and drivers is performed trying to match compatible string with driver names. However driver names are not strictly defined, and also there are different names used when declaring a driver with U_BOOT_DRIVER, the name of the symbol used in the linker list and the used in the struct driver_info. In order to make things a bit more clear, rename the drivers names. This will also help for further OF_PLATDATA improvements, such as checking for valid driver names. Signed-off-by: Walter Lozano --- .../mach-at91/arm926ejs/at91sam9260_devices.c | 6 +-- .../arm926ejs/at91sam9m10g45_devices.c| 10 ++-- arch/arm/mach-rockchip/rk3328/syscon_rk3328.c | 4 +- board/davinci/da8xxevm/omapl138_lcdk.c| 2 +- board/sandbox/sandbox.c | 2 +- drivers/clk/at91/clk-master.c | 4 +- drivers/clk/at91/clk-peripheral.c | 4 +- drivers/clk/at91/pmc.c| 4 +- drivers/core/simple-bus.c | 4 +- drivers/gpio/at91_gpio.c | 4 +- drivers/gpio/da8xx_gpio.c | 4 +- drivers/gpio/mxs_gpio.c | 6 +-- drivers/gpio/rk_gpio.c| 4 +- drivers/gpio/sandbox.c| 4 +- drivers/i2c/rk_i2c.c | 4 +- drivers/input/cros_ec_keyb.c | 4 +- drivers/misc/cros_ec_sandbox.c| 4 +- drivers/mmc/davinci_mmc.c | 4 +- drivers/mmc/mxsmmc.c | 6 +-- drivers/mmc/rockchip_dw_mmc.c | 2 +- drivers/mtd/spi/sf-uclass.c | 2 +- drivers/mtd/spi/sf_probe.c| 4 +- drivers/pinctrl/nxp/pinctrl-mxs.c | 4 +- drivers/pinctrl/pinctrl-at91.c| 4 +- drivers/pinctrl/rockchip/pinctrl-rk3188.c | 2 +- drivers/pinctrl/rockchip/pinctrl-rk3288.c | 2 +- drivers/pinctrl/rockchip/pinctrl-rk3328.c | 2 +- drivers/pinctrl/rockchip/pinctrl-rk3368.c | 2 +- drivers/power/pmic/rk8xx.c| 4 +- drivers/power/regulator/fixed.c | 4 +- drivers/ram/rockchip/dmc-rk3368.c | 2 +- drivers/ram/rockchip/sdram_rk3188.c | 2 +- drivers/ram/rockchip/sdram_rk3288.c | 2 +- drivers/ram/rockchip/sdram_rk3328.c | 2 +- drivers/serial/sandbox.c | 6 +-- drivers/spi/mxs_spi.c | 6 +-- drivers/spi/rk_spi.c | 6 +-- drivers/spi/sandbox_spi.c | 4 +- drivers/tpm/tpm_tis_sandbox.c | 4 +- drivers/video/rockchip/rk3288_vop.c | 4 +- drivers/video/sandbox_sdl.c | 4 +- drivers/watchdog/at91sam9_wdt.c | 4 +- test/dm/gpio.c| 2 +- test/dm/spi.c | 6 +-- test/py/tests/test_bind.py| 54 +-- 45 files changed, 104 insertions(+), 120 deletions(-) diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c index c033ed6d16..8122d2f98e 100644 --- a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c +++ b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c @@ -220,7 +220,7 @@ static const struct at91_port_platdata at91sam9260_plat[] = { }; U_BOOT_DEVICES(at91sam9260_gpios) = { - { "gpio_at91", &at91sam9260_plat[0] }, - { "gpio_at91", &at91sam9260_plat[1] }, - { "gpio_at91", &at91sam9260_plat[2] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[0] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[1] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[2] }, }; diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c index 89cbeafa20..08ca3edd78 100644 --- a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c +++ b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c @@ -176,9 +176,9 @@ static const struct at91_port_platdata at91sam9260_plat[] = { }; U_BOOT_DEVICES(at91sam9260_gpios) = { - { "gpio_at91", &at91sam9260_plat[0] }, - { "gpio_at91", &at91sam9260_plat[1] }, - { "gpio_at91", &at91sam9260_plat[2] }, - { "gpio_at91", &at91sam9260_plat[3] }, - { "gpio_at91", &at91sam9260_plat[4] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[0] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[1] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[2] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[3] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[4] }, }; diff --git a/arch/arm/mach-rockchip/rk3328/syscon_rk3328.c b/arch/arm/mach-rockchip/rk3328/syscon_rk3328.c index 8a0eceb178..daf74a0e2d 100644 --- a/arch/arm/mach-rockchip/rk3328/syscon_rk3328.c +++ b/arch/arm/mach-rockchip/
[PATCH v3 14/14] dtoc: add test for cd-gpios
Add a test for dtoc taking into account the cd-gpios property. Signed-off-by: Walter Lozano --- tools/dtoc/dtoc_test_phandle_cd_gpios.dts | 42 ++ tools/dtoc/test_dtoc.py | 67 +++ 2 files changed, 109 insertions(+) create mode 100644 tools/dtoc/dtoc_test_phandle_cd_gpios.dts diff --git a/tools/dtoc/dtoc_test_phandle_cd_gpios.dts b/tools/dtoc/dtoc_test_phandle_cd_gpios.dts new file mode 100644 index 00..241743e73e --- /dev/null +++ b/tools/dtoc/dtoc_test_phandle_cd_gpios.dts @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2020 Collabora Ltd. + */ + +/dts-v1/; + +/ { + phandle: phandle-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <0>; + #gpio-cells = <0>; + }; + + phandle_1: phandle2-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <1>; + #gpio-cells = <1>; + }; + phandle_2: phandle3-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <2>; + #gpio-cells = <2>; + }; + + phandle-source { + u-boot,dm-pre-reloc; + compatible = "source"; + cd-gpios = <&phandle &phandle_1 11 &phandle_2 12 13 &phandle>; + }; + + phandle-source2 { + u-boot,dm-pre-reloc; + compatible = "source"; + cd-gpios = <&phandle>; + }; +}; diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 67ca9a8da1..3c8e343b1f 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -466,6 +466,73 @@ U_BOOT_DEVICE(phandle_source2) = { void dm_populate_phandle_data(void) { \tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target); } +''', data) + +def test_phandle_cd_gpio(self): +"""Test that phandle targets are generated when unsing cd-gpios""" +dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts') +output = tools.GetOutputFilename('output') +dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True) +with open(output) as infile: +data = infile.read() +self._CheckStrings(C_HEADER + ''' +static struct dtd_target dtv_phandle_target = { +\t.intval\t\t\t= 0x0, +}; +U_BOOT_DEVICE(phandle_target) = { +\t.name\t\t= "target", +\t.platdata\t= &dtv_phandle_target, +\t.platdata_size\t= sizeof(dtv_phandle_target), +}; + +static struct dtd_target dtv_phandle2_target = { +\t.intval\t\t\t= 0x1, +}; +U_BOOT_DEVICE(phandle2_target) = { +\t.name\t\t= "target", +\t.platdata\t= &dtv_phandle2_target, +\t.platdata_size\t= sizeof(dtv_phandle2_target), +}; + +static struct dtd_target dtv_phandle3_target = { +\t.intval\t\t\t= 0x2, +}; +U_BOOT_DEVICE(phandle3_target) = { +\t.name\t\t= "target", +\t.platdata\t= &dtv_phandle3_target, +\t.platdata_size\t= sizeof(dtv_phandle3_target), +}; + +static struct dtd_source dtv_phandle_source = { +\t.cd_gpios\t\t= { +\t\t\t{NULL, {}}, +\t\t\t{NULL, {11}}, +\t\t\t{NULL, {12, 13}}, +\t\t\t{NULL, {}},}, +}; +U_BOOT_DEVICE(phandle_source) = { +\t.name\t\t= "source", +\t.platdata\t= &dtv_phandle_source, +\t.platdata_size\t= sizeof(dtv_phandle_source), +}; + +static struct dtd_source dtv_phandle_source2 = { +\t.cd_gpios\t\t= { +\t\t\t{NULL, {}},}, +}; +U_BOOT_DEVICE(phandle_source2) = { +\t.name\t\t= "source", +\t.platdata\t= &dtv_phandle_source2, +\t.platdata_size\t= sizeof(dtv_phandle_source2), +}; + +void dm_populate_phandle_data(void) { +\tdtv_phandle_source.cd_gpios[0].node = DM_GET_DEVICE(phandle_target); +\tdtv_phandle_source.cd_gpios[1].node = DM_GET_DEVICE(phandle2_target); +\tdtv_phandle_source.cd_gpios[2].node = DM_GET_DEVICE(phandle3_target); +\tdtv_phandle_source.cd_gpios[3].node = DM_GET_DEVICE(phandle_target); +\tdtv_phandle_source2.cd_gpios[0].node = DM_GET_DEVICE(phandle_target); +} ''', data) def test_phandle_bad(self): -- 2.20.1
[PATCH v3 13/14] dtoc: update dtb_platdata to support cd-gpios
Currently dtoc does not support the property cd-gpios used to declare the gpios for card detect in mmc. This patch adds support to cd-gpios property. Signed-off-by: Walter Lozano --- tools/dtoc/dtb_platdata.py | 16 ++-- tools/dtoc/test_dtoc.py| 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index b25e1c17e0..6015ae734f 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -258,7 +258,7 @@ class DtbPlatdata(object): Return: Number of argument cells is this is a phandle, else None """ -if prop.name in ['clocks']: +if prop.name in ['clocks', 'cd-gpios']: if not isinstance(prop.value, list): prop.value = [prop.value] val = prop.value @@ -278,11 +278,14 @@ class DtbPlatdata(object): if not target: raise ValueError("Cannot parse '%s' in node '%s'" % (prop.name, node_name)) -prop_name = '#clock-cells' -cells = target.props.get(prop_name) +cells = None +for prop_name in ['#clock-cells', '#gpio-cells']: +cells = target.props.get(prop_name) +if cells: +break if not cells: -raise ValueError("Node '%s' has no '%s' property" % -(target.name, prop_name)) +raise ValueError("Node '%s' has no cells property" % +(target.name)) num_args = fdt_util.fdt32_to_cpu(cells.value) max_args = max(max_args, num_args) args.append(num_args) @@ -652,7 +655,8 @@ class DtbPlatdata(object): # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx) self.buf('void dm_populate_phandle_data(void) {\n') for l in self._links: -self.buf('\t%s = DM_GET_DEVICE(%s);\n' % (l['var_node'], l['dev_name'])) +self.buf('\t%s = DM_GET_DEVICE(%s);\n' % + (l['var_node'], l['dev_name'])) self.buf('}\n') self.out(''.join(self.get_buf())) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 209542c849..67ca9a8da1 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -485,7 +485,7 @@ void dm_populate_phandle_data(void) { output = tools.GetOutputFilename('output') with self.assertRaises(ValueError) as e: self.run_test(['struct'], dtb_file, output) -self.assertIn("Node 'phandle-target' has no '#clock-cells' property", +self.assertIn("Node 'phandle-target' has no cells property", str(e.exception)) def test_aliases(self): -- 2.20.1
[PATCH v3 08/14] core: extend struct driver_info to point to device
Currently when creating an U_BOOT_DEVICE entry a struct driver_info is declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its struct driver_info. This patch extends struct driver_info adding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its struct driver_info. Signed-off-by: Walter Lozano --- drivers/core/device.c | 26 +++--- drivers/core/root.c | 4 include/dm/device.h | 15 +++ include/dm/platdata.h | 14 ++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index a0ad080aaf..4f8c97a195 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, { struct driver *drv; uint platdata_size = 0; + int ret; drv = lists_driver_lookup_name(info->name); if (!drv) @@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, #if CONFIG_IS_ENABLED(OF_PLATDATA) platdata_size = info->platdata_size; #endif - return device_bind_common(parent, drv, info->name, - (void *)info->platdata, 0, ofnode_null(), platdata_size, - devp); + ret = device_bind_common(parent, drv, info->name, +(void *)info->platdata, 0, ofnode_null(), +platdata_size, devp); + if (ret) + return ret; +#if CONFIG_IS_ENABLED(OF_PLATDATA) + info->dev = *devp; +#endif + + return ret; } static void *alloc_priv(int size, uint flags) @@ -727,6 +735,18 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp) return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); } +#if CONFIG_IS_ENABLED(OF_PLATDATA) +int device_get_by_driver_info(const struct driver_info *info, + struct udevice **devp) +{ + struct udevice *dev; + + dev = info->dev; + + return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp); +} +#endif + int device_find_first_child(const struct udevice *parent, struct udevice **devp) { if (list_empty(&parent->child_head)) { diff --git a/drivers/core/root.c b/drivers/core/root.c index c9ee56478a..2643ef68a7 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -346,6 +346,10 @@ int dm_init_and_scan(bool pre_reloc_only) { int ret; +#if CONFIG_IS_ENABLED(OF_PLATDATA) + dm_populate_phandle_data(); +#endif + ret = dm_init(IS_ENABLED(CONFIG_OF_LIVE)); if (ret) { debug("dm_init() failed: %d\n", ret); diff --git a/include/dm/device.h b/include/dm/device.h index 2cfe10766f..f5738a0cee 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -538,6 +538,21 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp); */ int device_get_global_by_ofnode(ofnode node, struct udevice **devp); +/** + * device_get_by_driver_info() - Get a device based on driver_info + * + * Locates a device by its struct driver_info, by using its reference which + * is updated during the bind process. + * + * The device is probed to activate it ready for use. + * + * @info: Struct driver_info + * @devp: Returns pointer to device if found, otherwise this is set to NULL + * @return 0 if OK, -ve on error + */ +int device_get_by_driver_info(const struct driver_info *info, + struct udevice **devp); + /** * device_find_first_child() - Find the first child of a device * diff --git a/include/dm/platdata.h b/include/dm/platdata.h index c972fa6936..cab93b071b 100644 --- a/include/dm/platdata.h +++ b/include/dm/platdata.h @@ -22,12 +22,14 @@ * @name: Driver name * @platdata: Driver-specific platform data * @platdata_size: Size of platform data structure + * @dev: Device created from this structure data */ struct driver_info { const char *name; const void *platdata; #if CONFIG_IS_ENABLED(OF_PLATDATA) uint platdata_size; + struct udevice *dev; #endif }; @@ -43,4 +45,16 @@ struct driver_info { #define U_BOOT_DEVICES(__name) \ ll_entry_declare_list(struct driver_info, __name, driver_info) +/* Get a pointer to a given driver */ +#define DM_GET_DEVICE(__name) \ + ll_entry_get(struct driver_info, __name, driver_info) + +/** + * dm_populate_phandle_data() - Populates phandle data in platda + * + * This populates phandle data with an U_BOOT_DEVICE entry get by + * DM_GET_DEVICE. The implementation of this function will be done + * by dtoc when parsing dtb. + */ +void dm_populate_phandle_data(void); #endif -- 2.20.1
[PATCH v3 12/14] arm: dts: include gpio nodes for card detect
Several MMC drivers use GPIO for card detection with cd-gpios property in the MMC node pointing to a GPIO node. However, as U-Boot tries to save space by keeping only required nodes using u-boot* properties, several devices tree result in having only in the MMC node but not the GPIO node associated to cd-gpios. This patch, fixes several ocurrence of this issue. Signed-off-by: Walter Lozano --- arch/arm/dts/da850-evm-u-boot.dtsi| 4 arch/arm/dts/da850-lcdk-u-boot.dtsi | 4 arch/arm/dts/rk3288-u-boot.dtsi | 4 arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi | 2 +- arch/arm/dts/rk3288-veyron-u-boot.dtsi| 11 +++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 arch/arm/dts/rk3288-veyron-u-boot.dtsi diff --git a/arch/arm/dts/da850-evm-u-boot.dtsi b/arch/arm/dts/da850-evm-u-boot.dtsi index d9afc5edf4..d588628641 100644 --- a/arch/arm/dts/da850-evm-u-boot.dtsi +++ b/arch/arm/dts/da850-evm-u-boot.dtsi @@ -39,3 +39,7 @@ &spi1 { u-boot,dm-spl; }; + +&gpio { + u-boot,dm-spl; +}; diff --git a/arch/arm/dts/da850-lcdk-u-boot.dtsi b/arch/arm/dts/da850-lcdk-u-boot.dtsi index b372d06ca9..d50775c173 100644 --- a/arch/arm/dts/da850-lcdk-u-boot.dtsi +++ b/arch/arm/dts/da850-lcdk-u-boot.dtsi @@ -28,3 +28,7 @@ &serial2 { u-boot,dm-spl; }; + +&gpio { + u-boot,dm-spl; +}; diff --git a/arch/arm/dts/rk3288-u-boot.dtsi b/arch/arm/dts/rk3288-u-boot.dtsi index 6d31735362..51b6e018bd 100644 --- a/arch/arm/dts/rk3288-u-boot.dtsi +++ b/arch/arm/dts/rk3288-u-boot.dtsi @@ -43,3 +43,7 @@ &noc { u-boot,dm-pre-reloc; }; + +&gpio7 { + u-boot,dm-pre-reloc; +}; diff --git a/arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi b/arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi index eccc069368..251fbdee71 100644 --- a/arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi +++ b/arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi @@ -3,7 +3,7 @@ * Copyright 2015 Google, Inc */ -#include "rk3288-u-boot.dtsi" +#include "rk3288-veyron-u-boot.dtsi" &dmc { rockchip,pctl-timing = <0x215 0xc8 0x0 0x35 0x26 0x2 0x70 0x2000d diff --git a/arch/arm/dts/rk3288-veyron-u-boot.dtsi b/arch/arm/dts/rk3288-veyron-u-boot.dtsi new file mode 100644 index 00..899fe6e7a0 --- /dev/null +++ b/arch/arm/dts/rk3288-veyron-u-boot.dtsi @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright 2015 Google, Inc + */ + +#include "rk3288-u-boot.dtsi" + +&gpio7 { + u-boot,dm-pre-reloc; +}; + -- 2.20.1
[PATCH v3 10/14] dtoc: extend dtoc to use struct driver_info when linking nodes
In the current implementation, when dtoc parses a dtb to generate a struct platdata it converts the information related to linked nodes as pointers to struct platdata of destination nodes. By doing this, it makes difficult to get pointer to udevices created based on these information. This patch extends dtoc to use struct driver_info when populating information about linked nodes, which makes it easier to later get the devices created. In this context, reimplement functions like clk_get_by_index_platdata() which made use of the previous approach. Signed-off-by: Walter Lozano --- drivers/clk/clk-uclass.c| 11 ++- drivers/misc/irq-uclass.c | 10 ++- drivers/mmc/ftsdc010_mci.c | 2 +- drivers/mmc/rockchip_dw_mmc.c | 2 +- drivers/mmc/rockchip_sdhci.c| 2 +- drivers/ram/rockchip/sdram_rk3399.c | 2 +- drivers/spi/rk_spi.c| 2 +- include/clk.h | 4 +- tools/dtoc/dtb_platdata.py | 26 ++- tools/dtoc/test_dtoc.py | 104 10 files changed, 100 insertions(+), 65 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index 71878474eb..412f26cd29 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -25,17 +25,16 @@ static inline const struct clk_ops *clk_dev_ops(struct udevice *dev) #if CONFIG_IS_ENABLED(OF_CONTROL) # if CONFIG_IS_ENABLED(OF_PLATDATA) -int clk_get_by_index_platdata(struct udevice *dev, int index, - struct phandle_1_arg *cells, struct clk *clk) +int clk_get_by_driver_info(struct udevice *dev, struct phandle_1_arg *cells, + struct clk *clk) { int ret; - if (index != 0) - return -ENOSYS; - ret = uclass_get_device(UCLASS_CLK, 0, &clk->dev); + ret = device_get_by_driver_info((struct driver_info *)cells->node, + &clk->dev); if (ret) return ret; - clk->id = cells[0].arg[0]; + clk->id = cells->arg[0]; return 0; } diff --git a/drivers/misc/irq-uclass.c b/drivers/misc/irq-uclass.c index 61aa10e465..3c38681108 100644 --- a/drivers/misc/irq-uclass.c +++ b/drivers/misc/irq-uclass.c @@ -63,17 +63,15 @@ int irq_read_and_clear(struct irq *irq) } #if CONFIG_IS_ENABLED(OF_PLATDATA) -int irq_get_by_index_platdata(struct udevice *dev, int index, - struct phandle_1_arg *cells, struct irq *irq) +int irq_get_by_driver_info(struct udevice *dev, + struct phandle_1_arg *cells, struct irq *irq) { int ret; - if (index != 0) - return -ENOSYS; - ret = uclass_get_device(UCLASS_IRQ, 0, &irq->dev); + ret = device_get_by_driver_info(cells->node, &irq->dev); if (ret) return ret; - irq->id = cells[0].arg[0]; + irq->id = cells->arg[0]; return 0; } diff --git a/drivers/mmc/ftsdc010_mci.c b/drivers/mmc/ftsdc010_mci.c index 9c15eb36d6..efa92d48be 100644 --- a/drivers/mmc/ftsdc010_mci.c +++ b/drivers/mmc/ftsdc010_mci.c @@ -437,7 +437,7 @@ static int ftsdc010_mmc_probe(struct udevice *dev) chip->priv = dev; chip->dev_index = 1; memcpy(priv->minmax, dtplat->clock_freq_min_max, sizeof(priv->minmax)); - ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->clk); + ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->clk); if (ret < 0) return ret; #endif diff --git a/drivers/mmc/rockchip_dw_mmc.c b/drivers/mmc/rockchip_dw_mmc.c index ac710324c8..80432ddbbc 100644 --- a/drivers/mmc/rockchip_dw_mmc.c +++ b/drivers/mmc/rockchip_dw_mmc.c @@ -120,7 +120,7 @@ static int rockchip_dwmmc_probe(struct udevice *dev) priv->minmax[0] = 40; /* 400 kHz */ priv->minmax[1] = dtplat->max_frequency; - ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->clk); + ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->clk); if (ret < 0) return ret; #else diff --git a/drivers/mmc/rockchip_sdhci.c b/drivers/mmc/rockchip_sdhci.c index b440996b26..b073f1a08d 100644 --- a/drivers/mmc/rockchip_sdhci.c +++ b/drivers/mmc/rockchip_sdhci.c @@ -46,7 +46,7 @@ static int arasan_sdhci_probe(struct udevice *dev) host->name = dev->name; host->ioaddr = map_sysmem(dtplat->reg[0], dtplat->reg[1]); max_frequency = dtplat->max_frequency; - ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &clk); + ret = clk_get_by_driver_info(dev, dtplat->clocks, &clk); #else max_frequency = dev_read_u32_default(dev, "max-frequency", 0); ret = clk_get_by_index(dev, 0, &clk); diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c index d69ef01d08..87ec25f893 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @
[PATCH v3 11/14] dm: doc: update of-plat with new phandle support
Update documentation to reflect the new phandle support when OF_PLATDATA is used. Now phandles are implemented as pointers to U_BOOT_DEVICE, which makes it possible to get a pointer to the actual device. Signed-off-by: Walter Lozano --- doc/driver-model/of-plat.rst | 24 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst index 376d4409a5..1e3fad137b 100644 --- a/doc/driver-model/of-plat.rst +++ b/doc/driver-model/of-plat.rst @@ -69,9 +69,8 @@ strictly necessary. Notable problems include: - Correct relations between nodes are not implemented. This means that parent/child relations (like bus device iteration) do not work yet. Some phandles (those that are recognised as such) are converted into - a pointer to platform data. This pointer can potentially be used to - access the referenced device (by searching for the pointer value). - This feature is not yet implemented, however. + a pointer to struct driver_info. This pointer can be used to access + the referenced device. How it works @@ -146,10 +145,10 @@ and the following device declaration: .clock_freq_min_max = {0x61a80, 0x8f0d180}, .vmmc_supply= 0xb, .num_slots = 0x1, -.clocks = {{&dtv_clock_controller_at_ff76, 456}, - {&dtv_clock_controller_at_ff76, 68}, - {&dtv_clock_controller_at_ff76, 114}, - {&dtv_clock_controller_at_ff76, 118}}, +.clocks = {{NULL, 456}, + {NULL, 68}, + {NULL, 114}, + {NULL, 118}}, .cap_mmc_highspeed = true, .disable_wp = true, .bus_width = 0x4, @@ -164,6 +163,13 @@ and the following device declaration: .platdata_size = sizeof(dtv_dwmmc_at_ff0c), }; +void dm_populate_phandle_data(void) { +dtv_dwmmc_at_ff0c.clocks[0].node = DM_GET_DEVICE(clock_controller_at_ff76); +dtv_dwmmc_at_ff0c.clocks[1].node = DM_GET_DEVICE(clock_controller_at_ff76); +dtv_dwmmc_at_ff0c.clocks[2].node = DM_GET_DEVICE(clock_controller_at_ff76); +dtv_dwmmc_at_ff0c.clocks[3].node = DM_GET_DEVICE(clock_controller_at_ff76); +} + The device is then instantiated at run-time and the platform data can be accessed using: @@ -329,7 +335,9 @@ prevents them being used inadvertently. All usage must be bracketed with #if CONFIG_IS_ENABLED(OF_PLATDATA). The dt-platdata.c file contains the device declarations and is is built in -spl/dt-platdata.c. +spl/dt-platdata.c. It additionally contains the definition of +dm_populate_phandle_data() which is responsible of filling the phandle +information by adding references to U_BOOT_DEVICE by using DM_GET_DEVICE The beginnings of a libfdt Python module are provided. So far this only implements a subset of the features. -- 2.20.1
[PATCH v3 09/14] sandbox: Move section u_boot_list to make it RW
In order to be able to update data in u_boot_list, move this section to make it RW. Signed-off-by: Walter Lozano --- arch/sandbox/cpu/u-boot-spl.lds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/u-boot-spl.lds b/arch/sandbox/cpu/u-boot-spl.lds index de65b01b33..c60eb109b1 100644 --- a/arch/sandbox/cpu/u-boot-spl.lds +++ b/arch/sandbox/cpu/u-boot-spl.lds @@ -20,4 +20,4 @@ SECTIONS __bss_start = .; } -INSERT BEFORE .data; +INSERT AFTER .data; -- 2.20.1
[PATCH v3 06/14] dm: doc: update of-plat with the support for driver aliases
Update the documentation with the support for driver aliases using U_BOOT_DRIVER_ALIAS. Signed-off-by: Walter Lozano --- doc/driver-model/of-plat.rst | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst index 034a68bb4e..376d4409a5 100644 --- a/doc/driver-model/of-plat.rst +++ b/doc/driver-model/of-plat.rst @@ -183,6 +183,17 @@ via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a it to a valid name for C) is needed, so a dedicated driver is required for each 'compatible' string. +In order to make this a bit more flexible U_BOOT_DRIVER_ALIAS macro can be +used to declare an alias for a driver name, typically a 'compatible' string. +This macro produces no code, but it is by dtoc tool. + +During the build process dtoc parses both U_BOOT_DRIVER and U_BOOT_DRIVER_ALIAS +to build a list of valid driver names and driver aliases. If the 'compatible' +string used for a device does not not match a valid driver name, it will be +checked against the list of driver aliases in order to get the right driver +name to use. If in this step there is no match found a warning is issued to +avoid run-time failures. + Where a node has multiple compatible strings, a #define is used to make them equivalent, e.g.: @@ -269,7 +280,7 @@ For example: }; U_BOOT_DRIVER(mmc_drv) = { -.name = "vendor_mmc", /* matches compatible string */ +.name = "mmc_drv", .id = UCLASS_MMC, .of_match = mmc_ids, .ofdata_to_platdata = mmc_ofdata_to_platdata, @@ -278,6 +289,7 @@ For example: .platdata_auto_alloc_size = sizeof(struct mmc_platdata), }; +U_BOOT_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */ Note that struct mmc_platdata is defined in the C file, not in a header. This is to avoid needing to include dt-structs.h in a header file. The idea is to -- 2.20.1
[PATCH v3 07/14] core: drop const for struct driver_info
In order to prepare for a new support of phandle when OF_PLATDATA is used drop the const for struct driver_info as this struct will need to be updated on runtime. Signed-off-by: Walter Lozano --- drivers/core/device.c| 2 +- drivers/core/root.c | 2 +- include/dm/device-internal.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 0157bb1fe0..a0ad080aaf 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -246,7 +246,7 @@ int device_bind_ofnode(struct udevice *parent, const struct driver *drv, } int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, - const struct driver_info *info, struct udevice **devp) + struct driver_info *info, struct udevice **devp) { struct driver *drv; uint platdata_size = 0; diff --git a/drivers/core/root.c b/drivers/core/root.c index 14df16c280..c9ee56478a 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -25,7 +25,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const struct driver_info root_info = { +static struct driver_info root_info = { .name = "root_driver", }; diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index 294d6c1810..5145fb4e14 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -81,7 +81,7 @@ int device_bind_with_driver_data(struct udevice *parent, * @return 0 if OK, -ve on error */ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only, - const struct driver_info *info, struct udevice **devp); + struct driver_info *info, struct udevice **devp); /** * device_ofdata_to_platdata() - Read platform data for a device -- 2.20.1
[PATCH v3 04/14] dtoc: add support to scan drivers
Currently dtoc scans dtbs to convert them to struct platdata and to generate U_BOOT_DEVICE entries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry. In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names and aliases. This allows to generate U_BOOT_DEVICE entries using valid driver names and rise a warning in the case a name is not valid. Signed-off-by: Walter Lozano --- tools/dtoc/dtb_platdata.py | 91 -- tools/dtoc/test_dtoc.py| 33 ++ 2 files changed, 120 insertions(+), 4 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index bc0de426a9..ae8674d85c 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -13,6 +13,8 @@ static data. import collections import copy +import os +import re import sys from dtoc import fdt @@ -143,6 +145,11 @@ class DtbPlatdata(object): _aliases: Dict that hold aliases for compatible strings key: First compatible string declared in a node value: List of additional compatible strings declared in a node +_drivers: List of valid driver names found in drivers/ +_driver_aliases: Dict that holds aliases for driver names +key: Driver alias declared with +U_BOOT_DRIVER_ALIAS(driver_alias, driver_name) +value: Driver name declared with U_BOOT_DRIVER(driver_name) """ def __init__(self, dtb_fname, include_disabled): self._fdt = None @@ -152,6 +159,38 @@ class DtbPlatdata(object): self._outfile = None self._lines = [] self._aliases = {} +self._drivers = [] +self._driver_aliases = {} + +def get_normalized_compat_name(self, node): +"""Get a node's normalized compat name + +Returns a valid driver name by retrieving node's first compatible +string as a C identifier and performing a check against _drivers +and a lookup in driver_aliases printing a warning in case of failure. + +Args: +node: Node object to check +Return: +Tuple: +Driver name associated with the first compatible string +List of C identifiers for all the other compatible strings +(possibly empty) +In case of no match found, the return will be the same as +get_compat_name() +""" +compat_c, aliases_c = get_compat_name(node) +if compat_c not in self._drivers: +compat_c_old = compat_c +compat_c = self._driver_aliases.get(compat_c) +if not compat_c: +print('WARNING: the driver %s was not found in the driver list' + % (compat_c_old)) +compat_c = compat_c_old +else: +aliases_c = [compat_c_old] + aliases_c + +return compat_c, aliases_c def setup_output(self, fname): """Set up the output destination @@ -246,6 +285,49 @@ class DtbPlatdata(object): return PhandleInfo(max_args, args) return None +def scan_driver(self, fn): +"""Scan a driver file to build a list of driver names and aliases + +This procedure will populate self._drivers and self._driver_aliases + +Args +fn: Driver filename to scan +""" +with open(fn) as fd: +buff = fd.read() + +# The following re will search for driver names declared as +# U_BOOT_DRIVER(driver_name) +drivers = re.findall('U_BOOT_DRIVER\((.*)\)', buff) + +for driver in drivers: +self._drivers.append(driver) + +# The following re will search for driver aliases declared as +# U_BOOT_DRIVER_ALIAS(alias, driver_name) +driver_aliases = re.findall('U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', +buff) + +for alias in driver_aliases: # pragma: no cover +if len(alias) != 2: +continue +self._driver_aliases[alias[1]] = alias[0] + +def scan_drivers(self): +"""Scan the driver folders to build a list of driver names and aliases + +This procedure will populate self._drivers and self._driver_aliases + +""" +basedir = sys.argv[0].replace('tools/dtoc/dtoc', '') +if basedir == '': +basedir = './' +for (dirpath, dirnames, filenames) in os.walk(basedir): +for fn in filenames: +if not fn.endswith('.c'): +continue +self.scan_driver(dirpath + '/' + fn) +
[PATCH v3 05/14] dtoc: add option to disable warnings
As dtoc now performs checks for valid driver names, when running dtoc tests several warnings arise as these tests don't use valid driver names. This patch adds an option to disable those warning, which is only intended for running tests. Signed-off-by: Walter Lozano --- tools/dtoc/dtb_platdata.py | 13 ++-- tools/dtoc/dtoc_test_invalid_driver.dts | 15 tools/dtoc/test_dtoc.py | 91 + 3 files changed, 85 insertions(+), 34 deletions(-) create mode 100644 tools/dtoc/dtoc_test_invalid_driver.dts diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index ae8674d85c..d0cd4bf9bd 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -141,6 +141,7 @@ class DtbPlatdata(object): _valid_nodes: A list of Node object with compatible strings _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) +_warning_disabled: true to disable warnings about driver names not found _lines: Stashed list of output lines for outputting in the future _aliases: Dict that hold aliases for compatible strings key: First compatible string declared in a node @@ -151,12 +152,13 @@ class DtbPlatdata(object): U_BOOT_DRIVER_ALIAS(driver_alias, driver_name) value: Driver name declared with U_BOOT_DRIVER(driver_name) """ -def __init__(self, dtb_fname, include_disabled): +def __init__(self, dtb_fname, include_disabled, warning_disabled): self._fdt = None self._dtb_fname = dtb_fname self._valid_nodes = None self._include_disabled = include_disabled self._outfile = None +self._warning_disabled = warning_disabled self._lines = [] self._aliases = {} self._drivers = [] @@ -184,8 +186,9 @@ class DtbPlatdata(object): compat_c_old = compat_c compat_c = self._driver_aliases.get(compat_c) if not compat_c: -print('WARNING: the driver %s was not found in the driver list' - % (compat_c_old)) +if not self._warning_disabled: +print('WARNING: the driver %s was not found in the driver list' + % (compat_c_old)) compat_c = compat_c_old else: aliases_c = [compat_c_old] + aliases_c @@ -634,7 +637,7 @@ class DtbPlatdata(object): nodes_to_output.remove(node) -def run_steps(args, dtb_file, include_disabled, output): +def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False): """Run all the steps of the dtoc tool Args: @@ -646,7 +649,7 @@ def run_steps(args, dtb_file, include_disabled, output): if not args: raise ValueError('Please specify a command: struct, platdata') -plat = DtbPlatdata(dtb_file, include_disabled) +plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled) plat.scan_drivers() plat.scan_dtb() plat.scan_tree() diff --git a/tools/dtoc/dtoc_test_invalid_driver.dts b/tools/dtoc/dtoc_test_invalid_driver.dts new file mode 100644 index 00..914ac3e899 --- /dev/null +++ b/tools/dtoc/dtoc_test_invalid_driver.dts @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2017 Google, Inc + */ + +/dts-v1/; + +/ { + spl-test { + u-boot,dm-pre-reloc; + compatible = "invalid"; + }; +}; diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 91fc9d77f3..ae3ec509c1 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -12,6 +12,7 @@ tool. import collections import os import struct +import sys import unittest from dtoc import dtb_platdata @@ -101,6 +102,10 @@ class TestDtoc(unittest.TestCase): print('Failures written to /tmp/binman.{expected,actual}') self.assertEquals(expected, actual) + +def run_test(self, args, dtb_file, output): +dtb_platdata.run_steps(args, dtb_file, False, output, True) + def test_name(self): """Test conversion of device tree names to C identifiers""" self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) @@ -154,12 +159,12 @@ class TestDtoc(unittest.TestCase): """Test output from a device tree file with no nodes""" dtb_file = get_dtb_file('dtoc_test_empty.dts') output = tools.GetOutputFilename('output') -dtb_platdata.run_steps(['struct'], dtb_file, False, output) +self.run_test(['struct'], dtb_file, output) with open(output) as infile: lines = infile.read().splitlines() self.assertEqual(HEADER.splitlines(), lines) -dtb_platdata.run_steps(['platdata'], dtb_file, False, output) +self.run_test(['platdata'], dtb_file, output
[PATCH v3 01/14] drivers: rename drivers to match compatible string
When using OF_PLATDATA, the bind process between devices and drivers is performed trying to match compatible string with driver names. However driver names are not strictly defined, and also there are different names used when declaring a driver with U_BOOT_DRIVER, the name of the symbol used in the linker list and the used in the struct driver_info. In order to make things a bit more clear, rename the drivers names. This will also help for further OF_PLATDATA improvements, such as checking for valid driver names. Signed-off-by: Walter Lozano --- .../mach-at91/arm926ejs/at91sam9260_devices.c | 6 +-- .../arm926ejs/at91sam9m10g45_devices.c| 10 ++-- arch/arm/mach-rockchip/rk3328/syscon_rk3328.c | 4 +- board/davinci/da8xxevm/omapl138_lcdk.c| 2 +- board/sandbox/sandbox.c | 2 +- drivers/clk/at91/clk-master.c | 4 +- drivers/clk/at91/clk-peripheral.c | 4 +- drivers/clk/at91/pmc.c| 4 +- drivers/core/simple-bus.c | 4 +- drivers/gpio/at91_gpio.c | 4 +- drivers/gpio/da8xx_gpio.c | 4 +- drivers/gpio/mxs_gpio.c | 6 +-- drivers/gpio/rk_gpio.c| 4 +- drivers/gpio/sandbox.c| 4 +- drivers/i2c/rk_i2c.c | 4 +- drivers/input/cros_ec_keyb.c | 4 +- drivers/misc/cros_ec_sandbox.c| 4 +- drivers/mmc/davinci_mmc.c | 4 +- drivers/mmc/mxsmmc.c | 6 +-- drivers/mmc/rockchip_dw_mmc.c | 2 +- drivers/mtd/spi/sf-uclass.c | 2 +- drivers/mtd/spi/sf_probe.c| 4 +- drivers/pinctrl/nxp/pinctrl-mxs.c | 4 +- drivers/pinctrl/pinctrl-at91.c| 4 +- drivers/pinctrl/rockchip/pinctrl-rk3188.c | 2 +- drivers/pinctrl/rockchip/pinctrl-rk3288.c | 2 +- drivers/pinctrl/rockchip/pinctrl-rk3328.c | 2 +- drivers/pinctrl/rockchip/pinctrl-rk3368.c | 2 +- drivers/power/pmic/rk8xx.c| 4 +- drivers/power/regulator/fixed.c | 4 +- drivers/ram/rockchip/dmc-rk3368.c | 2 +- drivers/ram/rockchip/sdram_rk3188.c | 2 +- drivers/ram/rockchip/sdram_rk3288.c | 2 +- drivers/ram/rockchip/sdram_rk3328.c | 2 +- drivers/serial/sandbox.c | 6 +-- drivers/spi/mxs_spi.c | 6 +-- drivers/spi/rk_spi.c | 6 +-- drivers/spi/sandbox_spi.c | 4 +- drivers/tpm/tpm_tis_sandbox.c | 4 +- drivers/video/rockchip/rk3288_vop.c | 4 +- drivers/video/sandbox_sdl.c | 4 +- drivers/watchdog/at91sam9_wdt.c | 4 +- test/dm/gpio.c| 2 +- test/dm/spi.c | 6 +-- test/py/tests/test_bind.py| 54 +-- 45 files changed, 104 insertions(+), 120 deletions(-) diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c index c033ed6d16..8122d2f98e 100644 --- a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c +++ b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c @@ -220,7 +220,7 @@ static const struct at91_port_platdata at91sam9260_plat[] = { }; U_BOOT_DEVICES(at91sam9260_gpios) = { - { "gpio_at91", &at91sam9260_plat[0] }, - { "gpio_at91", &at91sam9260_plat[1] }, - { "gpio_at91", &at91sam9260_plat[2] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[0] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[1] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[2] }, }; diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c index 89cbeafa20..08ca3edd78 100644 --- a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c +++ b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c @@ -176,9 +176,9 @@ static const struct at91_port_platdata at91sam9260_plat[] = { }; U_BOOT_DEVICES(at91sam9260_gpios) = { - { "gpio_at91", &at91sam9260_plat[0] }, - { "gpio_at91", &at91sam9260_plat[1] }, - { "gpio_at91", &at91sam9260_plat[2] }, - { "gpio_at91", &at91sam9260_plat[3] }, - { "gpio_at91", &at91sam9260_plat[4] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[0] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[1] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[2] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[3] }, + { "atmel_at91rm9200_gpio", &at91sam9260_plat[4] }, }; diff --git a/arch/arm/mach-rockchip/rk3328/syscon_rk3328.c b/arch/arm/mach-rockchip/rk3328/syscon_rk3328.c index 8a0eceb178..daf74a0e2d 100644 --- a/arch/arm/mach-rockchip/rk3328/syscon_rk3328.c +++ b/arch/arm/mach-rockchip/
[PATCH v3 03/14] core: add support for U_BOOT_DRIVER_ALIAS
Currently when using OF_PLATDATA the binding between devices and drivers is done trying to match the compatible string in the node with a driver name. However, usually a single driver supports multiple compatible strings which causes that only devices which its compatible string matches a driver name get bound. To overcome this issue, this patch adds the U_BOOT_DRIVER_ALIAS macro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc could be improve to look for the driver name based on its alias when it populates the U_BOOT_DEVICE entry. Signed-off-by: Walter Lozano --- drivers/clk/at91/pmc.c| 2 ++ drivers/gpio/mxs_gpio.c | 2 ++ drivers/gpio/sandbox.c| 2 ++ drivers/i2c/rk_i2c.c | 2 ++ drivers/mmc/mxsmmc.c | 1 + drivers/mmc/rockchip_dw_mmc.c | 3 +++ drivers/mtd/spi/sf_probe.c| 2 ++ drivers/pinctrl/nxp/pinctrl-mxs.c | 2 ++ drivers/pinctrl/pinctrl-at91.c| 2 ++ drivers/power/pmic/rk8xx.c| 2 ++ drivers/serial/ns16550.c | 4 drivers/spi/mxs_spi.c | 2 ++ drivers/spi/rk_spi.c | 2 ++ include/dm/device.h | 7 +++ 14 files changed, 35 insertions(+) diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c index 1fede16a0c..793a506d27 100644 --- a/drivers/clk/at91/pmc.c +++ b/drivers/clk/at91/pmc.c @@ -30,6 +30,8 @@ U_BOOT_DRIVER(atmel_at91rm9200_pmc) = { .of_match = at91_pmc_match, }; +U_BOOT_DRIVER_ALIAS(atmel_at91rm9200_pmc, atmel_at91sam9260_pmc) + /*-*/ int at91_pmc_core_probe(struct udevice *dev) diff --git a/drivers/gpio/mxs_gpio.c b/drivers/gpio/mxs_gpio.c index e43484d13a..bcdf08c255 100644 --- a/drivers/gpio/mxs_gpio.c +++ b/drivers/gpio/mxs_gpio.c @@ -309,4 +309,6 @@ U_BOOT_DRIVER(fsl_imx23_gpio) = { .ofdata_to_platdata = mxs_ofdata_to_platdata, #endif }; + +U_BOOT_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio) #endif /* DM_GPIO */ diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index ff46d3c8d1..8923e54867 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -253,6 +253,8 @@ U_BOOT_DRIVER(sandbox_gpio) = { .ops= &gpio_sandbox_ops, }; +U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias) + /* pincontrol: used only to check GPIO pin configuration (pinmux command) */ struct sb_pinctrl_priv { diff --git a/drivers/i2c/rk_i2c.c b/drivers/i2c/rk_i2c.c index eceef80e70..e76c087b1d 100644 --- a/drivers/i2c/rk_i2c.c +++ b/drivers/i2c/rk_i2c.c @@ -492,3 +492,5 @@ U_BOOT_DRIVER(rockchip_rk3066_i2c) = { .priv_auto_alloc_size = sizeof(struct rk_i2c), .ops= &rockchip_i2c_ops, }; + +U_BOOT_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c) diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 35c336b499..afa95e57ee 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -724,4 +724,5 @@ U_BOOT_DRIVER(fsl_imx23_mmc) = { .platdata_auto_alloc_size = sizeof(struct mxsmmc_platdata), }; +U_BOOT_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc) #endif /* CONFIG_DM_MMC */ diff --git a/drivers/mmc/rockchip_dw_mmc.c b/drivers/mmc/rockchip_dw_mmc.c index ef75367b3e..ac710324c8 100644 --- a/drivers/mmc/rockchip_dw_mmc.c +++ b/drivers/mmc/rockchip_dw_mmc.c @@ -178,6 +178,9 @@ U_BOOT_DRIVER(rockchip_rk3288_dw_mshc) = { .platdata_auto_alloc_size = sizeof(struct rockchip_mmc_plat), }; +U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc) +U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc) + #ifdef CONFIG_PWRSEQ static int rockchip_dwmmc_pwrseq_set_power(struct udevice *dev, bool enable) { diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 1b44cc68c6..97fa22a4b3 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -180,4 +180,6 @@ U_BOOT_DRIVER(jedec_spi_nor) = { .ops= &spi_flash_std_ops, }; +U_BOOT_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16) + #endif /* CONFIG_DM_SPI_FLASH */ diff --git a/drivers/pinctrl/nxp/pinctrl-mxs.c b/drivers/pinctrl/nxp/pinctrl-mxs.c index bd434667b1..da6b95acc5 100644 --- a/drivers/pinctrl/nxp/pinctrl-mxs.c +++ b/drivers/pinctrl/nxp/pinctrl-mxs.c @@ -190,3 +190,5 @@ U_BOOT_DRIVER(fsl_imx23_pinctrl) = { .priv_auto_alloc_size = sizeof(struct mxs_pinctrl_priv), .ops = &mxs_pinctrl_ops, }; + +U_BOOT_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl) diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c index 0cc35042f5..b40ff8c823 100644 --- a/drivers/pinctrl/pinctrl-at91.c +++ b/drivers/pinctrl/pinctrl-at91.c @@ -525,3 +525,5 @@ U_BOOT_DRIVER(atmel_sama5d3_pinctrl) = { .priv_auto_alloc_size = sizeof(struct at91_pinctrl_priv), .ops = &at91_pinctrl_ops, }; + +U_BOOT_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl) diff --git a/drivers/power/pmi
[PATCH v3 02/14] dtoc: add missing code comments
Add missing information about internal class members in order to make the code easier to follow. Signed-off-by: Walter Lozano --- tools/dtoc/dtb_platdata.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index ecfe0624d1..bc0de426a9 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -140,6 +140,9 @@ class DtbPlatdata(object): _include_disabled: true to include nodes marked status = "disabled" _outfile: The current output file (sys.stdout or a real file) _lines: Stashed list of output lines for outputting in the future +_aliases: Dict that hold aliases for compatible strings +key: First compatible string declared in a node +value: List of additional compatible strings declared in a node """ def __init__(self, dtb_fname, include_disabled): self._fdt = None -- 2.20.1
Re: [PATCH v3 0/4] spi: kirkwood: dm-conversion (part4)
On Fri, Jun 19, 2020 at 8:31 PM Chris Packham wrote: > > Hi Jagan, > > On Fri, 19 Jun 2020, 5:45 AM Jagan Teki, wrote: >> >> Series of kirkwood boards to switch DM_SPI and drop >> which are not DM enabled still. >> >> Any inputs? >> Jagan. > > > I had a quick glance over the series and it looks good to me. > > I'm fortunate enough to be able to get into the office so I'll try and give > this a spin on the kirkwood board I have on Monday. > Tooks a bit longer to dust off the kirkwood board than I expected. For this series Tested-by: Chris Packham
[PATCH 0/2] arm: mvebu: a38x: USB2 serdes changes
While debugging this issue with Marvell I found the change that was made to Marvell's u-boot but doesn't appear to have made it upstream. We're in the process of checking the affect it has on the USB compliance testing we're doing. I have regression tested it against a couple of USB devices (Ethernet and Storage). But it'd be good to get some more coverage against other hardware platforms and USB devices. Chris Packham (2): arm: mvebu: a38x: Fix typo arm: mvebu: a38x: Adjust UTMI PHY parameters .../serdes/a38x/high_speed_env_spec.c | 27 +++ 1 file changed, 22 insertions(+), 5 deletions(-) -- 2.27.0
[PATCH 1/2] arm: mvebu: a38x: Fix typo
Fix spelling of Alignment. Signed-off-by: Chris Packham --- arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c b/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c index 67a00cf1cf7b..d4480622c89c 100644 --- a/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c +++ b/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c @@ -533,7 +533,7 @@ struct op_params pex_and_usb3_tx_config_params3[] = { struct op_params pex_by4_config_params[] = { /* unit_base_reg, unit_offset, mask, data, wait_time, num_of_loops */ {GLOBAL_CLK_SRC_HI, 0x800, 0x7, {0x5, 0x0, 0x0, 0x2}, 0, 0}, - /* Lane Alignement enable */ + /* Lane Alignment enable */ {LANE_ALIGN_REG0, 0x800, 0x1000, {0x0, 0x0, 0x0, 0x0}, 0, 0}, /* Max PLL phy config */ {CALIBRATION_CTRL_REG, 0x800, 0x1000, {0x1000, 0x1000, 0x1000, 0x1000}, -- 2.27.0
[PATCH 2/2] arm: mvebu: a38x: Adjust UTMI PHY parameters
When running USB compliance tests on our Armada-385 hardware platforms we have seen some eye mask violations. Marvell's internal documentation says: Based on silicon test results, it is recommended to change the impedance calibration threshold setting to 0x6 prior to calibration. Port changes from Marvell's u-boot fork[1] to address this. [1] - https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/commit/a6221551 Signed-off-by: Chris Packham --- .../serdes/a38x/high_speed_env_spec.c | 25 --- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c b/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c index d4480622c89c..2454730e6d86 100644 --- a/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c +++ b/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c @@ -672,12 +672,29 @@ struct op_params usb2_power_up_params[] = { {0xc200c, 0x0 /*NA*/, 0x100, {0x100}, 0, 0}, /* Phy0 register 3 - TX Channel control 0 */ {0xc400c, 0x0 /*NA*/, 0x100, {0x100}, 0, 0}, - /* check PLLCAL_DONE is set and IMPCAL_DONE is set */ + /* Decrease the amplitude of the low speed eye to meet the spec */ + {0xc000c, 0x0 /*NA*/, 0xf000, {0x1000}, 0, 0}, + {0xc200c, 0x0 /*NA*/, 0xf000, {0x1000}, 0, 0}, + {0xc400c, 0x0 /*NA*/, 0xf000, {0x1000}, 0, 0}, + /* Change the High speed impedance threshold */ + {0xc0008, 0x0 /*NA*/, 0x700, {0x600}, 0, 0}, + {0xc2008, 0x0 /*NA*/, 0x700, {0x600}, 0, 0}, + {0xc4008, 0x0 /*NA*/, 0x700, {0x600}, 0, 0}, + /* Change the squelch level of the receiver to meet the receiver electrical measurements (squelch and receiver sensitivity tests) */ + {0xc0014, 0x0 /*NA*/, 0xf, {0x8}, 0, 0}, + {0xc2014, 0x0 /*NA*/, 0xf, {0x8}, 0, 0}, + {0xc4014, 0x0 /*NA*/, 0xf, {0x8}, 0, 0}, + /* Check PLLCAL_DONE is set and IMPCAL_DONE is set */ {0xc0008, 0x0 /*NA*/, 0x8080, {0x8080}, 1, 1000}, - /* check REG_SQCAL_DONE is set */ + /* Check REG_SQCAL_DONE is set */ {0xc0018, 0x0 /*NA*/, 0x8000, {0x8000}, 1, 1000}, - /* check PLL_READY is set */ - {0xc, 0x0 /*NA*/, 0x8000, {0x8000}, 1, 1000} + /* Check PLL_READY is set */ + {0xc, 0x0 /*NA*/, 0x8000, {0x8000}, 1, 1000}, + /* Start calibrate of high seed impedance */ + {0xc0008, 0x0 /*NA*/, 0x2000, {0x2000}, 0, 0}, + {0x0, 0x0 /*NA*/, 0x0, {0x0}, 10, 0}, + /* De-assert the calibration signal */ + {0xc0008, 0x0 /*NA*/, 0x2000, {0x0}, 0, 0}, }; /* -- 2.27.0
Re: U-Boot atheros PHY support and cubox ethernet
On Wed, Jun 24, 2020 at 8:19 PM Fabio Estevam wrote: > - We tried via devicetree with the "qca,clk-out-frequency" property, > but it did not work. This is an area where you could add some debug > prints inside drivers/net/phy/atheros.c and see if if > qca,clk-out-frequency is being parsed correctly to configure a 125MHz > clock output. This is the method I used on mx6cuboxi last week and it > works. To help debugging why "qca,clk-out-frequency" is not taking effect you could try this debug patch: https://pastebin.com/raw/RKG63JGJ This is the result on a imx6 hummingboard: Net: ar803x_of_init: found PHY node: ethernet-phy@0 ** clk out frequency is 12500 ar803x_of_init: flags=0 clk_25m_reg=0018 clk_25m_mask=0018 PHY mode is 8 Warning: ethernet@2188000 using MAC address from ROM eth0: ethernet@2188000 Hit any key to stop autoboot: 0 =>
Re: [PATCH v4 1/4] fu540: prci: add request and free clock handlers
Hi Sagar, On Wed, Jun 24, 2020 at 6:58 PM Sagar Kadam wrote: > > Hi Bin, > > > -Original Message- > > From: Bin Meng > > Sent: Wednesday, June 24, 2020 6:50 AM > > To: Sagar Kadam > > Cc: U-Boot Mailing List ; Rick Chen > > ; Lukasz Majewski ; Jagan Teki > > ; Pragnesh Patel > > ; Anup Patel ; Simon > > Glass ; Sean Anderson > > Subject: Re: [PATCH v4 1/4] fu540: prci: add request and free clock handlers > > > > [External Email] Do not click links or attachments unless you recognize the > > sender and know the content is safe > > > > Hi Sagar, > > > > On Sun, Jun 21, 2020 at 9:10 PM Sagar Shrikant Kadam > > wrote: > > > > > > Add clk_request handler to check if a valid clock is requested. > > > Here clk_free handler is added for debug purpose which will display > > > details of clock passed to clk_free. > > > > > > Signed-off-by: Sagar Shrikant Kadam > > > Reviewed-by: Pragnesh Patel > > > --- > > > drivers/clk/sifive/fu540-prci.c | 21 + > > > 1 file changed, 21 insertions(+) > > > > > > diff --git a/drivers/clk/sifive/fu540-prci.c > > > b/drivers/clk/sifive/fu540-prci.c index fe6e0d4..9a9ff6b 100644 > > > --- a/drivers/clk/sifive/fu540-prci.c > > > +++ b/drivers/clk/sifive/fu540-prci.c > > > @@ -686,6 +686,25 @@ static ulong sifive_fu540_prci_set_rate(struct clk > > *clk, ulong rate) > > > return rate; > > > } > > > > > > +static int sifive_fu540_prci_clk_request(struct clk *clk) { > > > + debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, > > > + clk->id); > > > + > > > + if (clk->id >= ARRAY_SIZE(__prci_init_clocks)) > > > + return -EINVAL; > > > + > > > + return 0; > > > +} > > > + > > > +static int sifive_fu540_prci_clk_free(struct clk *clk) { > > > + debug("%s(clk=%p) (dev=%p, id=%lu)\n", __func__, clk, clk->dev, > > > + clk->id); > > > + > > > + return 0; > > > +} > > > > It seems these 2 routines do not actually do anything? Is this for debugging > > purposes? > > > The sifive_fu540_prci_clk_request will check if the clock requested is valid > or not. > While the sifive_fu540_prci_clk_free function is just for debug. > Is it ok if I retain these in V5 or you have some other thought here. > OK, but I suspect the parameter check in sifive_fu540_prci_clk_request() is not necessary too as currently the codes work well. Regards, Bin
Re: U-Boot atheros PHY support and cubox ethernet
Hi Soeren, On Wed, Jun 24, 2020 at 7:29 PM Soeren Moch wrote: > Unfortunately I have no access to my usual development board (and will > not have until the v2020.07 release). I only can use an old board > without working USB-OTG, limited to eMMC boot. So I tried to avoid > bisecting, because a bad commit could completely brick this board. Ok, understood. We could check if the issue on your board is due to: commit 6333cbb3817ed551cd7d4e92f7359c73ccc567fc Author: Michael Walle Date: Thu May 7 00:11:58 2020 +0200 phy: atheros: ar8035: remove static clock config We can configure the clock output in the device tree. Disable the hardcoded one in here. This is highly board-specific and should have never been enabled in the PHY driver. If bisecting shows that this commit breaks your board it probably depends on the clock output of your Atheros AR8035 PHY. Please have a look at doc/device-tree-bindings/net/phy/atheros.txt. You need to set "clk-out-frequency = <12500>" because that value was the hardcoded value until this commit. Signed-off-by: Michael Walle Acked-by: Joe Hershberger On your board, are you able to measure with a scope the AR8035 CLK_25M pin? Prior to this commit the CLK_25M was hardcoded to output a 125MHz clock. Now that this setting from the ar8035 phy driver is gone we should pass this information in some form: - We tried via devicetree with the "qca,clk-out-frequency" property, but it did not work. This is an area where you could add some debug prints inside drivers/net/phy/atheros.c and see if if qca,clk-out-frequency is being parsed correctly to configure a 125MHz clock output. This is the method I used on mx6cuboxi last week and it works. - Other way to configure the AR803x is via board code. Please try to copy the ar8031_phy_fixup() and board_phy_config() from board/freescale/mx6sabresd/mx6sabresd.c into your board file. (I plan to remove this board PHY code in mx6sabresd after 2020.07 and use "qca,clk-out-frequency" to do the job).
Re: [PATCH v3 1/2] riscv: Do not return error if reserved node already exists
On Thu, Jun 25, 2020 at 5:56 AM Atish Patra wrote: > > Not all errors are fatal. If a reserved memory node already exists in the > destination device tree, we can continue to boot without failing. > > Signed-off-by: Atish Patra > --- > arch/riscv/lib/fdt_fixup.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > Reviewed-by: Bin Meng
Re: [PATCH v3 2/4] arm: Remove d2net_v2 board
On Fri, Jun 19, 2020 at 08:25:59PM -0400, Tom Rini wrote: > On Sat, Jun 20, 2020 at 02:24:47AM +0200, Simon Guinot wrote: > > On Thu, Jun 18, 2020 at 06:25:06PM -0400, Tom Rini wrote: > > > On Fri, Jun 19, 2020 at 12:02:17AM +0200, Simon Guinot wrote: > > > > On Thu, Jun 18, 2020 at 11:15:14PM +0530, Jagan Teki wrote: > > > > Hi Jagan, > > > > > > > > > This board has not been converted to CONFIG_DM by the deadline. > > > > > > > > Is that possible to negociate a new deadline ? > > > > > > Well, when will you be able to spend some time bringing the platform up > > > to current standards? Doing a quick build for net2big_v2 I see: > > > +(net2big_v2) = WARNING == > > > +(net2big_v2) This board does not use CONFIG_DM. CONFIG_DM will be > > > +(net2big_v2) compulsory starting with the v2020.01 release. > > > +(net2big_v2) Failure to update may result in board removal. > > > +(net2big_v2) See doc/driver-model/migration.rst for more info. > > > +(net2big_v2) > > > +(net2big_v2) This board does not use CONFIG_DM_USB. Please update > > > +(net2big_v2) the board to use CONFIG_DM_USB before the v2019.07 release. > > > +(net2big_v2) Failure to update by the deadline may result in board > > > removal. > > > +(net2big_v2) This board does use CONFIG_MVSATA_IDE which is not > > > +(net2big_v2) ported to driver-model (DM) yet. Please update the storage > > > +(net2big_v2) controller driver to use CONFIG_AHCI before the v2019.07 > > > +(net2big_v2) release. > > > +(net2big_v2) This board does not use CONFIG_DM_SPI_FLASH. Please update > > > +(net2big_v2) the board to use CONFIG_SPI_FLASH before the v2019.07 > > > release. > > > +(net2big_v2) This board does not use CONFIG_DM_ETH (Driver Model > > > +(net2big_v2) for Ethernet drivers). Please update the board to use > > > +(net2big_v2) CONFIG_DM_ETH before the v2020.07 release. Failure to > > > +(net2big_v2) update by the deadline may result in board removal. > > > > > > So there's a lot of stuff that needs updating. Conversion to CONFIG_DM > > > is what you'll need to then convert SPI, ETH and USB to use DM and the > > > IDE driver also needs attention and conversion. Thanks! > > > > Hi Tom, > > > > I am working on it. But so far it is not going very well and the whole > > thing is turning into a debug session. > > > > But I'll do my best and whatever the result will be, I'll send you an > > update by the end of the next week. > > > > Is this acceptable to you ? Hi Tom, I just sent a patch series converting the LaCie boards to use DM drivers. I apologize for missing all this DM deadlines. Simon signature.asc Description: PGP signature
Re: U-Boot atheros PHY support and cubox ethernet
Hi Fabio, On 24.06.20 23:35, Fabio Estevam wrote: > Hi Soeren, > > On Wed, Jun 24, 2020 at 5:45 PM Sören Moch wrote: > >> Still no luck: > > mx6cuboxi has an AR8035 too and it is working fine in U-Boot mainline. > > I am not sure why tbs2910 is failing. Could you try to bisect? > Unfortunately I have no access to my usual development board (and will not have until the v2020.07 release). I only can use an old board without working USB-OTG, limited to eMMC boot. So I tried to avoid bisecting, because a bad commit could completely brick this board. Is there a reliable way to start a new u-boot directly from a running u-boot? Soeren
[PATCH 3/4] arm: kirkwood: enable DM_USB for LaCie board
This patch enables DM_USB and USB_STORAGE for the following Kirkwood-based LaCie boards: - d2 Network v2 - Internet Space v2 - 2Big Network v2 - Network Space v2 - Network Space Lite v2 - Network Space Max v2 Signed-off-by: Simon Guinot --- configs/d2net_v2_defconfig | 2 ++ configs/inetspace_v2_defconfig | 2 ++ configs/net2big_v2_defconfig | 2 ++ configs/netspace_lite_v2_defconfig | 2 ++ configs/netspace_max_v2_defconfig | 2 ++ configs/netspace_v2_defconfig | 2 ++ 6 files changed, 12 insertions(+) diff --git a/configs/d2net_v2_defconfig b/configs/d2net_v2_defconfig index 5a3a1f60e308..33f48e0dd94c 100644 --- a/configs/d2net_v2_defconfig +++ b/configs/d2net_v2_defconfig @@ -52,4 +52,6 @@ CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_EHCI_HCD=y +CONFIG_USB_STORAGE=y diff --git a/configs/inetspace_v2_defconfig b/configs/inetspace_v2_defconfig index 6cd4348a3c1d..ca444d0aafa3 100644 --- a/configs/inetspace_v2_defconfig +++ b/configs/inetspace_v2_defconfig @@ -52,4 +52,6 @@ CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_EHCI_HCD=y +CONFIG_USB_STORAGE=y diff --git a/configs/net2big_v2_defconfig b/configs/net2big_v2_defconfig index e7b7be7ed506..4d0e50b3e0a5 100644 --- a/configs/net2big_v2_defconfig +++ b/configs/net2big_v2_defconfig @@ -52,4 +52,6 @@ CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_EHCI_HCD=y +CONFIG_USB_STORAGE=y diff --git a/configs/netspace_lite_v2_defconfig b/configs/netspace_lite_v2_defconfig index 9e3768ef4efd..26ca464e0b48 100644 --- a/configs/netspace_lite_v2_defconfig +++ b/configs/netspace_lite_v2_defconfig @@ -52,5 +52,7 @@ CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_STORAGE=y +CONFIG_USB_STORAGE=y diff --git a/configs/netspace_max_v2_defconfig b/configs/netspace_max_v2_defconfig index b06321895b20..af2d9df6ff8a 100644 --- a/configs/netspace_max_v2_defconfig +++ b/configs/netspace_max_v2_defconfig @@ -52,5 +52,7 @@ CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_STORAGE=y +CONFIG_USB_STORAGE=y diff --git a/configs/netspace_v2_defconfig b/configs/netspace_v2_defconfig index fc09c6b22464..3585b7cf6318 100644 --- a/configs/netspace_v2_defconfig +++ b/configs/netspace_v2_defconfig @@ -52,4 +52,6 @@ CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_EHCI_HCD=y +CONFIG_USB_STORAGE=y -- 2.27.0
[PATCH 4/4] arm: kirkwood: enable DM_ETH for LaCie board
This patch enables DM_ETH for the following Kirkwood-based LaCie boards: - d2 Network v2 - Internet Space v2 - 2Big Network v2 - Network Space v2 - Network Space Lite v2 - Network Space Max v2 - Network Space Mini v2 Signed-off-by: Simon Guinot --- board/LaCie/net2big_v2/net2big_v2.c | 2 +- board/LaCie/netspace_v2/netspace_v2.c | 4 ++-- configs/d2net_v2_defconfig| 1 + configs/inetspace_v2_defconfig| 1 + configs/net2big_v2_defconfig | 1 + configs/netspace_lite_v2_defconfig| 1 + configs/netspace_max_v2_defconfig | 1 + configs/netspace_mini_v2_defconfig| 1 + configs/netspace_v2_defconfig | 1 + 9 files changed, 10 insertions(+), 3 deletions(-) diff --git a/board/LaCie/net2big_v2/net2big_v2.c b/board/LaCie/net2big_v2/net2big_v2.c index dbd8b5755da3..e94c9a6dce96 100644 --- a/board/LaCie/net2big_v2/net2big_v2.c +++ b/board/LaCie/net2big_v2/net2big_v2.c @@ -239,7 +239,7 @@ int misc_init_r(void) /* Configure and initialize PHY */ void reset_phy(void) { - mv_phy_88e1116_init("egiga0", 8); + mv_phy_88e1116_init("ethernet-controller@72000", 8); } #endif diff --git a/board/LaCie/netspace_v2/netspace_v2.c b/board/LaCie/netspace_v2/netspace_v2.c index 011cc563d19d..33246b201528 100644 --- a/board/LaCie/netspace_v2/netspace_v2.c +++ b/board/LaCie/netspace_v2/netspace_v2.c @@ -100,9 +100,9 @@ int misc_init_r(void) void reset_phy(void) { #if defined(CONFIG_NETSPACE_LITE_V2) || defined(CONFIG_NETSPACE_MINI_V2) - mv_phy_88e1318_init("egiga0", 0); + mv_phy_88e1318_init("ethernet-controller@72000", 0); #else - mv_phy_88e1116_init("egiga0", 8); + mv_phy_88e1116_init("ethernet-controller@72000", 8); #endif } #endif diff --git a/configs/d2net_v2_defconfig b/configs/d2net_v2_defconfig index 33f48e0dd94c..31a5d91af2b3 100644 --- a/configs/d2net_v2_defconfig +++ b/configs/d2net_v2_defconfig @@ -45,6 +45,7 @@ CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_DM_ETH=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y diff --git a/configs/inetspace_v2_defconfig b/configs/inetspace_v2_defconfig index ca444d0aafa3..b5973977a5b8 100644 --- a/configs/inetspace_v2_defconfig +++ b/configs/inetspace_v2_defconfig @@ -45,6 +45,7 @@ CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_DM_ETH=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y diff --git a/configs/net2big_v2_defconfig b/configs/net2big_v2_defconfig index 4d0e50b3e0a5..bba85030492a 100644 --- a/configs/net2big_v2_defconfig +++ b/configs/net2big_v2_defconfig @@ -45,6 +45,7 @@ CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_DM_ETH=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y diff --git a/configs/netspace_lite_v2_defconfig b/configs/netspace_lite_v2_defconfig index 26ca464e0b48..bfa93dbd1c27 100644 --- a/configs/netspace_lite_v2_defconfig +++ b/configs/netspace_lite_v2_defconfig @@ -45,6 +45,7 @@ CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_DM_ETH=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y diff --git a/configs/netspace_max_v2_defconfig b/configs/netspace_max_v2_defconfig index af2d9df6ff8a..d0f750369a3a 100644 --- a/configs/netspace_max_v2_defconfig +++ b/configs/netspace_max_v2_defconfig @@ -45,6 +45,7 @@ CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_DM_ETH=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y diff --git a/configs/netspace_mini_v2_defconfig b/configs/netspace_mini_v2_defconfig index 7e013b48d1a1..6cfaccf51dbd 100644 --- a/configs/netspace_mini_v2_defconfig +++ b/configs/netspace_mini_v2_defconfig @@ -43,6 +43,7 @@ CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_DM_ETH=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y diff --git a/configs/netspace_v2_defconfig b/configs/netspace_v2_defconfig index 3585b7cf6318..1bd148f9b511 100644 --- a/configs/netspace_v2_defconfig +++ b/configs/netspace_v2_defconfig @@ -45,6 +45,7 @@ CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_DM_ETH=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y -- 2.27.0
[PATCH 2/4] arm: kirkwood: switch LaCie boards to sata_mv driver
This patch switches the SATA driver from mvsata_ide to sata_mv for the following Kirkwood-based LaCie boards: - d2 Network v2 - Internet Space v2 - 2Big Network v2 - Network Space v2 - Network Space Lite v2 - Network Space Max v2 - Network Space Mini v2 Signed-off-by: Simon Guinot --- configs/d2net_v2_defconfig | 6 +++--- configs/inetspace_v2_defconfig | 6 +++--- configs/net2big_v2_defconfig | 6 +++--- configs/netspace_lite_v2_defconfig | 5 +++-- configs/netspace_max_v2_defconfig | 5 +++-- configs/netspace_mini_v2_defconfig | 5 +++-- configs/netspace_v2_defconfig | 6 +++--- include/configs/lacie_kw.h | 19 +-- 8 files changed, 30 insertions(+), 28 deletions(-) diff --git a/configs/d2net_v2_defconfig b/configs/d2net_v2_defconfig index 0d240daf01a1..5a3a1f60e308 100644 --- a/configs/d2net_v2_defconfig +++ b/configs/d2net_v2_defconfig @@ -21,8 +21,8 @@ CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="d2v2> " CONFIG_CMD_EEPROM=y -CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y +CONFIG_CMD_SATA=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y @@ -40,7 +40,8 @@ CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 CONFIG_DM=y -CONFIG_MVSATA_IDE=y +CONFIG_SATA_MV=y +CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y @@ -52,4 +53,3 @@ CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y -CONFIG_USB_STORAGE=y diff --git a/configs/inetspace_v2_defconfig b/configs/inetspace_v2_defconfig index 2ef916fa85ba..6cd4348a3c1d 100644 --- a/configs/inetspace_v2_defconfig +++ b/configs/inetspace_v2_defconfig @@ -21,8 +21,8 @@ CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="ns2> " CONFIG_CMD_EEPROM=y -CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y +CONFIG_CMD_SATA=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y @@ -40,7 +40,8 @@ CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 CONFIG_DM=y -CONFIG_MVSATA_IDE=y +CONFIG_SATA_MV=y +CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y @@ -52,4 +53,3 @@ CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y -CONFIG_USB_STORAGE=y diff --git a/configs/net2big_v2_defconfig b/configs/net2big_v2_defconfig index 9c1ed539b2a0..e7b7be7ed506 100644 --- a/configs/net2big_v2_defconfig +++ b/configs/net2big_v2_defconfig @@ -21,8 +21,8 @@ CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="2big2> " CONFIG_CMD_EEPROM=y -CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y +CONFIG_CMD_SATA=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y @@ -40,7 +40,8 @@ CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 CONFIG_DM=y -CONFIG_MVSATA_IDE=y +CONFIG_SATA_MV=y +CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y @@ -52,4 +53,3 @@ CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y -CONFIG_USB_STORAGE=y diff --git a/configs/netspace_lite_v2_defconfig b/configs/netspace_lite_v2_defconfig index 180d1402a188..9e3768ef4efd 100644 --- a/configs/netspace_lite_v2_defconfig +++ b/configs/netspace_lite_v2_defconfig @@ -21,8 +21,8 @@ CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="ns2> " CONFIG_CMD_EEPROM=y -CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y +CONFIG_CMD_SATA=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y @@ -40,7 +40,8 @@ CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 CONFIG_DM=y -CONFIG_MVSATA_IDE=y +CONFIG_SATA_MV=y +CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y diff --git a/configs/netspace_max_v2_defconfig b/configs/netspace_max_v2_defconfig index ed1a4e2d3653..b06321895b20 100644 --- a/configs/netspace_max_v2_defconfig +++ b/configs/netspace_max_v2_defconfig @@ -21,8 +21,8 @@ CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="ns2> " CONFIG_CMD_EEPROM=y -CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y +CONFIG_CMD_SATA=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y @@ -40,7 +40,8 @@ CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 CONFIG_DM=y -CONFIG_MVSATA_IDE=y +CONFIG_SATA_MV=y +CONFIG_BLK=y # CONFIG_MMC is not set CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y diff --git a/configs/netspace_mini_v2_defconfig b/configs/netspace_mini_v2_defconfig index 884bb63f0b90..7e013b48d1a1 100644 --- a/configs/netspace_mini_v2_defconfig +++ b/configs/netspace_mini_v2_defconfig @@ -21,8 +21,8 @@ CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="ns2> " CONFIG_CMD_EEPROM=y -CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y +CONFIG_CMD_SATA=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y CONFIG_CMD_MII=y @@ -38,7 +38,8 @@ CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 CONFI
[PATCH 0/4] Convert LaCie boards to use DM drivers
This patch converts the following LaCie boards (Marvell Kirkwood-based) to use DM drivers: - d2 Network v2 - Internet Space v2 - 2Big Network v2 - Network Space v2 - Network Space Lite v2 - Network Space Max v2 - Network Space Mini v2 Simon Guinot (4): arm: kirkwood: convert LaCie boards to DM_SPI_FLASH arm: kirkwood: switch LaCie boards to sata_mv driver arm: kirkwood: enable DM_USB for LaCie board arm: kirkwood: enable DM_ETH for LaCie board arch/arm/dts/kirkwood-netxbig.dtsi| 4 arch/arm/dts/kirkwood-ns2-common.dtsi | 4 board/LaCie/net2big_v2/net2big_v2.c | 2 +- board/LaCie/netspace_v2/netspace_v2.c | 4 ++-- configs/d2net_v2_defconfig| 13 + configs/inetspace_v2_defconfig| 13 + configs/net2big_v2_defconfig | 13 + configs/netspace_lite_v2_defconfig| 14 ++ configs/netspace_max_v2_defconfig | 14 ++ configs/netspace_mini_v2_defconfig| 12 configs/netspace_v2_defconfig | 13 + include/configs/lacie_kw.h| 19 +-- 12 files changed, 84 insertions(+), 41 deletions(-) -- 2.27.0
[PATCH 1/4] arm: kirkwood: convert LaCie boards to DM_SPI_FLASH
This patch converts the following Kirkwood-based LaCie boards to DM, DM_SPI and DM_SPI_FLASH: - d2 Network v2 - Internet Space v2 - 2Big Network v2 - Network Space v2 - Network Space Lite v2 - Network Space Max v2 - Network Space Mini v2 Signed-off-by: Simon Guinot --- arch/arm/dts/kirkwood-netxbig.dtsi| 4 arch/arm/dts/kirkwood-ns2-common.dtsi | 4 configs/d2net_v2_defconfig| 6 -- configs/inetspace_v2_defconfig| 6 -- configs/net2big_v2_defconfig | 6 -- configs/netspace_lite_v2_defconfig| 6 -- configs/netspace_max_v2_defconfig | 6 -- configs/netspace_mini_v2_defconfig| 6 -- configs/netspace_v2_defconfig | 6 -- 9 files changed, 36 insertions(+), 14 deletions(-) diff --git a/arch/arm/dts/kirkwood-netxbig.dtsi b/arch/arm/dts/kirkwood-netxbig.dtsi index b5737026e244..439eda736ca9 100644 --- a/arch/arm/dts/kirkwood-netxbig.dtsi +++ b/arch/arm/dts/kirkwood-netxbig.dtsi @@ -16,6 +16,10 @@ #include "kirkwood-6281.dtsi" / { + aliases { + spi0 = &spi0; + }; + chosen { bootargs = "console=ttyS0,115200n8"; stdout-path = &uart0; diff --git a/arch/arm/dts/kirkwood-ns2-common.dtsi b/arch/arm/dts/kirkwood-ns2-common.dtsi index 51530ea86622..4bccab45fba3 100644 --- a/arch/arm/dts/kirkwood-ns2-common.dtsi +++ b/arch/arm/dts/kirkwood-ns2-common.dtsi @@ -3,6 +3,10 @@ #include "kirkwood-6281.dtsi" / { + aliases { + spi0 = &spi0; + }; + chosen { bootargs = "console=ttyS0,115200n8"; stdout-path = &uart0; diff --git a/configs/d2net_v2_defconfig b/configs/d2net_v2_defconfig index fe3c6c47620d..0d240daf01a1 100644 --- a/configs/d2net_v2_defconfig +++ b/configs/d2net_v2_defconfig @@ -9,6 +9,7 @@ CONFIG_ENV_OFFSET=0x7 CONFIG_ENV_SECT_SIZE=0x1 CONFIG_NR_DRAM_BANKS=2 CONFIG_IDENT_STRING=" D2 v2" +# CONFIG_SYS_MALLOC_F is not set CONFIG_SYS_EXTRA_OPTIONS="D2NET_V2" CONFIG_BOOTDELAY=3 CONFIG_USE_BOOTARGS=y @@ -22,7 +23,6 @@ CONFIG_SYS_PROMPT="d2v2> " CONFIG_CMD_EEPROM=y CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y -CONFIG_CMD_SF=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y @@ -39,14 +39,16 @@ CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 +CONFIG_DM=y CONFIG_MVSATA_IDE=y # CONFIG_MMC is not set -CONFIG_SPI_FLASH=y +CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y CONFIG_SPI=y +CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/inetspace_v2_defconfig b/configs/inetspace_v2_defconfig index 6144eb5fad45..2ef916fa85ba 100644 --- a/configs/inetspace_v2_defconfig +++ b/configs/inetspace_v2_defconfig @@ -9,6 +9,7 @@ CONFIG_ENV_OFFSET=0x7 CONFIG_ENV_SECT_SIZE=0x1 CONFIG_NR_DRAM_BANKS=2 CONFIG_IDENT_STRING=" IS v2" +# CONFIG_SYS_MALLOC_F is not set CONFIG_SYS_EXTRA_OPTIONS="INETSPACE_V2" CONFIG_BOOTDELAY=3 CONFIG_USE_BOOTARGS=y @@ -22,7 +23,6 @@ CONFIG_SYS_PROMPT="ns2> " CONFIG_CMD_EEPROM=y CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y -CONFIG_CMD_SF=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y @@ -39,14 +39,16 @@ CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 +CONFIG_DM=y CONFIG_MVSATA_IDE=y # CONFIG_MMC is not set -CONFIG_SPI_FLASH=y +CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y CONFIG_SPI=y +CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/net2big_v2_defconfig b/configs/net2big_v2_defconfig index 1389d3090096..9c1ed539b2a0 100644 --- a/configs/net2big_v2_defconfig +++ b/configs/net2big_v2_defconfig @@ -9,6 +9,7 @@ CONFIG_ENV_OFFSET=0x7 CONFIG_ENV_SECT_SIZE=0x1 CONFIG_NR_DRAM_BANKS=2 CONFIG_IDENT_STRING=" 2Big v2" +# CONFIG_SYS_MALLOC_F is not set CONFIG_SYS_EXTRA_OPTIONS="NET2BIG_V2" CONFIG_BOOTDELAY=3 CONFIG_USE_BOOTARGS=y @@ -22,7 +23,6 @@ CONFIG_SYS_PROMPT="2big2> " CONFIG_CMD_EEPROM=y CONFIG_CMD_IDE=y CONFIG_CMD_I2C=y -CONFIG_CMD_SF=y CONFIG_CMD_USB=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_DHCP=y @@ -39,14 +39,16 @@ CONFIG_ENV_IS_IN_SPI_FLASH=y CONFIG_USE_ENV_SPI_MAX_HZ=y CONFIG_ENV_SPI_MAX_HZ=2000 CONFIG_ENV_ADDR=0x7 +CONFIG_DM=y CONFIG_MVSATA_IDE=y # CONFIG_MMC is not set -CONFIG_SPI_FLASH=y +CONFIG_DM_SPI_FLASH=y CONFIG_SPI_FLASH_MACRONIX=y CONFIG_MVGBE=y CONFIG_MII=y CONFIG_SYS_NS16550=y CONFIG_SPI=y +CONFIG_DM_SPI=y CONFIG_KIRKWOOD_SPI=y CONFIG_USB=y CONFIG_USB_EHCI_HCD=y diff --git a/configs/netspace_lite_v2_defconfig b/configs/netspace_lite_v2_defconfig index c744d2c58efc..180d1402a188 100644 --- a/configs/netspace_lite_v2_defconfig +++ b/configs/netspace_lite_v2_defconfig @@ -9,6 +9,7 @@ CONFIG_ENV_OFFSET=0x7 CONFIG_ENV_SECT_SIZE=0x1000
[PATCH v3 0/2] Assorted fixes related to reserved memory
This series has few small assorted fixes related to reserved memory support in RISC-V. The series is rebased on top of the following series http://patchwork.ozlabs.org/project/uboot/patch/1591767391-2669-2-git-send-email-bmeng...@gmail.com/ Changes form v2->v3: 1. Dropped bootefi patch as it is already merged. 2. Fixed minor typos. Changes from v1->v2: 1. Rebased on top of the Bin's series. Dropped the fix generic fdtdec code. 2. Added bootefi fix. Atish Patra (2): riscv: Do not return error if reserved node already exists riscv: Use optimized version of fdtdec_get_addr_size_no_parent arch/riscv/lib/fdt_fixup.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.24.0
[PATCH v3 2/2] riscv: Use optimized version of fdtdec_get_addr_size_no_parent
fdtdec_get_addr_size_no_parent is not an optimized version if parent node is already available with the caller. Use fdtdec_get_addr_size_auto_parent to read the "reg" property Signed-off-by: Atish Patra Reviewed-by: Bin Meng --- arch/riscv/lib/fdt_fixup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c index 05ca41b49dda..fab93873d5c7 100644 --- a/arch/riscv/lib/fdt_fixup.c +++ b/arch/riscv/lib/fdt_fixup.c @@ -44,9 +44,9 @@ int riscv_fdt_copy_resv_mem_node(const void *src, void *dst) fdt_for_each_subnode(node, src, offset) { name = fdt_get_name(src, node, NULL); - addr = fdtdec_get_addr_size_auto_noparent(src, node, - "reg", 0, &size, - false); + addr = fdtdec_get_addr_size_auto_parent(src, offset, node, + "reg", 0, &size, + false); if (addr == FDT_ADDR_T_NONE) { debug("failed to read address/size for %s\n", name); continue; -- 2.24.0
[PATCH v3 1/2] riscv: Do not return error if reserved node already exists
Not all errors are fatal. If a reserved memory node already exists in the destination device tree, we can continue to boot without failing. Signed-off-by: Atish Patra --- arch/riscv/lib/fdt_fixup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c index 6db48ad04a56..05ca41b49dda 100644 --- a/arch/riscv/lib/fdt_fixup.c +++ b/arch/riscv/lib/fdt_fixup.c @@ -62,7 +62,7 @@ int riscv_fdt_copy_resv_mem_node(const void *src, void *dst) pmp_mem.end = addr + size - 1; err = fdtdec_add_reserved_memory(dst, basename, &pmp_mem, &phandle); - if (err < 0) { + if (err < 0 && err != -FDT_ERR_EXISTS) { printf("failed to add reserved memory: %d\n", err); return err; } -- 2.24.0
Re: U-Boot atheros PHY support and cubox ethernet
Hi Soeren, On Wed, Jun 24, 2020 at 5:45 PM Sören Moch wrote: > Still no luck: mx6cuboxi has an AR8035 too and it is working fine in U-Boot mainline. I am not sure why tbs2910 is failing. Could you try to bisect?
Re: U-Boot atheros PHY support and cubox ethernet
Hi Fabio, On 24.06.20 22:29, Fabio Estevam wrote: > Hi Soeren, > > On Wed, Jun 24, 2020 at 5:13 PM Soeren Moch wrote: > >> Schematics are at >> https://www.tbsdtv.com/download/document/tbs2910/TBS2910-Matrix-ARM-mini-PC-SCH_rev2.1.pdf > Here is another patch for you to try: > https://pastebin.com/raw/Dkipgq1n Still no luck: U-Boot 2020.07-rc5-00039-g4ff63383e3-dirty (Jun 24 2020 - 22:36:43 +0200) CPU: Freescale i.MX6Q rev1.2 at 792MHz CPU: Commercial temperature grade (0C to 95C) at 47C Reset cause: POR Model: TBS2910 Matrix ARM mini PC DRAM: 2 GiB MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2 Loading Environment from MMC... OK No panel detected: default to HDMI Display: HDMI (1024x768) In: serial Out: vga Err: vga Net: eth0: ethernet@2188000 PCI: PCI: pcie phy link never came up No such bus starting USB... Bus usb@2184000: usb dr_mode not found Bus usb@2184200: USB EHCI 1.00 scanning bus usb@2184000 for devices... 1 USB Device(s) found scanning bus usb@2184200 for devices... 4 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 Matrix U-Boot> dhcp BOOTP broadcast 1 BOOTP broadcast 2 BOOTP broadcast 3 BOOTP broadcast 4 BOOTP broadcast 5 BOOTP broadcast 6 BOOTP broadcast 7 BOOTP broadcast 8 BOOTP broadcast 9 BOOTP broadcast 10 BOOTP broadcast 11 BOOTP broadcast 12 BOOTP broadcast 13 BOOTP broadcast 14 BOOTP broadcast 15 BOOTP broadcast 16 BOOTP broadcast 17 Retry time exceeded; starting again Matrix U-Boot> mdio list FEC0: 4 - AR8035 <--> ethernet@2188000 Matrix U-Boot>
Re: [PATCH v2 1/1] travis-ci: Fix "ResourceWarning: unclosed file"
On Wed, Jun 24, 2020 at 02:30:24PM -0600, Stephen Warren wrote: > On 12/30/19 9:41 AM, Stephen Warren wrote: > > On 12/30/19 4:49 AM, Cristian Ciocaltea wrote: > >> This patch gets rid of the warning messages like: > >> > >> uboot-test-hooks/py/travis-ci/travis_tftp.py:43: ResourceWarning: > >> unclosed file <_io.BufferedReader name='.bm-work/qemu_arm/u-boot.bin'> > >> > >> Signed-off-by: Cristian Ciocaltea > >> --- > >> Changes in v2: > >> * The warning line number in the comment relies on Heinrich Schuchardt's > >> work 'travis-ci: provide env__efi_fit_tftp_file', but my initial patch > >> was based on the master version. Even though it is still applicable, > >> to avoid any confusion, I rebased it on Heinrich's latest patch (v2): > >> https://lists.denx.de/pipermail/u-boot/2019-December/395029.html > > > > There's no need to rebase the patch for that kind of thing; the warning > > is only a reference/example anyway, and the next time someone edits this > > file after you, the line number will change again, and we can't go back > > and edit this commit description to patch that up. > > > >> diff --git a/py/travis-ci/travis_tftp.py b/py/travis-ci/travis_tftp.py > > > >> + > >> + with open(file_full, 'rb') as fd: > >> + ret["crc32"] = hex(binascii.crc32(fd.read()) & 0x)[2:] > > > > Nit: "f" for "file" rather than "fd" for "file descriptor" (usually an > > integer) would have been a better variable name. No need to resend to > > change this though. > > > > Reviewed-by: Stephen Warren > > Oh, somehow I failed to realize that I needed to apply this. It's now > applied. Great, thanks!
Re: [PATCH v2 02/10] test: pinmux: Add test for pin muxing
On 6/24/20 9:45 AM, Simon Glass wrote: > Hi Sean, > > On Wed, 24 Jun 2020 at 02:01, Sean Anderson wrote: >> >> On 6/17/20 10:07 AM, Simon Glass wrote: >>> Hi Sean, >>> >>> On Tue, 16 Jun 2020 at 21:18, Sean Anderson wrote: On 6/16/20 11:11 PM, Simon Glass wrote: > Hi Sean, > > On Sun, 7 Jun 2020 at 19:27, Sean Anderson wrote: >> >> This extends the pinctrl-sandbox driver to support pin muxing, and adds a >> test for that behaviour. The test is done in C and not python (like the >> existing tests for the pinctrl uclass) because it needs to call >> pinctrl_select_state. Another option could be to add a command that >> invokes pinctrl_select_state and then test everything in >> test/py/tests/test_pinmux.py. >> >> The pinctrl-sandbox driver now mimics the way that many pinmux devices >> work. There are two groups of pins which are muxed together, as well as >> four pins which are muxed individually. I have tried to test all normal >> paths. However, very few error cases are explicitly checked for. >> >> Signed-off-by: Sean Anderson >> --- >> >> Changes in v2: >> - New >> >> arch/sandbox/dts/test.dts | 45 +++-- >> drivers/pinctrl/pinctrl-sandbox.c | 155 +++--- >> test/dm/Makefile | 3 + >> test/py/tests/test_pinmux.py | 36 +++ >> 4 files changed, 178 insertions(+), 61 deletions(-) >> > > [..] > > >> diff --git a/test/dm/Makefile b/test/dm/Makefile >> index 0d1c66fa1e..9e273ee02d 100644 >> --- a/test/dm/Makefile >> +++ b/test/dm/Makefile >> @@ -76,4 +76,7 @@ obj-$(CONFIG_DM_RNG) += rng.o >> obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o >> obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o >> obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o >> +ifneq ($(CONFIG_PINMUX),) >> +obj-$(CONFIG_PINCONF) += pinmux.o > > I don't see this file in your patch. Whoops, will add it next revision. > >> +endif >> endif >> diff --git a/test/py/tests/test_pinmux.py b/test/py/tests/test_pinmux.py >> index 4e6df992a4..0cbbae000c 100644 >> --- a/test/py/tests/test_pinmux.py >> +++ b/test/py/tests/test_pinmux.py >> @@ -28,15 +28,15 @@ def test_pinmux_status_all(u_boot_console): > > Feel free to convert this to C also if you like. It is faster, > although perhaps not much faster since it only runs a few commands? Ok, I can have a look. Should C be preferred for new tests? >>> >>> +Stephen Warren >>> >>> For sandbox tests, yes. If there is a lot of interaction, Python is >>> extremely slow. >>> >>> But with Python we can run a test on real hardware without compiling >>> the test into U-Boot. So there are benefits on both sides. >> >> Ok, I looked into it, and the python test uses the >> assert 'somestring' in output >> idiom a lot. From what I can tell, there's not an easy way to replicate >> this behavior on the C side of things. Adding a function to do this >> would probably call for its own patch. I could also use the existing >> functionality to test for lines, but I think that would be much more >> brittle when compared to the python version. > > Well you could add assert_nextline_contains() for example? Yes, but I would also have to skip a specific number of lines, e.g. console_record_reset(); run_command("pinmux", 0); ut_assert_nextline_contains(""); ut_assert_nextline_contains(""); ut_assert_nextline_contains("Usage:"); console_record_reset(); /* ... */ That's ok, but still fairly brittle in how it tests the output. Oh well, perhaps I'll add something like that next revision... --Sean
Re: [PATCH v2 1/1] travis-ci: Fix "ResourceWarning: unclosed file"
On 12/30/19 9:41 AM, Stephen Warren wrote: > On 12/30/19 4:49 AM, Cristian Ciocaltea wrote: >> This patch gets rid of the warning messages like: >> >> uboot-test-hooks/py/travis-ci/travis_tftp.py:43: ResourceWarning: >> unclosed file <_io.BufferedReader name='.bm-work/qemu_arm/u-boot.bin'> >> >> Signed-off-by: Cristian Ciocaltea >> --- >> Changes in v2: >> * The warning line number in the comment relies on Heinrich Schuchardt's >> work 'travis-ci: provide env__efi_fit_tftp_file', but my initial patch >> was based on the master version. Even though it is still applicable, >> to avoid any confusion, I rebased it on Heinrich's latest patch (v2): >> https://lists.denx.de/pipermail/u-boot/2019-December/395029.html > > There's no need to rebase the patch for that kind of thing; the warning > is only a reference/example anyway, and the next time someone edits this > file after you, the line number will change again, and we can't go back > and edit this commit description to patch that up. > >> diff --git a/py/travis-ci/travis_tftp.py b/py/travis-ci/travis_tftp.py > >> + >> + with open(file_full, 'rb') as fd: >> + ret["crc32"] = hex(binascii.crc32(fd.read()) & 0x)[2:] > > Nit: "f" for "file" rather than "fd" for "file descriptor" (usually an > integer) would have been a better variable name. No need to resend to > change this though. > > Reviewed-by: Stephen Warren Oh, somehow I failed to realize that I needed to apply this. It's now applied.
Re: U-Boot atheros PHY support and cubox ethernet
Hi Soeren, On Wed, Jun 24, 2020 at 5:13 PM Soeren Moch wrote: > Schematics are at > https://www.tbsdtv.com/download/document/tbs2910/TBS2910-Matrix-ARM-mini-PC-SCH_rev2.1.pdf Here is another patch for you to try: https://pastebin.com/raw/Dkipgq1n
Re: U-Boot atheros PHY support and cubox ethernet
Hi Fabio On 24.06.20 21:39, Fabio Estevam wrote: > Hi Soeren, > > On Wed, Jun 24, 2020 at 4:20 PM Soeren Moch wrote: > >> I tested current master (v2020.07-rc5 + imx fixes) on tbs2910 (imx6q + >> atheros PHY). >> Unfortunately ethernet is broken now, while it used to work well on >> u-boot version v2020.04. Ethernet support was copied from imx6q-sabresd, >> the recently for sabresd fixed phy-mode already is rgmii-id for tbs2910. >> >> Any ideas what could be wrong? > I just tested mainline U-Boot and Ethernet works fine on a imx6qp sabresd > board: > > U-Boot SPL 2020.07-rc5-00052-g922c6d5d00 (Jun 24 2020 - 16:21:27 -0300) > Trying to boot from MMC1 > > > U-Boot 2020.07-rc5-00052-g922c6d5d00 (Jun 24 2020 - 16:21:27 -0300) > > CPU: Freescale i.MX6QP rev1.0 996 MHz (running at 792 MHz) > CPU: Automotive temperature grade (-40C to 125C) at 30C > Reset cause: POR > Model: Freescale i.MX6 Quad Plus SABRE Smart Device Board > Board: MX6-SabreSD > I2C: ready > DRAM: 1 GiB > PMIC: PFUZE100 ID=0x10 > MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 3 > Loading Environment from MMC... OK > No panel detected: default to Hannstar-XGA > Display: Hannstar-XGA (1024x768) > In:serial > Out: serial > Err: serial > Net: eth0: ethernet@2188000 > Hit any key to stop autoboot: 0 > => dhcp zImage > BOOTP broadcast 1 > DHCP client bound to address 192.168.0.24 (50 ms) > Using ethernet@2188000 device > TFTP from server 192.168.0.12; our IP address is 192.168.0.24 > Filename 'zImage'. > Load address: 0x1200 > Loading: # > # > # > # > # > # > # > # > # > # > 1.3 MiB/s > done > Bytes transferred = 9468928 (907c00 hex) > => mdio list > FEC0: > 1 - AR8031/AR8033 <--> ethernet@2188000 > => > > What is the exact failure you see? Is the Ethernet PHY found at the > correct address and probed? From what I see nothing is obviously wrong, just no ethernet connection: U-Boot 2020.07-rc5-00039-g4ff63383e3-dirty (Jun 24 2020 - 21:48:31 +0200) CPU: Freescale i.MX6Q rev1.2 at 792MHz CPU: Commercial temperature grade (0C to 95C) at 42C Reset cause: POR Model: TBS2910 Matrix ARM mini PC DRAM: 2 GiB MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2 Loading Environment from MMC... OK No panel detected: default to HDMI Display: HDMI (1024x768) In: serial Out: vga Err: vga Net: eth0: ethernet@2188000 PCI: PCI: pcie phy link never came up No such bus starting USB... Bus usb@2184000: usb dr_mode not found Bus usb@2184200: USB EHCI 1.00 scanning bus usb@2184000 for devices... 1 USB Device(s) found scanning bus usb@2184200 for devices... 4 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 Matrix U-Boot> dhcp BOOTP broadcast 1 BOOTP broadcast 2 BOOTP broadcast 3 BOOTP broadcast 4
Re: [PATCH 1/1] gitlab: show skipped Python tests
Hi Tom, On Wed, 24 Jun 2020 at 09:53, Tom Rini wrote: > > On Wed, Jun 24, 2020 at 09:17:51AM -0600, Simon Glass wrote: > > Hi Heinrich, > > > > On Wed, 24 Jun 2020 at 07:56, Heinrich Schuchardt > > wrote: > > > > > > On 24.06.20 15:49, Simon Glass wrote: > > > > Hi, > > > > > > > > On Mon, 22 Jun 2020 at 12:46, Tom Rini wrote: > > > >> > > > >> On Mon, Jun 22, 2020 at 12:23:35PM -0600, Simon Glass wrote: > > > >>> Hi Heinrich, > > > >>> > > > >>> On Mon, 22 Jun 2020 at 10:40, Heinrich Schuchardt > > > >>> wrote: > > > > > > On 22.06.20 18:17, Simon Glass wrote: > > > > Hi Heinrich, > > > > > > > > On Mon, 22 Jun 2020 at 10:07, Heinrich Schuchardt > > > > wrote: > > > >> > > > >> Call pytest3 with argument -ra to display reason why Python tests > > > >> are > > > >> skipped. > > > >> > > > >> Signed-off-by: Heinrich Schuchardt > > > >> --- > > > >> .gitlab-ci.yml | 2 +- > > > >> 1 file changed, 1 insertion(+), 1 deletion(-) > > > >> > > > >> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml > > > >> index f2e491c117..f53098ea5f 100644 > > > >> --- a/.gitlab-ci.yml > > > >> +++ b/.gitlab-ci.yml > > > >> @@ -46,7 +46,7 @@ stages: > > > >> # "${var:+"-k $var"}" expands to "" if $var is empty, "-k > > > >> $var" if not > > > >> - export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH}; > > > >>export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci; > > > >> - ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID} > > > >> + ./test/py/test.py -ra --bd ${TEST_PY_BD} ${TEST_PY_ID} > > > >> ${TEST_PY_TEST_SPEC:+"-k ${TEST_PY_TEST_SPEC}"} > > > >> --build-dir "$UBOOT_TRAVIS_BUILD_DIR" > > > > > > > > Do you have a link showing the current output with this patch? > > > > > > Hello Simon, > > > > > > here is an example output: > > > > > > https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112385 > > > >>> > > > >>> That's what I was afraid of. The skip output is more than the normal > > > >>> output, and if we don't intend to fix it, I'd rather not have > > > >>> unactionable warnings in the output. > > > >>> > > > >>> Having said that, we need to enable SPI flash, FPGA and MMC > > > >>> environment tests by the look of it. > > > >> > > > >> On a different note, I think we should look at: > > > >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112376 > > > >> and: > > > >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112380 > > > >> > > > >> as it shows that the reason we probably skip the test_fs/test_mkdir.py > > > >> tests is that since board is literal, we don't match sandbox on > > > >> sandbox_flattree. That answers one outstanding question about why we > > > >> skip some tests and not others at least. > > > > > > > > Hmm yes. > > > > > > > > It is definitely good to have this output so we can figure out what > > > > should not be skipped. > > > > > > > > But outputting things which we know should be skipped just means we > > > > won't notice those that are not supposed to be skipped. How do we > > > > handle that? > > > > > > > > Regards, > > > > Simon > > > > > > > If you have a lines like: > > > > > > .config feature "cmd_fpga_loadbp" not enabled > > > board "qemu_arm64" not supported > > > > > > you know the test is skipped due to configuration. > > > > OK then can we avoid printing this useless information by default? > > It's not useless information. It's what I pointed to in another part of > the thread as to why we're skipping tests we didn't expect to skip. I thought these ones were intended to be skipped? I'm perhaps just confused about what is going on here. > > > > Other messages clearly tell you that something is not correctly set up: > > > > > > No env__efi_loader_grub_file binary specified in environment > > > got empty parameter set ['env__mmc_dev_config'] > > > > OK then this is what we should display. > > This one is actually one I dug in to a bit, and I don't like how pytest > handles. You can't add a custom parameter checker, AFAICT, you can only > have empty params be skip or xfail. > > I think we could condense the output a little bit as @pytest.mark things > get condensed, but pytest.skip in a test do not (as it counts line > number). That's what got me looking for a way to mark that a config > needs to exist, but that isn't supported. But we could condense some of > the network related stuff by having a single test / helper for network > configuration rather than duplicating it, and then mark network tests as > depending on it. That sounds good. But in general, my point is that we should avoid displaying a message when things are working as intended, only when some action has to be taken. When everything is right, there should not be any warnings or failures IMO. Regards, Simon
Re: U-Boot atheros PHY support and cubox ethernet
Hi Soeren, On Wed, Jun 24, 2020 at 4:20 PM Soeren Moch wrote: > I tested current master (v2020.07-rc5 + imx fixes) on tbs2910 (imx6q + > atheros PHY). > Unfortunately ethernet is broken now, while it used to work well on > u-boot version v2020.04. Ethernet support was copied from imx6q-sabresd, > the recently for sabresd fixed phy-mode already is rgmii-id for tbs2910. > > Any ideas what could be wrong? I just tested mainline U-Boot and Ethernet works fine on a imx6qp sabresd board: U-Boot SPL 2020.07-rc5-00052-g922c6d5d00 (Jun 24 2020 - 16:21:27 -0300) Trying to boot from MMC1 U-Boot 2020.07-rc5-00052-g922c6d5d00 (Jun 24 2020 - 16:21:27 -0300) CPU: Freescale i.MX6QP rev1.0 996 MHz (running at 792 MHz) CPU: Automotive temperature grade (-40C to 125C) at 30C Reset cause: POR Model: Freescale i.MX6 Quad Plus SABRE Smart Device Board Board: MX6-SabreSD I2C: ready DRAM: 1 GiB PMIC: PFUZE100 ID=0x10 MMC: FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 3 Loading Environment from MMC... OK No panel detected: default to Hannstar-XGA Display: Hannstar-XGA (1024x768) In:serial Out: serial Err: serial Net: eth0: ethernet@2188000 Hit any key to stop autoboot: 0 => dhcp zImage BOOTP broadcast 1 DHCP client bound to address 192.168.0.24 (50 ms) Using ethernet@2188000 device TFTP from server 192.168.0.12; our IP address is 192.168.0.24 Filename 'zImage'. Load address: 0x1200 Loading: # # # # # # # # # # 1.3 MiB/s done Bytes transferred = 9468928 (907c00 hex) => mdio list FEC0: 1 - AR8031/AR8033 <--> ethernet@2188000 => What is the exact failure you see? Is the Ethernet PHY found at the correct address and probed? On tbs2910 does the AR8031 generate a 125MHz clock to the i.MX6Q Ethernet? If so, does the change below help (I am assuming the PHY is located at address 1, if not, please adjust the @ and reg accordingly)? --- a/arch/arm/dts/imx6q-tbs2910.dts +++ b/arch/arm/dts/imx6q-tbs2910.dts @@ -108,6 +108,16 @@ phy-mode = "rgmii-id"; phy-reset-gpios = <&gpio1 25 GPIO_ACTIVE_LOW>; status = "okay"; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + phy: ethernet-phy@1 { + reg = <1>; + qca,clk-out-frequency = <12500>; + }; + }; }; In case you still have issues, please share the tbs2910 schematics with me offline so I can try to understand the failure.
Re: U-Boot atheros PHY support and cubox ethernet
On 20.06.20 04:14, Fabio Estevam wrote: > Hi Tom, > > On Thu, Jun 18, 2020 at 10:39 AM Tom Rini wrote: > >> It's a good question what else doesn't work. What has been actively >> verified at this point? > > After the fixes I sent yesterday, the few imx boards I have access at > the moment have Ethernet working well. > I tested current master (v2020.07-rc5 + imx fixes) on tbs2910 (imx6q + atheros PHY). Unfortunately ethernet is broken now, while it used to work well on u-boot version v2020.04. Ethernet support was copied from imx6q-sabresd, the recently for sabresd fixed phy-mode already is rgmii-id for tbs2910. Any ideas what could be wrong? Thanks, Soeren
Re: [PULL] please pull u-boot-mmc mmc-2020-6-24
On Wed, Jun 24, 2020 at 12:37:00PM +, Peng Fan wrote: > Hi Tom, > > Please pull mmc-2020-6-24 > > CI: https://travis-ci.org/github/MrVan/u-boot/builds/701528851 Applied to u-boot/master, thanks! -- Tom signature.asc Description: PGP signature
Re: [PATCH] [RFC] tools: fitmount: fuse mount fit images
On Wed, Jun 24, 2020 at 08:20:38AM +0530, selvamuthukumar v wrote: > On Tue, Jun 23, 2020 at 11:47 PM Tom Rini wrote: > > > > On Tue, Jun 23, 2020 at 06:01:38PM +0530, selvamuthukumar v wrote: > > > On Mon, Jun 15, 2020 at 11:15 PM Selva Muthukumar > > > wrote: > > > > > > > > Allow mounting of FIT images. If FIT images are used for firmware > > > > upgrade > > > > from linux, mouting can save space in comparison to using dumpimage. > > > > > > > > > > Any comments on this? Is there any other way to get FIT image > > > contents, without extracting it? > > > > Sorry for the delay. For your program, there's a few things such as > > missing license header and being able to opt-in as otherwise we add a > > new build dependency for everyone. > > > > For getting FIT image contents, the existing dumpimage tool handles > > this. > > > dumpimage extracts image contents into new files. Current firmware > upgrade process in our product is: > > 1. FIT image has kernel and rootfs. Get new FIT image in tmpfs. > 2. dumpimage to extract the FIT image in tmpfs. > 3. Write kernel and rootfs in partitions. > > many times step2 fails because there is not enough space in tmpfs. FIT > image and individual components need to be present in tmpfs. When we > mount the FIT image, it does not take extra space tmpfs. Ah, so that's your use-case. But in this case, couldn't you use a named pipe instead to stream from the image after step one? Or add a -q option to dumpimage (so it doesn't print anything) and use -o /dev/stdout and pipe that directly to whatever is writing to flash? -- Tom signature.asc Description: PGP signature
Re: [PATCH v2 3/9] env: correctly handle result in env_init
On Wed, Jun 24, 2020 at 11:19:50AM +, Patrick DELAUNAY wrote: > Hi Tom, > > > From: Tom Rini > > Sent: mardi 23 juin 2020 17:17 > > > > On Tue, Jun 23, 2020 at 01:13:55PM +, Patrick DELAUNAY wrote: > > > Hi Tom, > > > > > > > From: Tom Rini > > > > Sent: vendredi 19 juin 2020 20:05 > > > > > > > > On Fri, Jun 19, 2020 at 02:14:00PM +, Patrick DELAUNAY wrote: > > > > > Hi Tom and Marek, > > > > > > > > > > > From: Tom Rini > > > > > > Sent: jeudi 18 juin 2020 21:16 > > > > > > > > > > > > On Tue, Jun 16, 2020 at 09:40:42AM +0200, Patrick Delaunay wrote: > > > > > > > > > > > > > Don't return error with ret=-ENOENT when the optional ops > > > > > > > drv->init is absent but only if env_driver_lookup doesn't found > > > > > > > driver. > > > > > > > > > > > > > > This patch correct an issue for the code > > > > > > > if (!env_init()) > > > > > > > env_load() > > > > > > > When only ext4 is supported (CONFIG_ENV_IS_IN_EXT4), as the > > > > > > > backend env/ext4.c doesn't define an ops .init > > > > > > > > > > > > > > Signed-off-by: Patrick Delaunay > > > > > > > --- > > > > > > > > > > > > > > (no changes since v1) > > > > > > > > > > > > > > env/env.c | 5 - > > > > > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > > > > > > > > > diff --git a/env/env.c b/env/env.c index > > > > > > > dcc25c030b..819c88f729 > > > > > > > 100644 > > > > > > > --- a/env/env.c > > > > > > > +++ b/env/env.c > > > > > > > @@ -295,7 +295,10 @@ int env_init(void) > > > > > > > int prio; > > > > > > > > > > > > > > for (prio = 0; (drv = env_driver_lookup(ENVOP_INIT, prio)); > > prio++) { > > > > > > > - if (!drv->init || !(ret = drv->init())) > > > > > > > + ret = 0; > > > > > > > + if (drv->init) > > > > > > > + ret = drv->init(); > > > > > > > + if (!ret) > > > > > > > env_set_inited(drv->location); > > > > > > > > > > > > > > debug("%s: Environment %s init done (ret=%d)\n", > > __func__, > > > > > > > > > > > > I'm adding in Marek here because this reminds me of similar > > > > > > questions / concerns I had looking in to his series. At root, I > > > > > > think we're not being consistent in each of our env backing > > > > > > implementations about where flags such as ENV_VALID are set, and > > > > > > return > > > > values / checks of functions. > > > > > > > > > > > > Just outside of the start of the patch context here, we set ret > > > > > > to -ENOENT and just past this, if still -ENOENT we say ENV_VALID > > > > > > and point at the default environment. > > > > > > > > > > > > But, I don't follow the patch commit message here. If we don't > > > > > > have > > > > > > drv->init we call env_set_inited(drv->location) but we won't > > > > > > drv->have change > > > > > > ret to 0, which means that later on down the function we go back > > > > > > to default environment. > > > > > > > > > > The cause of the issue is because the init() ops is optional in > > > > > "struct > > > > env_driver". > > > > > > > > Right. > > > > > > > > > When this opt is absent, I assume that the initialization is not > > > > > mandatory but this inititialization need to be tagged in > > > > > gd->env_has_init with the call of > > > > > env_set_inited() function > > > > > > > > So when drv->init isn't set we are already calling env_set_inited(...). > > > > If that's not the case, what's going on? > > > > > > > > > And the ENV backend is FOUND (don't return -ENOENT) > > > > > > > > > > else the next call of env_has_inited(drv->location) always failed > > > > > : in > > > > > env_load() > > > > > > > > > > I see the error in EXT4 env backend,.all the other backend as a > > > > > env_init() function > > > > > > > > > > But some othe backend don't define the .init operation and have > > > > > the issue > > > > > > > > > > eeprom.c:235:U_BOOT_ENV_LOCATION(eeprom) = { > > > > > ext4.c:135:U_BOOT_ENV_LOCATION(ext4) = { > > > > > fat.c:128:U_BOOT_ENV_LOCATION(fat) = { > > > > > mmc.c:393:U_BOOT_ENV_LOCATION(mmc) = { > > > > > onenand.c:108:U_BOOT_ENV_LOCATION(onenand) = { > > > > > sata.c:117:U_BOOT_ENV_LOCATION(sata) = { > > > > > ubi.c:179:U_BOOT_ENV_LOCATION(ubi) = { > > > > > > > > > > The other don't have issue: > > > > > > > > > > flash.c:358:U_BOOT_ENV_LOCATION(flash) = { > > > > > flash.c:368: .init = env_flash_init, > > > > > nand.c:382:U_BOOT_ENV_LOCATION(nand) = { > > > > > nand.c:389: .init = env_nand_init, > > > > > nowhere.c:30:U_BOOT_ENV_LOCATION(nowhere) = { > > > > > nowhere.c:32: .init = env_nowhere_init, > > > > > nvram.c:117:U_BOOT_ENV_LOCATION(nvram) = { > > > > > nvram.c:122: .init = env_nvram_init, > > > > > remote.c:54:U_BOOT_ENV_LOCATION(remote) = { > > > > > remote.c:59: .init = env_remote_init, > > > > > sf.c:306:U_BOOT_ENV_LOCATION(sf) = { > > > > > sf.c:312: .init = env_sf_init, > > > > > > > > Right, there should be a problem showing up
Re: [PATCH U-BOOT v3 00/30] PLEASE TEST fs: btrfs: Re-implement btrfs support using code from btrfs-progs
I shall compile for different platforms with and without these patches to see how much these patches increase the size of the resulting U-Boot binary. Maybe it will show us that it is finally time to look into LTO for U-Boot.
[PATCH U-BOOT v3 28/30] fs: btrfs: Imeplement btrfs_list_subvols() using new infrastructure
From: Qu Wenruo Reimplement btrfs_list_subvols() to use new code. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/subvolume.c | 78 +--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c index 258c3dafef..6fc28d53e5 100644 --- a/fs/btrfs/subvolume.c +++ b/fs/btrfs/subvolume.c @@ -155,6 +155,72 @@ out: return ret; } +static int list_subvolums(struct btrfs_fs_info *fs_info) +{ + struct btrfs_root *tree_root = fs_info->tree_root; + struct btrfs_root *root; + struct btrfs_path path; + struct btrfs_key key; + char *result; + int ret = 0; + + result = malloc(PATH_MAX); + if (!result) + return -ENOMEM; + + ret = list_one_subvol(fs_info->fs_root, result); + if (ret < 0) + goto out; + root = fs_info->fs_root; + printf("ID %llu gen %llu path %.*s\n", + root->root_key.objectid, btrfs_root_generation(&root->root_item), + PATH_MAX, result); + + key.objectid = BTRFS_FIRST_FREE_OBJECTID; + key.type = BTRFS_ROOT_ITEM_KEY; + key.offset = 0; + btrfs_init_path(&path); + ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0); + if (ret < 0) + goto out; + while (1) { + if (path.slots[0] >= btrfs_header_nritems(path.nodes[0])) + goto next; + + btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]); + if (key.objectid > BTRFS_LAST_FREE_OBJECTID) + break; + if (key.objectid < BTRFS_FIRST_FREE_OBJECTID || + key.type != BTRFS_ROOT_ITEM_KEY) + goto next; + key.offset = (u64)-1; + root = btrfs_read_fs_root(fs_info, &key); + if (IS_ERR(root)) { + ret = PTR_ERR(root); + if (ret == -ENOENT) + goto next; + } + ret = list_one_subvol(root, result); + if (ret < 0) + goto out; + printf("ID %llu gen %llu path %.*s\n", + root->root_key.objectid, + btrfs_root_generation(&root->root_item), + PATH_MAX, result); +next: + ret = btrfs_next_item(tree_root, &path); + if (ret < 0) + goto out; + if (ret > 0) { + ret = 0; + break; + } + } +out: + free(result); + return ret; +} + static int get_subvol_name(u64 subvolid, char *name, int max_len) { struct btrfs_root_ref rref; @@ -268,10 +334,12 @@ static void list_subvols(u64 tree, char *nameptr, int max_name_len, int level) void btrfs_list_subvols(void) { - char *nameptr = malloc(4096); - - list_subvols(BTRFS_FS_TREE_OBJECTID, nameptr, nameptr ? 4096 : 0, 40); + struct btrfs_fs_info *fs_info = current_fs_info; + int ret; - if (nameptr) - free(nameptr); + if (!fs_info) + return; + ret = list_subvolums(fs_info); + if (ret < 0) + error("failed to list subvolume: %d", ret); } -- 2.26.2
[PATCH U-BOOT v3 29/30] fs: btrfs: Cleanup the old implementation
From: Qu Wenruo This cleans up the now unneeded code from the old btrfs implementation. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/Makefile | 4 +- fs/btrfs/btrfs.c | 31 fs/btrfs/btrfs.h | 47 -- fs/btrfs/chunk-map.c | 178 --- fs/btrfs/compression.c | 2 +- fs/btrfs/ctree.c | 290 fs/btrfs/ctree.h | 63 fs/btrfs/dir-item.c| 79 -- fs/btrfs/disk-io.c | 30 fs/btrfs/disk-io.h | 3 - fs/btrfs/extent-io.c | 116 --- fs/btrfs/inode.c | 323 - fs/btrfs/root.c| 92 fs/btrfs/subvolume.c | 111 -- 14 files changed, 3 insertions(+), 1366 deletions(-) delete mode 100644 fs/btrfs/chunk-map.c delete mode 100644 fs/btrfs/root.c diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 8d76422ce2..fc074c84d2 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -2,6 +2,6 @@ # # 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz -obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ - extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o \ +obj-y := btrfs.o compression.o ctree.o dev.o dir-item.o \ + extent-io.o inode.o subvolume.o crypto/hash.o disk-io.o \ common/rbtree-utils.o extent-cache.o volumes.o root-tree.o diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index ffd96427cc..786bb4733f 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -13,7 +13,6 @@ #include "crypto/hash.h" #include "disk-io.h" -struct btrfs_info btrfs_info; struct btrfs_fs_info *current_fs_info; static int show_dir(struct btrfs_root *root, struct extent_buffer *eb, @@ -120,36 +119,7 @@ int btrfs_probe(struct blk_desc *fs_dev_desc, struct btrfs_fs_info *fs_info; int ret = -1; - btrfs_blk_desc = fs_dev_desc; - btrfs_part_info = fs_partition; - - memset(&btrfs_info, 0, sizeof(btrfs_info)); - btrfs_hash_init(); - if (btrfs_read_superblock()) - return -1; - - if (btrfs_chunk_map_init()) { - printf("%s: failed to init chunk map\n", __func__); - return -1; - } - - btrfs_info.tree_root.objectid = 0; - btrfs_info.tree_root.bytenr = btrfs_info.sb.root; - btrfs_info.chunk_root.objectid = 0; - btrfs_info.chunk_root.bytenr = btrfs_info.sb.chunk_root; - - if (__btrfs_read_chunk_tree()) { - printf("%s: failed to read chunk tree\n", __func__); - return -1; - } - - if (btrfs_find_root(btrfs_get_default_subvol_objectid(), - &btrfs_info.fs_root, NULL)) { - printf("%s: failed to find default subvolume\n", __func__); - return -1; - } - fs_info = open_ctree_fs_info(fs_dev_desc, fs_partition); if (fs_info) { current_fs_info = fs_info; @@ -297,7 +267,6 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, void btrfs_close(void) { - btrfs_chunk_map_exit(); if (current_fs_info) { close_ctree_fs_info(current_fs_info); current_fs_info = NULL; diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index 268ca077d9..7d8b395b26 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -11,65 +11,18 @@ #include #include "conv-funcs.h" -struct btrfs_info { - struct btrfs_super_block sb; - - struct __btrfs_root tree_root; - struct __btrfs_root fs_root; - struct __btrfs_root chunk_root; - - struct rb_root chunks_root; -}; - extern struct btrfs_info btrfs_info; extern struct btrfs_fs_info *current_fs_info; -/* dev.c */ -extern struct blk_desc *btrfs_blk_desc; -extern struct disk_partition *btrfs_part_info; - -int btrfs_devread(u64, int, void *); - -/* chunk-map.c */ -u64 btrfs_map_logical_to_physical(u64); -int btrfs_chunk_map_init(void); -void btrfs_chunk_map_exit(void); -int __btrfs_read_chunk_tree(void); - /* compression.c */ u32 btrfs_decompress(u8 type, const char *, u32, char *, u32); -/* super.c */ -int btrfs_read_superblock(void); - -/* dir-item.c */ -int __btrfs_lookup_dir_item(const struct __btrfs_root *, u64, const char *, int, - struct btrfs_dir_item *); -/* root.c */ -int btrfs_find_root(u64, struct __btrfs_root *, struct btrfs_root_item *); -u64 btrfs_lookup_root_ref(u64, struct btrfs_root_ref *, char *); - /* inode.c */ -u64 __btrfs_lookup_inode_ref(struct __btrfs_root *, u64, struct btrfs_inode_ref *, - char *); -int __btrfs_lookup_inode(const struct __btrfs_root *, struct btrfs_key *, - struct btrfs_inode_item *, struct __btrfs_root *); -int __btrfs_readlink(const struct __btrfs_root *, u64, char *); int btrfs_readlink(struct btrfs_root *root, u64 ino, char *target); -u64 __btrfs_lookup_path(struct __btrf
[PATCH U-BOOT v3 18/30] fs: btrfs: inode: Allow next_length() to return value > BTRFS_NAME_LEN
From: Qu Wenruo All existing next_length() caller handles return value > BTRFS_NAME_LEN, so there is no need to do BTRFS_NAME_LEN check in next_length(). But still, we want to exit early if we're beyond BTRFS_NAME_LEN, so this patch makes next_length() exit as soon as we're beyond BTRFS_NAME_LEN. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/inode.c | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 007cf32c16..da2a5e90a1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -217,8 +217,12 @@ static u64 __get_parent_inode(struct __btrfs_root *root, u64 inr, static inline int next_length(const char *path) { int res = 0; - while (*path != '\0' && *path != '/' && res <= BTRFS_NAME_LEN) - ++res, ++path; + while (*path != '\0' && *path != '/') { + ++res; + ++path; + if (res > BTRFS_NAME_LEN) + break; + } return res; } -- 2.26.2
[PATCH U-BOOT v3 30/30] MAINTAINERS: Add btrfs mailing list and myself as reviewer
From: Qu Wenruo Since the current code base is mostly from btrfs-progs, anyone contributing to U-Boot btrfs code could also help us to improve btrfs-progs and btrfs kernel module. Also add myself as designated reviewer. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index db8cecd5e0..0cf04b5063 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -562,6 +562,8 @@ F: tools/binman/ BTRFS M: Marek Behun +R: Qu Wenruo +L: linux-bt...@vger.kernel.org S: Maintained F: cmd/btrfs.c F: fs/btrfs/ -- 2.26.2
[PATCH U-BOOT v3 27/30] fs: btrfs: Introduce function to resolve the path of one subvolume
From: Qu Wenruo This patch introduces a new function, list_one_subvol(), which will resolve the path to FS_TREE of one subvolume. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/subvolume.c | 81 1 file changed, 81 insertions(+) diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c index b446e729cd..258c3dafef 100644 --- a/fs/btrfs/subvolume.c +++ b/fs/btrfs/subvolume.c @@ -8,6 +8,7 @@ #include #include "ctree.h" #include "btrfs.h" +#include "disk-io.h" /* * Resolve the path of ino inside subvolume @root into @path_ret. @@ -74,6 +75,86 @@ out: return ret; } +static int list_one_subvol(struct btrfs_root *root, char *path_ret) +{ + struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_root *tree_root = fs_info->tree_root; + struct btrfs_path path; + struct btrfs_key key; + char *tmp; + u64 cur = root->root_key.objectid; + int ret = 0; + + tmp = malloc(PATH_MAX); + if (!tmp) + return -ENOMEM; + tmp[0] = '\0'; + path_ret[0] = '\0'; + btrfs_init_path(&path); + while (cur != BTRFS_FS_TREE_OBJECTID) { + struct btrfs_root_ref *rr; + struct btrfs_key location; + int name_len; + u64 ino; + + key.objectid = cur; + key.type = BTRFS_ROOT_BACKREF_KEY; + key.offset = (u64)-1; + btrfs_release_path(&path); + + ret = btrfs_search_slot(NULL, tree_root, &key, &path, 0, 0); + if (ret == 0) + ret = -EUCLEAN; + if (ret < 0) + goto out; + ret = btrfs_previous_item(tree_root, &path, cur, + BTRFS_ROOT_BACKREF_KEY); + if (ret > 0) + ret = -ENOENT; + if (ret < 0) + goto out; + + /* Get the subvolume name */ + rr = btrfs_item_ptr(path.nodes[0], path.slots[0], + struct btrfs_root_ref); + strncpy(tmp, path_ret, PATH_MAX); + name_len = btrfs_root_ref_name_len(path.nodes[0], rr); + if (name_len > BTRFS_NAME_LEN) { + ret = -ENAMETOOLONG; + goto out; + } + ino = btrfs_root_ref_dirid(path.nodes[0], rr); + read_extent_buffer(path.nodes[0], path_ret, + (unsigned long)(rr + 1), name_len); + path_ret[name_len] = '/'; + path_ret[name_len + 1] = '\0'; + strncat(path_ret, tmp, PATH_MAX); + + /* Get the path inside the parent subvolume */ + btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]); + location.objectid = key.offset; + location.type = BTRFS_ROOT_ITEM_KEY; + location.offset = (u64)-1; + root = btrfs_read_fs_root(fs_info, &location); + if (IS_ERR(root)) { + ret = PTR_ERR(root); + goto out; + } + ret = get_path_in_subvol(root, ino, path_ret); + if (ret < 0) + goto out; + cur = key.offset; + } + /* Add the leading '/' */ + strncpy(tmp, path_ret, PATH_MAX); + strncpy(path_ret, "/", PATH_MAX); + strncat(path_ret, tmp, PATH_MAX); +out: + btrfs_release_path(&path); + free(tmp); + return ret; +} + static int get_subvol_name(u64 subvolid, char *name, int max_len) { struct btrfs_root_ref rref; -- 2.26.2
[PATCH U-BOOT v3 26/30] fs: btrfs: Introduce function to resolve path in one subvolume
From: Qu Wenruo This patch introduces a new function, get_path_in_subvolume(), which resolves inode number into path inside a subvolume. This function will be later used for btrfs subvolume list functionality. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/compat.h| 1 + fs/btrfs/subvolume.c | 68 +++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h index 2dbeb90d33..321681814f 100644 --- a/fs/btrfs/compat.h +++ b/fs/btrfs/compat.h @@ -24,6 +24,7 @@ static inline void error(const char *fmt, ...) /* No so have to define it here */ #define XATTR_NAME_MAX 255 +#define PATH_MAX 4096 /* * Macros to generate set/get funcs for the struct fields diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c index 0e72577d0d..b446e729cd 100644 --- a/fs/btrfs/subvolume.c +++ b/fs/btrfs/subvolume.c @@ -5,8 +5,74 @@ * 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz */ -#include "btrfs.h" #include +#include "ctree.h" +#include "btrfs.h" + +/* + * Resolve the path of ino inside subvolume @root into @path_ret. + * + * @path_ret must be at least PATH_MAX size. + */ +static int get_path_in_subvol(struct btrfs_root *root, u64 ino, char *path_ret) +{ + struct btrfs_path path; + struct btrfs_key key; + char *tmp; + u64 cur = ino; + int ret = 0; + + tmp = malloc(PATH_MAX); + if (!tmp) + return -ENOMEM; + tmp[0] = '\0'; + + btrfs_init_path(&path); + while (cur != BTRFS_FIRST_FREE_OBJECTID) { + struct btrfs_inode_ref *iref; + int name_len; + + btrfs_release_path(&path); + key.objectid = cur; + key.type = BTRFS_INODE_REF_KEY; + key.offset = (u64)-1; + + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); + /* Impossible */ + if (ret == 0) + ret = -EUCLEAN; + if (ret < 0) + goto out; + ret = btrfs_previous_item(root, &path, cur, + BTRFS_INODE_REF_KEY); + if (ret > 0) + ret = -ENOENT; + if (ret < 0) + goto out; + + strncpy(tmp, path_ret, PATH_MAX); + iref = btrfs_item_ptr(path.nodes[0], path.slots[0], + struct btrfs_inode_ref); + name_len = btrfs_inode_ref_name_len(path.nodes[0], + iref); + if (name_len > BTRFS_NAME_LEN) { + ret = -ENAMETOOLONG; + goto out; + } + read_extent_buffer(path.nodes[0], path_ret, + (unsigned long)(iref + 1), name_len); + path_ret[name_len] = '/'; + path_ret[name_len + 1] = '\0'; + strncat(path_ret, tmp, PATH_MAX); + + btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]); + cur = key.offset; + } +out: + btrfs_release_path(&path); + free(tmp); + return ret; +} static int get_subvol_name(u64 subvolid, char *name, int max_len) { -- 2.26.2
[PATCH U-BOOT v3 15/30] fs: btrfs: Crossport open_ctree_fs_info() from btrfs-progs
From: Qu Wenruo open_ctree_fs_info() is the main entry point to open btrfs. This version is a simplfied version of __open_ctree_fd() of btrfs-progs, the main differences are: - Parameters on how to specify a block device Instead of @fd and @path, U-Boot uses blk_desc and disk_partition_t. - Remove open_ctree flags There won't be multiple open ctree modes in U-Boot. Otherwise functions structures are all kept the same. With open_ctree_fs_info() implemented, also introduce the global current_fs_info pointer to show the current opened btrfs. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/Makefile| 2 +- fs/btrfs/btrfs.c | 15 +- fs/btrfs/btrfs.h | 1 + fs/btrfs/compat.h| 2 + fs/btrfs/ctree.h | 4 + fs/btrfs/disk-io.c | 509 +-- fs/btrfs/disk-io.h | 19 ++ fs/btrfs/root-tree.c | 47 8 files changed, 579 insertions(+), 20 deletions(-) create mode 100644 fs/btrfs/root-tree.c diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index ec30aae765..8d76422ce2 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -4,4 +4,4 @@ obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o \ - common/rbtree-utils.o extent-cache.o volumes.o + common/rbtree-utils.o extent-cache.o volumes.o root-tree.o diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index f5266f1b91..2bd2ec9ed9 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -14,6 +14,7 @@ #include "disk-io.h" struct btrfs_info btrfs_info; +struct btrfs_fs_info *current_fs_info; static int readdir_callback(const struct __btrfs_root *root, struct btrfs_dir_item *item) @@ -81,6 +82,9 @@ static int readdir_callback(const struct __btrfs_root *root, int btrfs_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) { + struct btrfs_fs_info *fs_info; + int ret = -1; + btrfs_blk_desc = fs_dev_desc; btrfs_part_info = fs_partition; @@ -111,7 +115,12 @@ int btrfs_probe(struct blk_desc *fs_dev_desc, return -1; } - return 0; + fs_info = open_ctree_fs_info(fs_dev_desc, fs_partition); + if (fs_info) { + current_fs_info = fs_info; + ret = 0; + } + return ret; } int btrfs_ls(const char *path) @@ -215,6 +224,10 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, void btrfs_close(void) { btrfs_chunk_map_exit(); + if (current_fs_info) { + close_ctree_fs_info(current_fs_info); + current_fs_info = NULL; + } } int btrfs_uuid(char *uuid_str) diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index 7dfdaf77ba..a52ff942f2 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -22,6 +22,7 @@ struct btrfs_info { }; extern struct btrfs_info btrfs_info; +extern struct btrfs_fs_info *current_fs_info; /* dev.c */ extern struct blk_desc *btrfs_blk_desc; diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h index b6b75deb3e..4da88fc311 100644 --- a/fs/btrfs/compat.h +++ b/fs/btrfs/compat.h @@ -18,6 +18,8 @@ static inline void error(const char *fmt, ...) printf("\n"); } +#define ASSERT(c) assert(c) + #define BTRFS_UUID_UNPARSED_SIZE 37 /* diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 7c814fd2a9..b050b5844d 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1275,6 +1275,10 @@ const char *btrfs_super_csum_name(u16 csum_type); u16 btrfs_csum_type_size(u16 csum_type); size_t btrfs_super_num_csums(void); +/* root-tree.c */ +int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, + struct btrfs_root_item *item, struct btrfs_key *key); + /* ctree.c */ int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); enum btrfs_tree_block_status diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 65b4020ebe..4d08b0204a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4,6 +4,7 @@ #include #include #include "kernel-shared/btrfs_tree.h" +#include "common/rbtree-utils.h" #include "disk-io.h" #include "ctree.h" #include "btrfs.h" @@ -424,24 +425,6 @@ out: } -int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid) -{ - int ret; - - ret = extent_buffer_uptodate(buf); - if (!ret) - return ret; - - ret = verify_parent_transid(&buf->fs_info->extent_cache, buf, - parent_transid, 1); - return !ret; -} - -int btrfs_set_buffer_uptodate(struct extent_buffer *eb) -{ - return set_extent_buffer_uptodate(eb); -} - int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirror) { unsigned long offset = 0; @@ -581,3 +564,493 @@ struct extent_buffer* read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
[PATCH U-BOOT v3 14/30] fs: btrfs: Crossport btrfs_read_sys_array() and btrfs_read_chunk_tree()
From: Qu Wenruo These two functions play a big role in btrfs bootstrap. The following function is removed: - Seed device support Although in theory we can still support multiple devices, we don't have a facility in U-Boot to do device scan without opening them. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.c | 2 +- fs/btrfs/btrfs.h | 2 +- fs/btrfs/chunk-map.c | 2 +- fs/btrfs/volumes.c | 301 +++ fs/btrfs/volumes.h | 2 + 5 files changed, 306 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index b4535c9551..f5266f1b91 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -100,7 +100,7 @@ int btrfs_probe(struct blk_desc *fs_dev_desc, btrfs_info.chunk_root.objectid = 0; btrfs_info.chunk_root.bytenr = btrfs_info.sb.chunk_root; - if (btrfs_read_chunk_tree()) { + if (__btrfs_read_chunk_tree()) { printf("%s: failed to read chunk tree\n", __func__); return -1; } diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index ae29226e9a..7dfdaf77ba 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -33,7 +33,7 @@ int btrfs_devread(u64, int, void *); u64 btrfs_map_logical_to_physical(u64); int btrfs_chunk_map_init(void); void btrfs_chunk_map_exit(void); -int btrfs_read_chunk_tree(void); +int __btrfs_read_chunk_tree(void); /* compression.c */ u32 btrfs_decompress(u8 type, const char *, u32, char *, u32); diff --git a/fs/btrfs/chunk-map.c b/fs/btrfs/chunk-map.c index 8e3d13c4a9..bff83e4dc8 100644 --- a/fs/btrfs/chunk-map.c +++ b/fs/btrfs/chunk-map.c @@ -142,7 +142,7 @@ int btrfs_chunk_map_init(void) return 0; } -int btrfs_read_chunk_tree(void) +int __btrfs_read_chunk_tree(void) { struct __btrfs_path path; struct btrfs_key key, *found_key; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 7c72c4267f..be3752bb75 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5,6 +5,7 @@ #include "ctree.h" #include "disk-io.h" #include "volumes.h" +#include "extent-io.h" const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { [BTRFS_RAID_RAID10] = { @@ -369,6 +370,14 @@ struct btrfs_device *btrfs_find_device(struct btrfs_fs_info *fs_info, u64 devid, return NULL; } +static struct btrfs_device *fill_missing_device(u64 devid) +{ + struct btrfs_device *device; + + device = kzalloc(sizeof(*device), GFP_NOFS); + return device; +} + /* * slot == -1: SYSTEM chunk * return -EIO on error, otherwise return 0 @@ -498,6 +507,298 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info, return 0; } +/* + * Slot is used to verify the chunk item is valid + * + * For sys chunk in superblock, pass -1 to indicate sys chunk. + */ +static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key, + struct extent_buffer *leaf, + struct btrfs_chunk *chunk, int slot) +{ + struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; + struct map_lookup *map; + struct cache_extent *ce; + u64 logical; + u64 length; + u64 devid; + u8 uuid[BTRFS_UUID_SIZE]; + int num_stripes; + int ret; + int i; + + logical = key->offset; + length = btrfs_chunk_length(leaf, chunk); + num_stripes = btrfs_chunk_num_stripes(leaf, chunk); + /* Validation check */ + ret = btrfs_check_chunk_valid(fs_info, leaf, chunk, slot, logical); + if (ret) { + error("%s checksums match, but it has an invalid chunk, %s", + (slot == -1) ? "Superblock" : "Metadata", + (slot == -1) ? "try btrfsck --repair -s ie, 0,1,2" : ""); + return ret; + } + + ce = search_cache_extent(&map_tree->cache_tree, logical); + + /* already mapped? */ + if (ce && ce->start <= logical && ce->start + ce->size > logical) { + return 0; + } + + map = kmalloc(btrfs_map_lookup_size(num_stripes), GFP_NOFS); + if (!map) + return -ENOMEM; + + map->ce.start = logical; + map->ce.size = length; + map->num_stripes = num_stripes; + map->io_width = btrfs_chunk_io_width(leaf, chunk); + map->io_align = btrfs_chunk_io_align(leaf, chunk); + map->sector_size = btrfs_chunk_sector_size(leaf, chunk); + map->stripe_len = btrfs_chunk_stripe_len(leaf, chunk); + map->type = btrfs_chunk_type(leaf, chunk); + map->sub_stripes = btrfs_chunk_sub_stripes(leaf, chunk); + + for (i = 0; i < num_stripes; i++) { + map->stripes[i].physical = + btrfs_stripe_offset_nr(leaf, chunk, i); + devid = btrfs_stripe_devid_nr(leaf, chunk, i); + read_extent_buffer(leaf, uuid, (unsigned long) + btrfs_stripe
[PATCH U-BOOT v3 16/30] fs: btrfs: Rename path resolve related functions to avoid name conflicts
From: Qu Wenruo Since the old code is using __btrfs_path/__btrfs_root which is different from the regular extent buffer based one, we add "__" prefix for the old implementation to avoid name conflicts for the incoming crossport. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.c | 12 ++-- fs/btrfs/btrfs.h | 10 +- fs/btrfs/compat.h| 3 +++ fs/btrfs/ctree.h | 7 +++ fs/btrfs/dir-item.c | 12 ++-- fs/btrfs/inode.c | 28 ++-- fs/btrfs/subvolume.c | 4 ++-- 7 files changed, 43 insertions(+), 33 deletions(-) diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index 2bd2ec9ed9..c967c114cc 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -35,7 +35,7 @@ static int readdir_callback(const struct __btrfs_root *root, char filetime[32], *target = NULL; time_t mtime; - if (btrfs_lookup_inode(root, (struct btrfs_key *)&item->location, + if (__btrfs_lookup_inode(root, (struct btrfs_key *)&item->location, &inode, NULL)) { printf("%s: Cannot find inode item for directory entry %.*s!\n", __func__, item->name_len, name); @@ -49,7 +49,7 @@ static int readdir_callback(const struct __btrfs_root *root, target = malloc(min(inode.size + 1, (u64) btrfs_info.sb.sectorsize)); - if (target && btrfs_readlink(root, item->location.objectid, + if (target && __btrfs_readlink(root, item->location.objectid, target)) { free(target); target = NULL; @@ -129,7 +129,7 @@ int btrfs_ls(const char *path) u64 inr; u8 type; - inr = btrfs_lookup_path(&root, root.root_dirid, path, &type, NULL, 40); + inr = __btrfs_lookup_path(&root, root.root_dirid, path, &type, NULL, 40); if (inr == -1ULL) { printf("Cannot lookup path %s\n", path); @@ -155,7 +155,7 @@ int btrfs_exists(const char *file) u64 inr; u8 type; - inr = btrfs_lookup_path(&root, root.root_dirid, file, &type, NULL, 40); + inr = __btrfs_lookup_path(&root, root.root_dirid, file, &type, NULL, 40); return (inr != -1ULL && type == BTRFS_FT_REG_FILE); } @@ -167,7 +167,7 @@ int btrfs_size(const char *file, loff_t *size) u64 inr; u8 type; - inr = btrfs_lookup_path(&root, root.root_dirid, file, &type, &inode, + inr = __btrfs_lookup_path(&root, root.root_dirid, file, &type, &inode, 40); if (inr == -1ULL) { @@ -192,7 +192,7 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, u64 inr, rd; u8 type; - inr = btrfs_lookup_path(&root, root.root_dirid, file, &type, &inode, + inr = __btrfs_lookup_path(&root, root.root_dirid, file, &type, &inode, 40); if (inr == -1ULL) { diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index a52ff942f2..e8197391a2 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -46,7 +46,7 @@ int btrfs_read_superblock(void); typedef int (*btrfs_readdir_callback_t)(const struct __btrfs_root *, struct btrfs_dir_item *); -int btrfs_lookup_dir_item(const struct __btrfs_root *, u64, const char *, int, +int __btrfs_lookup_dir_item(const struct __btrfs_root *, u64, const char *, int, struct btrfs_dir_item *); int btrfs_readdir(const struct __btrfs_root *, u64, btrfs_readdir_callback_t); @@ -55,12 +55,12 @@ int btrfs_find_root(u64, struct __btrfs_root *, struct btrfs_root_item *); u64 btrfs_lookup_root_ref(u64, struct btrfs_root_ref *, char *); /* inode.c */ -u64 btrfs_lookup_inode_ref(struct __btrfs_root *, u64, struct btrfs_inode_ref *, +u64 __btrfs_lookup_inode_ref(struct __btrfs_root *, u64, struct btrfs_inode_ref *, char *); -int btrfs_lookup_inode(const struct __btrfs_root *, struct btrfs_key *, +int __btrfs_lookup_inode(const struct __btrfs_root *, struct btrfs_key *, struct btrfs_inode_item *, struct __btrfs_root *); -int btrfs_readlink(const struct __btrfs_root *, u64, char *); -u64 btrfs_lookup_path(struct __btrfs_root *, u64, const char *, u8 *, +int __btrfs_readlink(const struct __btrfs_root *, u64, char *); +u64 __btrfs_lookup_path(struct __btrfs_root *, u64, const char *, u8 *, struct btrfs_inode_item *, int); u64 btrfs_file_read(const struct __btrfs_root *, u64, u64, u64, char *); diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h index 4da88fc311..2dbeb90d33 100644 --- a/fs/btrfs/compat.h +++ b/fs/btrfs/compat.h @@ -22,6 +22,9 @@ static inline void error(const char *fmt, ...) #define BTRFS_UUID_UNPARSED_SIZE 37 +/* No so have to define it here */ +#define XATTR_NAME_MAX 25
[PATCH U-BOOT v3 17/30] fs: btrfs: Use btrfs_readlink() to implement __btrfs_readlink()
From: Qu Wenruo The existing __btrfs_readlink() can be easily re-implemented using the extent buffer based btrfs_readlink(). This is the first step to re-implement U-Boot's btrfs code. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.h | 1 + fs/btrfs/inode.c | 101 ++- 2 files changed, 65 insertions(+), 37 deletions(-) diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index e8197391a2..53d53f310b 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -60,6 +60,7 @@ u64 __btrfs_lookup_inode_ref(struct __btrfs_root *, u64, struct btrfs_inode_ref int __btrfs_lookup_inode(const struct __btrfs_root *, struct btrfs_key *, struct btrfs_inode_item *, struct __btrfs_root *); int __btrfs_readlink(const struct __btrfs_root *, u64, char *); +int btrfs_readlink(struct btrfs_root *root, u64 ino, char *target); u64 __btrfs_lookup_path(struct __btrfs_root *, u64, const char *, u8 *, struct btrfs_inode_item *, int); u64 btrfs_file_read(const struct __btrfs_root *, u64, u64, u64, char *); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index eb34f546b5..007cf32c16 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5,8 +5,9 @@ * 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz */ -#include "btrfs.h" #include +#include "btrfs.h" +#include "disk-io.h" u64 __btrfs_lookup_inode_ref(struct __btrfs_root *root, u64 inr, struct btrfs_inode_ref *refp, char *name) @@ -83,56 +84,82 @@ out: return res; } -int __btrfs_readlink(const struct __btrfs_root *root, u64 inr, char *target) +/* + * Read the content of symlink inode @ino of @root, into @target. + * NOTE: @target will not be \0 termiated, caller should handle it properly. + * + * Return the number of read data. + * Return <0 for error. + */ +int btrfs_readlink(struct btrfs_root *root, u64 ino, char *target) { - struct __btrfs_path path; + struct btrfs_path path; struct btrfs_key key; - struct btrfs_file_extent_item *extent; - const char *data_ptr; - int res = -1; + struct btrfs_file_extent_item *fi; + int ret; - key.objectid = inr; + key.objectid = ino; key.type = BTRFS_EXTENT_DATA_KEY; key.offset = 0; + btrfs_init_path(&path); - if (btrfs_search_tree(root, &key, &path)) - return -1; - - if (__btrfs_comp_keys(&key, btrfs_path_leaf_key(&path))) - goto out; - - extent = btrfs_path_item_ptr(&path, struct btrfs_file_extent_item); - if (extent->type != BTRFS_FILE_EXTENT_INLINE) { - printf("%s: Extent for symlink %llu not of INLINE type\n", - __func__, inr); + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); + if (ret < 0) + return ret; + if (ret > 0) { + ret = -ENOENT; goto out; } - - btrfs_file_extent_item_to_cpu_inl(extent); - - if (extent->compression != BTRFS_COMPRESS_NONE) { - printf("%s: Symlink %llu extent data compressed!\n", __func__, - inr); + fi = btrfs_item_ptr(path.nodes[0], path.slots[0], + struct btrfs_file_extent_item); + if (btrfs_file_extent_type(path.nodes[0], fi) != + BTRFS_FILE_EXTENT_INLINE) { + ret = -EUCLEAN; + error("Extent for symlink %llu must be INLINE type!", ino); goto out; - } else if (extent->encryption != 0) { - printf("%s: Symlink %llu extent data encrypted!\n", __func__, - inr); + } + if (btrfs_file_extent_compression(path.nodes[0], fi) != + BTRFS_COMPRESS_NONE) { + ret = -EUCLEAN; + error("Extent for symlink %llu must not be compressed!", ino); goto out; - } else if (extent->ram_bytes >= btrfs_info.sb.sectorsize) { - printf("%s: Symlink %llu extent data too long (%llu)!\n", - __func__, inr, extent->ram_bytes); + } + if (btrfs_file_extent_ram_bytes(path.nodes[0], fi) >= + root->fs_info->sectorsize) { + ret = -EUCLEAN; + error("Symlink %llu extent data too large (%llu)!\n", + ino, btrfs_file_extent_ram_bytes(path.nodes[0], fi)); goto out; } + read_extent_buffer(path.nodes[0], target, + btrfs_file_extent_inline_start(fi), + btrfs_file_extent_ram_bytes(path.nodes[0], fi)); + ret = btrfs_file_extent_ram_bytes(path.nodes[0], fi); +out: + btrfs_release_path(&path); + return ret; +} - data_ptr = (const char *) extent - + offsetof(struct btrfs_file_extent_item, disk_bytenr); +int __btrfs_readlink(const struct __btrfs_root *root, u64 inr, char *target) +{ + struct
[PATCH U-BOOT v3 25/30] fs: btrfs: Implement btrfs_file_read()
From: Qu Wenruo This version of btrfs_file_read() has the following new features: - Tries all mirrors - More handling on unaligned size - Better compressed extent handling The old implementation doesn't handle compressed extent with offset properly: we need to read out the whole compressed extent, then decompress the whole extent, and only then copy the requested part. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.c | 48 +--- fs/btrfs/btrfs.h | 2 + fs/btrfs/inode.c | 146 +++ 3 files changed, 176 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index 7eb01c4ff9..ffd96427cc 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -253,37 +253,45 @@ out: int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, loff_t *actread) { - struct __btrfs_root root = btrfs_info.fs_root; - struct btrfs_inode_item inode; - u64 inr, rd; + struct btrfs_fs_info *fs_info = current_fs_info; + struct btrfs_root *root; + loff_t real_size; + u64 ino; u8 type; + int ret; - inr = __btrfs_lookup_path(&root, root.root_dirid, file, &type, &inode, - 40); - - if (inr == -1ULL) { - printf("Cannot lookup file %s\n", file); - return -1; + ASSERT(fs_info); + ret = btrfs_lookup_path(fs_info->fs_root, BTRFS_FIRST_FREE_OBJECTID, + file, &root, &ino, &type, 40); + if (ret < 0) { + error("Cannot lookup file %s", file); + return ret; } if (type != BTRFS_FT_REG_FILE) { - printf("Not a regular file: %s\n", file); - return -1; + error("Not a regular file: %s", file); + return -EINVAL; } - if (!len) - len = inode.size; + if (!len) { + ret = btrfs_size(file, &real_size); + if (ret < 0) { + error("Failed to get inode size: %s", file); + return ret; + } + len = real_size; + } - if (len > inode.size - offset) - len = inode.size - offset; + if (len > real_size - offset) + len = real_size - offset; - rd = __btrfs_file_read(&root, inr, offset, len, buf); - if (rd == -1ULL) { - printf("An error occured while reading file %s\n", file); - return -1; + ret = btrfs_file_read(root, ino, offset, len, buf); + if (ret < 0) { + error("An error occured while reading file %s", file); + return ret; } - *actread = rd; + *actread = len; return 0; } diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index 32ea2fc53a..268ca077d9 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -59,6 +59,8 @@ int btrfs_readlink(struct btrfs_root *root, u64 ino, char *target); u64 __btrfs_lookup_path(struct __btrfs_root *, u64, const char *, u8 *, struct btrfs_inode_item *, int); u64 __btrfs_file_read(const struct __btrfs_root *, u64, u64, u64, char *); +int btrfs_file_read(struct btrfs_root *root, u64 ino, u64 file_offset, u64 len, + char *dest); /* subvolume.c */ u64 btrfs_get_default_subvol_objectid(void); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 11eb30c27a..0c2b2b5705 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -926,3 +926,149 @@ check_next: *next_offset = key.offset; return 1; } + +static int read_and_truncate_page(struct btrfs_path *path, + struct btrfs_file_extent_item *fi, + int start, int len, char *dest) +{ + struct extent_buffer *leaf = path->nodes[0]; + struct btrfs_fs_info *fs_info = leaf->fs_info; + u64 aligned_start = round_down(start, fs_info->sectorsize); + u8 extent_type; + char *buf; + int page_off = start - aligned_start; + int page_len = fs_info->sectorsize - page_off; + int ret; + + ASSERT(start + len <= aligned_start + fs_info->sectorsize); + buf = malloc_cache_aligned(fs_info->sectorsize); + if (!buf) + return -ENOMEM; + + extent_type = btrfs_file_extent_type(leaf, fi); + if (extent_type == BTRFS_FILE_EXTENT_INLINE) { + ret = btrfs_read_extent_inline(path, fi, buf); + memcpy(dest, buf + page_off, min(page_len, ret)); + free(buf); + return len; + } + + ret = btrfs_read_extent_reg(path, fi, + round_down(start, fs_info->sectorsize), + fs_info->sectorsize, buf); + if (ret < 0) { + free(buf); + return ret; + } + memcpy(dest, buf + page_off, page_len
[PATCH U-BOOT v3 23/30] fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()
From: Qu Wenruo These two functions are used to do sector aligned read, which will be later used to implement btrfs_file_read(). Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/ctree.h | 5 ++ fs/btrfs/disk-io.c | 36 ++ fs/btrfs/disk-io.h | 2 + fs/btrfs/inode.c | 162 + 4 files changed, 205 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 0cf5e63451..c4b25189dc 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1294,6 +1294,11 @@ int btrfs_iter_dir(struct btrfs_root *root, u64 ino, int btrfs_lookup_path(struct btrfs_root *root, u64 ino, const char *filename, struct btrfs_root **root_ret, u64 *ino_ret, u8 *type_ret, int symlink_limit); +int btrfs_read_extent_inline(struct btrfs_path *path, +struct btrfs_file_extent_item *fi, char *dest); +int btrfs_read_extent_reg(struct btrfs_path *path, + struct btrfs_file_extent_item *fi, u64 offset, + int len, char *dest); /* ctree.c */ int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4d08b0204a..4da1b80038 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -565,6 +565,42 @@ struct extent_buffer* read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, return ERR_PTR(ret); } +int read_extent_data(struct btrfs_fs_info *fs_info, char *data, u64 logical, +u64 *len, int mirror) +{ + u64 offset = 0; + struct btrfs_multi_bio *multi = NULL; + struct btrfs_device *device; + int ret = 0; + u64 max_len = *len; + + ret = btrfs_map_block(fs_info, READ, logical, len, &multi, mirror, + NULL); + if (ret) { + fprintf(stderr, "Couldn't map the block %llu\n", + logical + offset); + goto err; + } + device = multi->stripes[0].dev; + + if (*len > max_len) + *len = max_len; + if (!device->desc || !device->part) { + ret = -EIO; + goto err; + } + + ret = __btrfs_devread(device->desc, device->part, data, *len, + multi->stripes[0].physical); + if (ret != *len) + ret = -EIO; + else + ret = 0; +err: + kfree(multi); + return ret; +} + void btrfs_setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, u64 objectid) { diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 9daf959c57..424bb01dcd 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -18,6 +18,8 @@ int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirr struct extent_buffer* read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, u64 parent_transid); +int read_extent_data(struct btrfs_fs_info *fs_info, char *data, u64 logical, +u64 *len, int mirror); struct extent_buffer* btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, u64 bytenr); struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 83d21467d9..ab45db87a6 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5,9 +5,12 @@ * 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz */ +#include #include +#include #include "btrfs.h" #include "disk-io.h" +#include "volumes.h" u64 __btrfs_lookup_inode_ref(struct __btrfs_root *root, u64 inr, struct btrfs_inode_ref *refp, char *name) @@ -663,3 +666,162 @@ out: __btrfs_free_path(&path); return rd_all; } + +/* + * Read out inline extent. + * + * Since inline extent should only exist for offset 0, no need for extra + * parameters. + * Truncating should be handled by the caller. + * + * Return the number of bytes read. + * Return <0 for error. + */ +int btrfs_read_extent_inline(struct btrfs_path *path, +struct btrfs_file_extent_item *fi, char *dest) +{ + struct extent_buffer *leaf = path->nodes[0]; + int slot = path->slots[0]; + char *cbuf = NULL; + char *dbuf = NULL; + u32 csize; + u32 dsize; + int ret; + + csize = btrfs_file_extent_inline_item_len(leaf, btrfs_item_nr(slot)); + if (btrfs_file_extent_compression(leaf, fi) == BTRFS_COMPRESS_NONE) { + /* Uncompressed, just read it out */ + read_extent_buffer(leaf, dest, + btrfs_file_extent_inline_start(fi), + csize); + return csize; + } + + /* Compressed extent, prepare the compressed and data buffer */ + dsize = btrfs_file_extent_ram_bytes(leaf, fi); + cbuf = malloc(csize); +
[PATCH U-BOOT v3 19/30] fs: btrfs: Implement btrfs_lookup_path()
From: Qu Wenruo This is the extent buffer based path lookup routine. To implement this, btrfs_lookup_dir_item() is crossported from btrfs-progs, and implements btrfs_lookup_path() from scratch. Unlike the existing __btrfs_lookup_path(), since btrfs_read_fs_root() will check whether a root is a orphan at read time, there is no need to check root backref, this makes the code a little easier to read. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/ctree.h| 4 + fs/btrfs/dir-item.c | 106 +++ fs/btrfs/inode.c| 250 3 files changed, 360 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index d635b0814e..111a5a6a29 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1285,6 +1285,10 @@ struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_path *path, u64 dir, const char *name, int name_len, int mod); +/* inode.c */ +int btrfs_lookup_path(struct btrfs_root *root, u64 ino, const char *filename, + struct btrfs_root **root_ret, u64 *ino_ret, + u8 *type_ret, int symlink_limit); /* ctree.c */ int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index aea621c72b..b49aaacbd8 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -8,6 +8,112 @@ #include "btrfs.h" #include "disk-io.h" +static int verify_dir_item(struct btrfs_root *root, + struct extent_buffer *leaf, + struct btrfs_dir_item *dir_item) +{ + u16 namelen = BTRFS_NAME_LEN; + u8 type = btrfs_dir_type(leaf, dir_item); + + if (type == BTRFS_FT_XATTR) + namelen = XATTR_NAME_MAX; + + if (btrfs_dir_name_len(leaf, dir_item) > namelen) { + fprintf(stderr, "invalid dir item name len: %u\n", + (unsigned)btrfs_dir_data_len(leaf, dir_item)); + return 1; + } + + /* BTRFS_MAX_XATTR_SIZE is the same for all dir items */ + if ((btrfs_dir_data_len(leaf, dir_item) + +btrfs_dir_name_len(leaf, dir_item)) > + BTRFS_MAX_XATTR_SIZE(root->fs_info)) { + fprintf(stderr, "invalid dir item name + data len: %u + %u\n", + (unsigned)btrfs_dir_name_len(leaf, dir_item), + (unsigned)btrfs_dir_data_len(leaf, dir_item)); + return 1; + } + + return 0; +} + +struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root, + struct btrfs_path *path, + const char *name, int name_len) +{ + struct btrfs_dir_item *dir_item; + unsigned long name_ptr; + u32 total_len; + u32 cur = 0; + u32 this_len; + struct extent_buffer *leaf; + + leaf = path->nodes[0]; + dir_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dir_item); + total_len = btrfs_item_size_nr(leaf, path->slots[0]); + if (verify_dir_item(root, leaf, dir_item)) + return NULL; + + while(cur < total_len) { + this_len = sizeof(*dir_item) + + btrfs_dir_name_len(leaf, dir_item) + + btrfs_dir_data_len(leaf, dir_item); + if (this_len > (total_len - cur)) { + fprintf(stderr, "invalid dir item size\n"); + return NULL; + } + + name_ptr = (unsigned long)(dir_item + 1); + + if (btrfs_dir_name_len(leaf, dir_item) == name_len && + memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0) + return dir_item; + + cur += this_len; + dir_item = (struct btrfs_dir_item *)((char *)dir_item + +this_len); + } + return NULL; +} + +struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, +struct btrfs_root *root, +struct btrfs_path *path, u64 dir, +const char *name, int name_len, +int mod) +{ + int ret; + struct btrfs_key key; + int ins_len = mod < 0 ? -1 : 0; + int cow = mod != 0; + struct btrfs_key found_key; + struct extent_buffer *leaf; + + key.objectid = dir; + key.type = BTRFS_DIR_ITEM_KEY; + + key.offset = btrfs_name_hash(name, name_len); + + ret = btrfs_search_slot(trans, root, &key, path, ins_len, cow); + if (ret < 0) + return ERR_PTR(ret); + if (ret > 0) { + i
[PATCH U-BOOT v3 24/30] fs: btrfs: Introduce lookup_data_extent() for later use
From: Qu Wenruo This implements lookup_data_extent() function for the incoming new implementation of btrfs_file_read(). Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/inode.c | 101 +++ 1 file changed, 101 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ab45db87a6..11eb30c27a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -825,3 +825,104 @@ out: free(dbuf); return ret; } + +/* + * Get the first file extent that covers bytenr @file_offset. + * + * @file_offset must be aligned to sectorsize. + * + * return 0 for found, and path points to the file extent. + * return >0 for not found, and fill @next_offset. + * @next_offset can be 0 if there is no next file extent. + * return <0 for error. + */ +static int lookup_data_extent(struct btrfs_root *root, struct btrfs_path *path, + u64 ino, u64 file_offset, u64 *next_offset) +{ + struct btrfs_key key; + struct btrfs_file_extent_item *fi; + u8 extent_type; + int ret = 0; + + ASSERT(IS_ALIGNED(file_offset, root->fs_info->sectorsize)); + key.objectid = ino; + key.type = BTRFS_EXTENT_DATA_KEY; + key.offset = file_offset; + + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + /* Error or we're already at the file extent */ + if (ret <= 0) + return ret; + if (ret > 0) { + /* Check previous file extent */ + ret = btrfs_previous_item(root, path, ino, + BTRFS_EXTENT_DATA_KEY); + if (ret < 0) + return ret; + if (ret > 0) + goto check_next; + } + /* Now the key.offset must be smaller than @file_offset */ + btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); + if (key.objectid != ino || + key.type != BTRFS_EXTENT_DATA_KEY) + goto check_next; + + fi = btrfs_item_ptr(path->nodes[0], path->slots[0], + struct btrfs_file_extent_item); + extent_type = btrfs_file_extent_type(path->nodes[0], fi); + if (extent_type == BTRFS_FILE_EXTENT_INLINE) { + if (file_offset == 0) + return 0; + /* Inline extent should be the only extent, no next extent. */ + *next_offset = 0; + return 1; + } + + /* This file extent covers @file_offset */ + if (key.offset <= file_offset && key.offset + + btrfs_file_extent_num_bytes(path->nodes[0], fi) > file_offset) + return 0; +check_next: + ret = btrfs_next_item(root, path); + if (ret < 0) + return ret; + if (ret > 0) { + *next_offset = 0; + return 1; + } + + btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); + fi = btrfs_item_ptr(path->nodes[0], path->slots[0], + struct btrfs_file_extent_item); + /* Next next data extent */ + if (key.objectid != ino || + key.type != BTRFS_EXTENT_DATA_KEY) { + *next_offset = 0; + return 1; + } + /* Current file extent already beyond @file_offset */ + if (key.offset > file_offset) { + *next_offset = key.offset; + return 1; + } + /* This file extent covers @file_offset */ + if (key.offset <= file_offset && key.offset + + btrfs_file_extent_num_bytes(path->nodes[0], fi) > file_offset) + return 0; + /* This file extent ends before @file_offset, check next */ + ret = btrfs_next_item(root, path); + if (ret < 0) + return ret; + if (ret > 0) { + *next_offset = 0; + return 1; + } + btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); + if (key.type != BTRFS_EXTENT_DATA_KEY || key.objectid != ino) { + *next_offset = 0; + return 1; + } + *next_offset = key.offset; + return 1; +} -- 2.26.2
[PATCH U-BOOT v3 21/30] fs: btrfs: Use btrfs_lookup_path() to implement btrfs_exists() and btrfs_size()
From: Qu Wenruo After this the only remaining function that still utilizes __btrfs_lookup_path() is btrfs_read(). Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.c | 65 +++- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index 2278b52e4d..aec91a57ec 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -188,37 +188,66 @@ int btrfs_ls(const char *path) int btrfs_exists(const char *file) { - struct __btrfs_root root = btrfs_info.fs_root; - u64 inr; + struct btrfs_fs_info *fs_info = current_fs_info; + struct btrfs_root *root; + u64 ino; u8 type; + int ret; + + ASSERT(fs_info); - inr = __btrfs_lookup_path(&root, root.root_dirid, file, &type, NULL, 40); + ret = btrfs_lookup_path(fs_info->fs_root, BTRFS_FIRST_FREE_OBJECTID, + file, &root, &ino, &type, 40); + if (ret < 0) + return 0; - return (inr != -1ULL && type == BTRFS_FT_REG_FILE); + if (type == BTRFS_FT_REG_FILE) + return 1; + return 0; } int btrfs_size(const char *file, loff_t *size) { - struct __btrfs_root root = btrfs_info.fs_root; - struct btrfs_inode_item inode; - u64 inr; + struct btrfs_fs_info *fs_info = current_fs_info; + struct btrfs_inode_item *ii; + struct btrfs_root *root; + struct btrfs_path path; + struct btrfs_key key; + u64 ino; u8 type; + int ret; - inr = __btrfs_lookup_path(&root, root.root_dirid, file, &type, &inode, - 40); - - if (inr == -1ULL) { + ret = btrfs_lookup_path(fs_info->fs_root, BTRFS_FIRST_FREE_OBJECTID, + file, &root, &ino, &type, 40); + if (ret < 0) { printf("Cannot lookup file %s\n", file); - return -1; + return ret; } - if (type != BTRFS_FT_REG_FILE) { printf("Not a regular file: %s\n", file); - return -1; + return -ENOENT; } + btrfs_init_path(&path); + key.objectid = ino; + key.type = BTRFS_INODE_ITEM_KEY; + key.offset = 0; - *size = inode.size; - return 0; + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); + if (ret < 0) { + printf("Cannot lookup ino %llu\n", ino); + return ret; + } + if (ret > 0) { + printf("Ino %llu does not exist\n", ino); + ret = -ENOENT; + goto out; + } + ii = btrfs_item_ptr(path.nodes[0], path.slots[0], + struct btrfs_inode_item); + *size = btrfs_inode_size(path.nodes[0], ii); +out: + btrfs_release_path(&path); + return ret; } int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, @@ -270,7 +299,9 @@ void btrfs_close(void) int btrfs_uuid(char *uuid_str) { #ifdef CONFIG_LIB_UUID - uuid_bin_to_str(btrfs_info.sb.fsid, uuid_str, UUID_STR_FORMAT_STD); + if (current_fs_info) + uuid_bin_to_str(current_fs_info->super_copy->fsid, uuid_str, + UUID_STR_FORMAT_STD); return 0; #endif return -ENOSYS; -- 2.26.2
[PATCH U-BOOT v3 20/30] fs: btrfs: Use btrfs_iter_dir() to replace btrfs_readdir()
From: Qu Wenruo Use extent buffer based infrastructure to re-implement btrfs_readdir(). Along this rework, some small corner cases fixed: - Subvolume tree mtime Mtime of a subvolume tree is recorded in its root item, since there is no INODE_ITEM for it. This needs extra search from tree root. - Output the unknown type If the DIR_ITEM is corrupted, at least don't try to access the memory out of boundary. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.c| 157 +++- fs/btrfs/btrfs.h| 5 -- fs/btrfs/ctree.h| 5 ++ fs/btrfs/dir-item.c | 68 +++ 4 files changed, 144 insertions(+), 91 deletions(-) diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index c967c114cc..2278b52e4d 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -16,67 +16,102 @@ struct btrfs_info btrfs_info; struct btrfs_fs_info *current_fs_info; -static int readdir_callback(const struct __btrfs_root *root, - struct btrfs_dir_item *item) +static int show_dir(struct btrfs_root *root, struct extent_buffer *eb, + struct btrfs_dir_item *di) { - static const char typestr[BTRFS_FT_MAX][4] = { - [BTRFS_FT_UNKNOWN] = " ? ", - [BTRFS_FT_REG_FILE] = " ", - [BTRFS_FT_DIR] = "DIR", - [BTRFS_FT_CHRDEV] = "CHR", - [BTRFS_FT_BLKDEV] = "BLK", - [BTRFS_FT_FIFO] = "FIF", - [BTRFS_FT_SOCK] = "SCK", - [BTRFS_FT_SYMLINK] = "SYM", - [BTRFS_FT_XATTR]= " ? ", + struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_inode_item ii; + struct btrfs_key key; + static const char* dir_item_str[] = { + [BTRFS_FT_REG_FILE] = "FILE", + [BTRFS_FT_DIR] = "DIR", + [BTRFS_FT_CHRDEV] = "CHRDEV", + [BTRFS_FT_BLKDEV] = "BLKDEV", + [BTRFS_FT_FIFO] = "FIFO", + [BTRFS_FT_SOCK] = "SOCK", + [BTRFS_FT_SYMLINK] = "SYMLINK", + [BTRFS_FT_XATTR]= "XATTR" }; - struct btrfs_inode_item inode; - const char *name = (const char *) (item + 1); - char filetime[32], *target = NULL; + u8 type = btrfs_dir_type(eb, di); + char namebuf[BTRFS_NAME_LEN]; + char *target = NULL; + char filetime[32]; time_t mtime; + int ret; - if (__btrfs_lookup_inode(root, (struct btrfs_key *)&item->location, - &inode, NULL)) { - printf("%s: Cannot find inode item for directory entry %.*s!\n", - __func__, item->name_len, name); - return 0; - } - - mtime = inode.mtime.sec; - ctime_r(&mtime, filetime); + btrfs_dir_item_key_to_cpu(eb, di, &key); - if (item->type == BTRFS_FT_SYMLINK) { - target = malloc(min(inode.size + 1, - (u64) btrfs_info.sb.sectorsize)); + if (key.type == BTRFS_ROOT_ITEM_KEY) { + struct btrfs_root *subvol; - if (target && __btrfs_readlink(root, item->location.objectid, -target)) { - free(target); - target = NULL; + /* It's a subvolume, get its mtime from root item */ + subvol = btrfs_read_fs_root(fs_info, &key); + if (IS_ERR(subvol)) { + ret = PTR_ERR(subvol); + error("Can't find root %llu", key.objectid); + return ret; } + mtime = btrfs_stack_timespec_sec(&subvol->root_item.otime); + } else { + struct btrfs_path path; + + /* It's regular inode, get its mtime from inode item */ + btrfs_init_path(&path); + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); + if (ret > 0) + ret = -ENOENT; + if (ret < 0) { + error("Can't find inode %llu", key.objectid); + btrfs_release_path(&path); + return ret; + } + read_extent_buffer(path.nodes[0], &ii, + btrfs_item_ptr_offset(path.nodes[0], path.slots[0]), + sizeof(ii)); + btrfs_release_path(&path); + mtime = btrfs_stack_timespec_sec(&ii.mtime); + } + ctime_r(&mtime, filetime); - if (!target) - printf("%s: Cannot read symlink target!\n", __func__); + if (type == BTRFS_FT_SYMLINK) { + target = malloc(fs_info->sectorsize); + if (!target) { + error("Can't alloc memory for symlink %llu", +
[PATCH U-BOOT v3 22/30] fs: btrfs: Rename btrfs_file_read() and its callees to avoid name conflicts
From: Qu Wenruo Rename btrfs_file_read() and its callees to avoid name conflicts with the incoming new code. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.c | 2 +- fs/btrfs/btrfs.h | 6 +++--- fs/btrfs/extent-io.c | 4 ++-- fs/btrfs/inode.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index aec91a57ec..7eb01c4ff9 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -277,7 +277,7 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, if (len > inode.size - offset) len = inode.size - offset; - rd = btrfs_file_read(&root, inr, offset, len, buf); + rd = __btrfs_file_read(&root, inr, offset, len, buf); if (rd == -1ULL) { printf("An error occured while reading file %s\n", file); return -1; diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index e36bd89827..32ea2fc53a 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -58,16 +58,16 @@ int __btrfs_readlink(const struct __btrfs_root *, u64, char *); int btrfs_readlink(struct btrfs_root *root, u64 ino, char *target); u64 __btrfs_lookup_path(struct __btrfs_root *, u64, const char *, u8 *, struct btrfs_inode_item *, int); -u64 btrfs_file_read(const struct __btrfs_root *, u64, u64, u64, char *); +u64 __btrfs_file_read(const struct __btrfs_root *, u64, u64, u64, char *); /* subvolume.c */ u64 btrfs_get_default_subvol_objectid(void); /* extent-io.c */ -u64 btrfs_read_extent_inline(struct __btrfs_path *, +u64 __btrfs_read_extent_inline(struct __btrfs_path *, struct btrfs_file_extent_item *, u64, u64, char *); -u64 btrfs_read_extent_reg(struct __btrfs_path *, struct btrfs_file_extent_item *, +u64 __btrfs_read_extent_reg(struct __btrfs_path *, struct btrfs_file_extent_item *, u64, u64, char *); #endif /* !__BTRFS_BTRFS_H__ */ diff --git a/fs/btrfs/extent-io.c b/fs/btrfs/extent-io.c index a524145a66..ccf4da3177 100644 --- a/fs/btrfs/extent-io.c +++ b/fs/btrfs/extent-io.c @@ -14,7 +14,7 @@ #include "extent-io.h" #include "disk-io.h" -u64 btrfs_read_extent_inline(struct __btrfs_path *path, +u64 __btrfs_read_extent_inline(struct __btrfs_path *path, struct btrfs_file_extent_item *extent, u64 offset, u64 size, char *out) { @@ -66,7 +66,7 @@ err: return -1ULL; } -u64 btrfs_read_extent_reg(struct __btrfs_path *path, +u64 __btrfs_read_extent_reg(struct __btrfs_path *path, struct btrfs_file_extent_item *extent, u64 offset, u64 size, char *out) { diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2e3fcad5a8..83d21467d9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -598,7 +598,7 @@ u64 __btrfs_lookup_path(struct __btrfs_root *root, u64 inr, const char *path, return inr; } -u64 btrfs_file_read(const struct __btrfs_root *root, u64 inr, u64 offset, +u64 __btrfs_file_read(const struct __btrfs_root *root, u64 inr, u64 offset, u64 size, char *buf) { struct __btrfs_path path; @@ -633,11 +633,11 @@ u64 btrfs_file_read(const struct __btrfs_root *root, u64 inr, u64 offset, if (extent->type == BTRFS_FILE_EXTENT_INLINE) { btrfs_file_extent_item_to_cpu_inl(extent); - rd = btrfs_read_extent_inline(&path, extent, offset, + rd = __btrfs_read_extent_inline(&path, extent, offset, size, buf); } else { btrfs_file_extent_item_to_cpu(extent); - rd = btrfs_read_extent_reg(&path, extent, offset, size, + rd = __btrfs_read_extent_reg(&path, extent, offset, size, buf); } -- 2.26.2
[PATCH U-BOOT v3 07/30] fs: btrfs: Crossport structure accessor into ctree.h
From: Qu Wenruo This brings all structure accessors from btrfs-progs/ctree.h, as in kernel's ctree.h. All these accessors handle the endian convert at runtime, and since all of them are defined as static inline functions, those which aren't used won't take space in resulting binary. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/compat.h | 14 + fs/btrfs/ctree.h | 1136 fs/btrfs/disk-io.h |9 - 3 files changed, 1064 insertions(+), 95 deletions(-) diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h index e7d7dc9f6e..2bbe97779e 100644 --- a/fs/btrfs/compat.h +++ b/fs/btrfs/compat.h @@ -29,6 +29,20 @@ static inline void error(const char *fmt, ...) #define cpu_to_le8(v) (v) #define __le8 u8 +/* + * Macros to generate set/get funcs for the struct fields + * assume there is a lefoo_to_cpu for every type, so lets make a simple + * one for u8: + */ +#define le8_to_cpu(v) (v) +#define cpu_to_le8(v) (v) +#define __le8 u8 + +#define get_unaligned_le8(p) (*((u8 *)(p))) +#define get_unaligned_8(p) (*((u8 *)(p))) +#define put_unaligned_le8(val,p) ((*((u8 *)(p))) = (val)) +#define put_unaligned_8(val,p) ((*((u8 *)(p))) = (val)) + /* * Read data from device specified by @desc and @part * diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index c7528d1ac3..a09587233e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -12,7 +12,10 @@ #include #include #include +#include +#include #include "kernel-shared/btrfs_tree.h" +#include "crypto/hash.h" #include "compat.h" #include "extent-io.h" @@ -34,6 +37,20 @@ /* four bytes for CRC32 */ #define BTRFS_EMPTY_DIR_SIZE 0 +struct btrfs_mapping_tree { + struct cache_tree cache_tree; +}; + +static inline unsigned long btrfs_chunk_item_size(int num_stripes) +{ + BUG_ON(num_stripes == 0); + return sizeof(struct btrfs_chunk) + + sizeof(struct btrfs_stripe) * (num_stripes - 1); +} + +#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) +#define BTRFS_LEAF_DATA_SIZE(fs_info) \ + (__BTRFS_LEAF_DATA_SIZE(fs_info->nodesize)) /* ioprio of readahead is set to idle */ #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)) @@ -41,6 +58,35 @@ #define BTRFS_MAX_EXTENT_SIZE SZ_128M +struct btrfs_device; +struct btrfs_fs_devices; +struct btrfs_fs_info { + u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; + u8 *new_chunk_tree_uuid; + struct btrfs_root *fs_root; + struct btrfs_root *tree_root; + struct btrfs_root *chunk_root; + struct btrfs_root *csum_root; + + struct rb_root fs_root_tree; + + struct extent_io_tree extent_cache; + + /* logical->physical extent mapping */ + struct btrfs_mapping_tree mapping_tree; + + u64 last_trans_committed; + + struct btrfs_super_block *super_copy; + + struct btrfs_fs_devices *fs_devices; + + /* Cached block sizes */ + u32 nodesize; + u32 sectorsize; + u32 stripesize; +}; + /* * File system states */ @@ -62,6 +108,35 @@ offsetof(type, member), \ sizeof(((type *)0)->member))) +#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits)\ +static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ +{ \ + const struct btrfs_header *h = (struct btrfs_header *)eb->data; \ + return le##bits##_to_cpu(h->member);\ +} \ +static inline void btrfs_set_##name(struct extent_buffer *eb, \ + u##bits val)\ +{ \ + struct btrfs_header *h = (struct btrfs_header *)eb->data; \ + h->member = cpu_to_le##bits(val); \ +} + +#define BTRFS_SETGET_FUNCS(name, type, member, bits) \ +static inline u##bits btrfs_##name(const struct extent_buffer *eb, \ + const type *s) \ +{ \ + unsigned long offset = (unsigned long)s;\ + const type *p = (type *) (eb->data + offset); \ + return get_unaligned_le##bits(&p->member); \ +} \ +static inline void btrfs_set_##name(struct extent_buffer *eb, \ + type *s, u##bits val) \ +{ \ + unsigned long offset = (unsigned long)s;\ + type *p = (type *) (eb->data + offset);
[PATCH U-BOOT v3 13/30] fs: btrfs: Crossport btrfs_search_slot() from btrfs-progs
From: Qu Wenruo This patch copies the core function, btrfs_search_slot(), from btrfs-progs. This version has the following functionality removed: - The ability to COW tree block Related code is commented out, and can be enabled in the future. - The readahead functionality This is abused in kernel. Remove it completely. With the core function in place, btrfs developers should feel at home now. This also crossports supporting code like btrfs_previous_item() to ctree.[ch]. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/ctree.c | 537 ++- fs/btrfs/ctree.h | 61 +- 2 files changed, 591 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 2956fe2cea..98c08d353a 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -5,10 +5,12 @@ * 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz */ -#include "btrfs.h" +#include #include #include #include +#include "btrfs.h" +#include "disk-io.h" static const struct btrfs_csum { u16 size; @@ -42,6 +44,32 @@ u16 btrfs_csum_type_size(u16 csum_type) return btrfs_csums[csum_type].size; } +struct btrfs_path *btrfs_alloc_path(void) +{ + struct btrfs_path *path; + path = kzalloc(sizeof(struct btrfs_path), GFP_NOFS); + return path; +} + +void btrfs_free_path(struct btrfs_path *p) +{ + if (!p) + return; + btrfs_release_path(p); + kfree(p); +} + +void btrfs_release_path(struct btrfs_path *p) +{ + int i; + for (i = 0; i < BTRFS_MAX_LEVEL; i++) { + if (!p->nodes[i]) + continue; + free_extent_buffer(p->nodes[i]); + } + memset(p, 0, sizeof(*p)); +} + int __btrfs_comp_keys(struct btrfs_key *a, struct btrfs_key *b) { if (a->objectid > b->objectid) @@ -72,7 +100,17 @@ int btrfs_comp_keys_type(struct btrfs_key *a, struct btrfs_key *b) return 0; } -static int generic_bin_search(void *addr, int item_size, struct btrfs_key *key, +/* + * search for key in the extent_buffer. The items start at offset p, + * and they are item_size apart. There are 'max' items in p. + * + * the slot in the array is returned via slot, and it points to + * the place where you would insert key if it is not found in + * the array. + * + * slot may point to max if the key is bigger than all of the keys + */ +static int __generic_bin_search(void *addr, int item_size, struct btrfs_key *key, int max, int *slot) { int low = 0, high = max, mid, ret; @@ -98,8 +136,8 @@ static int generic_bin_search(void *addr, int item_size, struct btrfs_key *key, return 1; } -int btrfs_bin_search(union btrfs_tree_node *p, struct btrfs_key *key, -int *slot) +int __btrfs_bin_search(union btrfs_tree_node *p, struct btrfs_key *key, + int *slot) { void *addr; unsigned long size; @@ -112,7 +150,7 @@ int btrfs_bin_search(union btrfs_tree_node *p, struct btrfs_key *key, size = sizeof(struct btrfs_item); } - return generic_bin_search(addr, size, key, p->header.nritems, slot); + return __generic_bin_search(addr, size, key, p->header.nritems, slot); } static void clear_path(struct __btrfs_path *p) @@ -209,7 +247,7 @@ int btrfs_search_tree(const struct __btrfs_root *root, struct btrfs_key *key, } prev_lvl = lvl; - ret = btrfs_bin_search(buf, key, &slot); + ret = __btrfs_bin_search(buf, key, &slot); if (ret < 0) goto err; if (ret && slot > 0 && lvl) @@ -464,6 +502,349 @@ fail: return ret; } +static int noinline check_block(struct btrfs_fs_info *fs_info, + struct btrfs_path *path, int level) +{ + struct btrfs_disk_key key; + struct btrfs_disk_key *key_ptr = NULL; + struct extent_buffer *parent; + enum btrfs_tree_block_status ret; + + if (path->nodes[level + 1]) { + parent = path->nodes[level + 1]; + btrfs_node_key(parent, &key, path->slots[level + 1]); + key_ptr = &key; + } + if (level == 0) + ret = btrfs_check_leaf(fs_info, key_ptr, path->nodes[0]); + else + ret = btrfs_check_node(fs_info, key_ptr, path->nodes[level]); + if (ret == BTRFS_TREE_BLOCK_CLEAN) + return 0; + return -EIO; +} + +/* + * search for key in the extent_buffer. The items start at offset p, + * and they are item_size apart. There are 'max' items in p. + * + * the slot in the array is returned via slot, and it points to + * the place where you would insert key if it is not found in + * the array. + * + * slot may point to max if the key is bigger than all of the keys + */ +static int generic_bin_search(struct extent_buffer *eb, unsigned long p, +
[PATCH U-BOOT v3 08/30] fs: btrfs: Crossport volumes.[ch] from btrfs-progs
From: Qu Wenruo This patch crossports volumes.[ch] from btrfs-progs, including: - btrfs_map_block() The core mechanism to map btrfs logical address to physical address. This version includes multi-device support, along with RAID56 support. - btrfs_scan_one_device() This is the function to register one btrfs device to the list. This is the main part of the multi-device btrfs assembling process. Although we're not going to support multiple devices until U-Boot allows us to scan one device without actually opening it. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/Makefile | 2 +- fs/btrfs/compat.h | 5 + fs/btrfs/ctree.h | 1 + fs/btrfs/volumes.c | 872 + fs/btrfs/volumes.h | 202 +++ 5 files changed, 1081 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/volumes.c create mode 100644 fs/btrfs/volumes.h diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 53be6e8835..ec30aae765 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -4,4 +4,4 @@ obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o \ - common/rbtree-utils.o extent-cache.o + common/rbtree-utils.o extent-cache.o volumes.o diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h index 2bbe97779e..b6b75deb3e 100644 --- a/fs/btrfs/compat.h +++ b/fs/btrfs/compat.h @@ -74,4 +74,9 @@ static inline void uuid_unparse(const u8 *uuid, char *out) return uuid_bin_to_str((unsigned char *)uuid, out, 0); } +static inline int is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} + #endif diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a09587233e..c746d3fd45 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include "kernel-shared/btrfs_tree.h" diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c new file mode 100644 index 00..7c72c4267f --- /dev/null +++ b/fs/btrfs/volumes.c @@ -0,0 +1,872 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include +#include +#include +#include "ctree.h" +#include "disk-io.h" +#include "volumes.h" + +const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { + [BTRFS_RAID_RAID10] = { + .sub_stripes= 2, + .dev_stripes= 1, + .devs_max = 0,/* 0 == as many as possible */ + .devs_min = 4, + .tolerated_failures = 1, + .devs_increment = 2, + .ncopies= 2, + .nparity= 0, + .raid_name = "raid10", + .bg_flag= BTRFS_BLOCK_GROUP_RAID10, + }, + [BTRFS_RAID_RAID1] = { + .sub_stripes= 1, + .dev_stripes= 1, + .devs_max = 2, + .devs_min = 2, + .tolerated_failures = 1, + .devs_increment = 2, + .ncopies= 2, + .nparity= 0, + .raid_name = "raid1", + .bg_flag= BTRFS_BLOCK_GROUP_RAID1, + }, + [BTRFS_RAID_RAID1C3] = { + .sub_stripes= 1, + .dev_stripes= 1, + .devs_max = 3, + .devs_min = 3, + .tolerated_failures = 2, + .devs_increment = 3, + .ncopies= 3, + .raid_name = "raid1c3", + .bg_flag= BTRFS_BLOCK_GROUP_RAID1C3, + }, + [BTRFS_RAID_RAID1C4] = { + .sub_stripes= 1, + .dev_stripes= 1, + .devs_max = 4, + .devs_min = 4, + .tolerated_failures = 3, + .devs_increment = 4, + .ncopies= 4, + .raid_name = "raid1c4", + .bg_flag= BTRFS_BLOCK_GROUP_RAID1C4, + }, + [BTRFS_RAID_DUP] = { + .sub_stripes= 1, + .dev_stripes= 2, + .devs_max = 1, + .devs_min = 1, + .tolerated_failures = 0, + .devs_increment = 1, + .ncopies= 2, + .nparity= 0, + .raid_name = "dup", + .bg_flag= BTRFS_BLOCK_GROUP_DUP, + }, + [BTRFS_RAID_RAID0] = { + .sub_stripes= 1, + .dev_stripes= 1, + .devs_max = 0, + .devs_min = 2, + .tolerated_failures = 0, + .devs_increment = 1, + .ncopies= 1, + .nparity= 0, + .raid_name = "raid0", + .bg_flag= BTRFS_BLOCK_GROUP_RAID0, + }, + [BTRFS_RAID_SINGLE] = {
[PATCH U-BOOT v3 10/30] fs: btrfs: Rename struct btrfs_path to struct __btrfs_path
From: Qu Wenruo To avoid name conflicting between the extent buffer based btrfs_path from btrfs-progs, rename struct btrfs_path to struct __btrfs_path. Also rename btrfs_free_path() to __btrfs_free_path() to avoid conflicts. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.h | 4 ++-- fs/btrfs/chunk-map.c | 4 ++-- fs/btrfs/ctree.c | 16 fs/btrfs/ctree.h | 20 ++-- fs/btrfs/dir-item.c | 10 +- fs/btrfs/extent-io.c | 4 ++-- fs/btrfs/inode.c | 16 fs/btrfs/root.c | 10 +- fs/btrfs/subvolume.c | 4 ++-- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index 1aacbc8cbb..a52fd34489 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -67,10 +67,10 @@ u64 btrfs_file_read(const struct btrfs_root *, u64, u64, u64, char *); u64 btrfs_get_default_subvol_objectid(void); /* extent-io.c */ -u64 btrfs_read_extent_inline(struct btrfs_path *, +u64 btrfs_read_extent_inline(struct __btrfs_path *, struct btrfs_file_extent_item *, u64, u64, char *); -u64 btrfs_read_extent_reg(struct btrfs_path *, struct btrfs_file_extent_item *, +u64 btrfs_read_extent_reg(struct __btrfs_path *, struct btrfs_file_extent_item *, u64, u64, char *); #endif /* !__BTRFS_BTRFS_H__ */ diff --git a/fs/btrfs/chunk-map.c b/fs/btrfs/chunk-map.c index 2e5be65067..8e3d13c4a9 100644 --- a/fs/btrfs/chunk-map.c +++ b/fs/btrfs/chunk-map.c @@ -144,7 +144,7 @@ int btrfs_chunk_map_init(void) int btrfs_read_chunk_tree(void) { - struct btrfs_path path; + struct __btrfs_path path; struct btrfs_key key, *found_key; struct btrfs_chunk *chunk; int res = 0; @@ -169,7 +169,7 @@ int btrfs_read_chunk_tree(void) } } while (!(res = btrfs_next_slot(&path))); - btrfs_free_path(&path); + __btrfs_free_path(&path); if (res < 0) return -1; diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index d97e195e5e..7bd12c2a1b 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -115,7 +115,7 @@ int btrfs_bin_search(union btrfs_tree_node *p, struct btrfs_key *key, return generic_bin_search(addr, size, key, p->header.nritems, slot); } -static void clear_path(struct btrfs_path *p) +static void clear_path(struct __btrfs_path *p) { int i; @@ -125,7 +125,7 @@ static void clear_path(struct btrfs_path *p) } } -void btrfs_free_path(struct btrfs_path *p) +void __btrfs_free_path(struct __btrfs_path *p) { int i; @@ -182,7 +182,7 @@ static int read_tree_node(u64 physical, union btrfs_tree_node **buf) } int btrfs_search_tree(const struct btrfs_root *root, struct btrfs_key *key, - struct btrfs_path *p) + struct __btrfs_path *p) { u8 lvl, prev_lvl; int i, slot, ret; @@ -236,13 +236,13 @@ int btrfs_search_tree(const struct btrfs_root *root, struct btrfs_key *key, return 0; err: - btrfs_free_path(p); + __btrfs_free_path(p); return -1; } -static int jump_leaf(struct btrfs_path *path, int dir) +static int jump_leaf(struct __btrfs_path *path, int dir) { - struct btrfs_path p; + struct __btrfs_path p; u32 slot; int level = 1, from_level, i; @@ -302,7 +302,7 @@ err: return -1; } -int btrfs_prev_slot(struct btrfs_path *p) +int btrfs_prev_slot(struct __btrfs_path *p) { if (!p->slots[0]) return jump_leaf(p, -1); @@ -311,7 +311,7 @@ int btrfs_prev_slot(struct btrfs_path *p) return 0; } -int btrfs_next_slot(struct btrfs_path *p) +int btrfs_next_slot(struct __btrfs_path *p) { struct btrfs_leaf *leaf = &p->nodes[0]->leaf; diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 7f024c0145..4562be9381 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1177,7 +1177,7 @@ union btrfs_tree_node { struct btrfs_node node; }; -struct btrfs_path { +struct __btrfs_path { union btrfs_tree_node *nodes[BTRFS_MAX_LEVEL]; u32 slots[BTRFS_MAX_LEVEL]; }; @@ -1191,20 +1191,20 @@ struct btrfs_root { int __btrfs_comp_keys(struct btrfs_key *, struct btrfs_key *); int btrfs_comp_keys_type(struct btrfs_key *, struct btrfs_key *); int btrfs_bin_search(union btrfs_tree_node *, struct btrfs_key *, int *); -void btrfs_free_path(struct btrfs_path *); +void __btrfs_free_path(struct __btrfs_path *); int btrfs_search_tree(const struct btrfs_root *, struct btrfs_key *, - struct btrfs_path *); -int btrfs_prev_slot(struct btrfs_path *); -int btrfs_next_slot(struct btrfs_path *); + struct __btrfs_path *); +int btrfs_prev_slot(struct __btrfs_path *); +int btrfs_next_slot(struct __btrfs_path *); -static inline struct btrfs_key *btrfs_path_leaf_key(struct btrfs_path *p) { +static inl
[PATCH U-BOOT v3 11/30] fs: btrfs: Rename btrfs_root to __btrfs_root
From: Qu Wenruo This is to avoid naming conflicts between extent buffer based btrfs_root. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.c | 10 +- fs/btrfs/btrfs.h | 26 +- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 6 +++--- fs/btrfs/dir-item.c | 4 ++-- fs/btrfs/inode.c | 16 fs/btrfs/root.c | 2 +- fs/btrfs/subvolume.c | 2 +- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index 78a32497b5..b4535c9551 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -15,7 +15,7 @@ struct btrfs_info btrfs_info; -static int readdir_callback(const struct btrfs_root *root, +static int readdir_callback(const struct __btrfs_root *root, struct btrfs_dir_item *item) { static const char typestr[BTRFS_FT_MAX][4] = { @@ -116,7 +116,7 @@ int btrfs_probe(struct blk_desc *fs_dev_desc, int btrfs_ls(const char *path) { - struct btrfs_root root = btrfs_info.fs_root; + struct __btrfs_root root = btrfs_info.fs_root; u64 inr; u8 type; @@ -142,7 +142,7 @@ int btrfs_ls(const char *path) int btrfs_exists(const char *file) { - struct btrfs_root root = btrfs_info.fs_root; + struct __btrfs_root root = btrfs_info.fs_root; u64 inr; u8 type; @@ -153,7 +153,7 @@ int btrfs_exists(const char *file) int btrfs_size(const char *file, loff_t *size) { - struct btrfs_root root = btrfs_info.fs_root; + struct __btrfs_root root = btrfs_info.fs_root; struct btrfs_inode_item inode; u64 inr; u8 type; @@ -178,7 +178,7 @@ int btrfs_size(const char *file, loff_t *size) int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, loff_t *actread) { - struct btrfs_root root = btrfs_info.fs_root; + struct __btrfs_root root = btrfs_info.fs_root; struct btrfs_inode_item inode; u64 inr, rd; u8 type; diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index a52fd34489..ae29226e9a 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -14,9 +14,9 @@ struct btrfs_info { struct btrfs_super_block sb; - struct btrfs_root tree_root; - struct btrfs_root fs_root; - struct btrfs_root chunk_root; + struct __btrfs_root tree_root; + struct __btrfs_root fs_root; + struct __btrfs_root chunk_root; struct rb_root chunks_root; }; @@ -42,26 +42,26 @@ u32 btrfs_decompress(u8 type, const char *, u32, char *, u32); int btrfs_read_superblock(void); /* dir-item.c */ -typedef int (*btrfs_readdir_callback_t)(const struct btrfs_root *, +typedef int (*btrfs_readdir_callback_t)(const struct __btrfs_root *, struct btrfs_dir_item *); -int btrfs_lookup_dir_item(const struct btrfs_root *, u64, const char *, int, +int btrfs_lookup_dir_item(const struct __btrfs_root *, u64, const char *, int, struct btrfs_dir_item *); -int btrfs_readdir(const struct btrfs_root *, u64, btrfs_readdir_callback_t); +int btrfs_readdir(const struct __btrfs_root *, u64, btrfs_readdir_callback_t); /* root.c */ -int btrfs_find_root(u64, struct btrfs_root *, struct btrfs_root_item *); +int btrfs_find_root(u64, struct __btrfs_root *, struct btrfs_root_item *); u64 btrfs_lookup_root_ref(u64, struct btrfs_root_ref *, char *); /* inode.c */ -u64 btrfs_lookup_inode_ref(struct btrfs_root *, u64, struct btrfs_inode_ref *, +u64 btrfs_lookup_inode_ref(struct __btrfs_root *, u64, struct btrfs_inode_ref *, char *); -int btrfs_lookup_inode(const struct btrfs_root *, struct btrfs_key *, - struct btrfs_inode_item *, struct btrfs_root *); -int btrfs_readlink(const struct btrfs_root *, u64, char *); -u64 btrfs_lookup_path(struct btrfs_root *, u64, const char *, u8 *, +int btrfs_lookup_inode(const struct __btrfs_root *, struct btrfs_key *, + struct btrfs_inode_item *, struct __btrfs_root *); +int btrfs_readlink(const struct __btrfs_root *, u64, char *); +u64 btrfs_lookup_path(struct __btrfs_root *, u64, const char *, u8 *, struct btrfs_inode_item *, int); -u64 btrfs_file_read(const struct btrfs_root *, u64, u64, u64, char *); +u64 btrfs_file_read(const struct __btrfs_root *, u64, u64, u64, char *); /* subvolume.c */ u64 btrfs_get_default_subvol_objectid(void); diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 7bd12c2a1b..2956fe2cea 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -181,7 +181,7 @@ static int read_tree_node(u64 physical, union btrfs_tree_node **buf) return 0; } -int btrfs_search_tree(const struct btrfs_root *root, struct btrfs_key *key, +int btrfs_search_tree(const struct __btrfs_root *root, struct btrfs_key *key, struct __btrfs_path *p) { u8 lvl, prev_lvl; diff --git a/f
[PATCH U-BOOT v3 01/30] fs: btrfs: Sync btrfs_btree.h from kernel
From: Qu Wenruo This version includes all needed on-disk format from kernel. Only need to modify the include headers for U-Boot, everything else is untouched. Also, since U-Boot btrfs is using a different endian convert timing (at tree block read time), it needs some forced type conversion before proper crossport. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/btrfs.c|3 +- fs/btrfs/btrfs_tree.h | 766 --- fs/btrfs/ctree.h| 214 + fs/btrfs/inode.c|5 +- fs/btrfs/kernel-shared/btrfs_tree.h | 1333 +++ fs/btrfs/root.c |2 +- fs/btrfs/subvolume.c|2 +- 7 files changed, 1343 insertions(+), 982 deletions(-) delete mode 100644 fs/btrfs/btrfs_tree.h create mode 100644 fs/btrfs/kernel-shared/btrfs_tree.h diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index de16217d0d..9f2888bab3 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -32,7 +32,8 @@ static int readdir_callback(const struct btrfs_root *root, char filetime[32], *target = NULL; time_t mtime; - if (btrfs_lookup_inode(root, &item->location, &inode, NULL)) { + if (btrfs_lookup_inode(root, (struct btrfs_key *)&item->location, + &inode, NULL)) { printf("%s: Cannot find inode item for directory entry %.*s!\n", __func__, item->name_len, name); return 0; diff --git a/fs/btrfs/btrfs_tree.h b/fs/btrfs/btrfs_tree.h deleted file mode 100644 index aa0f3d6c86..00 --- a/fs/btrfs/btrfs_tree.h +++ /dev/null @@ -1,766 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * From linux/include/uapi/linux/btrfs_tree.h - */ - -#ifndef __BTRFS_BTRFS_TREE_H__ -#define __BTRFS_BTRFS_TREE_H__ - -#include - -#define BTRFS_VOL_NAME_MAX 255 -#define BTRFS_NAME_MAX 255 -#define BTRFS_LABEL_SIZE 256 -#define BTRFS_FSID_SIZE 16 -#define BTRFS_UUID_SIZE 16 - -/* - * This header contains the structure definitions and constants used - * by file system objects that can be retrieved using - * the BTRFS_IOC_SEARCH_TREE ioctl. That means basically anything that - * is needed to describe a leaf node's key or item contents. - */ - -/* holds pointers to all of the tree roots */ -#define BTRFS_ROOT_TREE_OBJECTID 1ULL - -/* stores information about which extents are in use, and reference counts */ -#define BTRFS_EXTENT_TREE_OBJECTID 2ULL - -/* - * chunk tree stores translations from logical -> physical block numbering - * the super block points to the chunk tree - */ -#define BTRFS_CHUNK_TREE_OBJECTID 3ULL - -/* - * stores information about which areas of a given device are in use. - * one per device. The tree of tree roots points to the device tree - */ -#define BTRFS_DEV_TREE_OBJECTID 4ULL - -/* one per subvolume, storing files and directories */ -#define BTRFS_FS_TREE_OBJECTID 5ULL - -/* directory objectid inside the root tree */ -#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL - -/* holds checksums of all the data extents */ -#define BTRFS_CSUM_TREE_OBJECTID 7ULL - -/* holds quota configuration and tracking */ -#define BTRFS_QUOTA_TREE_OBJECTID 8ULL - -/* for storing items that use the BTRFS_UUID_KEY* types */ -#define BTRFS_UUID_TREE_OBJECTID 9ULL - -/* tracks free space in block groups. */ -#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL - -/* device stats in the device tree */ -#define BTRFS_DEV_STATS_OBJECTID 0ULL - -/* for storing balance parameters in the root tree */ -#define BTRFS_BALANCE_OBJECTID -4ULL - -/* orhpan objectid for tracking unlinked/truncated files */ -#define BTRFS_ORPHAN_OBJECTID -5ULL - -/* does write ahead logging to speed up fsyncs */ -#define BTRFS_TREE_LOG_OBJECTID -6ULL -#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL - -/* for space balancing */ -#define BTRFS_TREE_RELOC_OBJECTID -8ULL -#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL - -/* - * extent checksums all have this objectid - * this allows them to share the logging tree - * for fsyncs - */ -#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL - -/* For storing free space cache */ -#define BTRFS_FREE_SPACE_OBJECTID -11ULL - -/* - * The inode number assigned to the special inode for storing - * free ino cache - */ -#define BTRFS_FREE_INO_OBJECTID -12ULL - -/* dummy objectid represents multiple objectids */ -#define BTRFS_MULTIPLE_OBJECTIDS -255ULL - -/* - * All files have objectids in this range. - */ -#define BTRFS_FIRST_FREE_OBJECTID 256ULL -#define BTRFS_LAST_FREE_OBJECTID -256ULL -#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL - - -/* - * the device items go into the chunk tree. The key is in the form - * [ 1 BTRFS_DEV_ITEM_KEY device_id ] - */ -#define BTRFS_DEV_ITEMS_OBJECTID 1ULL - -#define BTRFS_BTREE_INODE_OBJECTID 1 - -#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2 - -#define BTRFS_DEV_REPLACE_DEVID 0ULL - -/* - * inode items have the data typically returned from stat and store other - * info about object c
[PATCH U-BOOT v3 12/30] fs: btrfs: Crossport struct btrfs_root to ctree.h
From: Qu Wenruo Crossport struct btrfs_root to ctree.h from btrfs-progs, with write related members deleted. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/ctree.h | 17 + 1 file changed, 17 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 0aa6b49a65..e658c88aee 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -69,6 +69,23 @@ enum btrfs_tree_block_status { BTRFS_TREE_BLOCK_INVALID_OFFSETS, }; +struct btrfs_root { + struct extent_buffer *node; + struct btrfs_root_item root_item; + struct btrfs_key root_key; + struct btrfs_fs_info *fs_info; + u64 objectid; + u64 last_trans; + + int ref_cows; + int track_dirty; + + u32 type; + u64 last_inode_alloc; + + struct rb_node rb_node; +}; + struct btrfs_device; struct btrfs_fs_devices; struct btrfs_fs_info { -- 2.26.2
[PATCH U-BOOT v3 09/30] fs: btrfs: Crossport read_tree_block() from btrfs-progs
From: Qu Wenruo This is the one of the basic stone function for btrfs, which: - Resolves the chunk mappings - Reads data from disk - Does various sanity check With read_tree_block(), we can finally crossport needed btrfs btree operations to U-Boot. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/ctree.c | 188 +++- fs/btrfs/ctree.h | 50 ++- fs/btrfs/disk-io.c | 348 + fs/btrfs/disk-io.h | 18 ++- fs/btrfs/inode.c | 6 +- 5 files changed, 602 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 1d8f7e168f..d97e195e5e 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -42,7 +42,7 @@ u16 btrfs_csum_type_size(u16 csum_type) return btrfs_csums[csum_type].size; } -int btrfs_comp_keys(struct btrfs_key *a, struct btrfs_key *b) +int __btrfs_comp_keys(struct btrfs_key *a, struct btrfs_key *b) { if (a->objectid > b->objectid) return 1; @@ -82,7 +82,7 @@ static int generic_bin_search(void *addr, int item_size, struct btrfs_key *key, mid = (low + high) / 2; tmp = (struct btrfs_key *) ((u8 *) addr + mid*item_size); - ret = btrfs_comp_keys(tmp, key); + ret = __btrfs_comp_keys(tmp, key); if (ret < 0) { low = mid + 1; @@ -321,3 +321,187 @@ int btrfs_next_slot(struct btrfs_path *p) p->slots[0]++; return 0; } + +int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2) +{ + if (k1->objectid > k2->objectid) + return 1; + if (k1->objectid < k2->objectid) + return -1; + if (k1->type > k2->type) + return 1; + if (k1->type < k2->type) + return -1; + if (k1->offset > k2->offset) + return 1; + if (k1->offset < k2->offset) + return -1; + return 0; +} + +static int btrfs_comp_keys(struct btrfs_disk_key *disk, +const struct btrfs_key *k2) +{ + struct btrfs_key k1; + + btrfs_disk_key_to_cpu(&k1, disk); + return btrfs_comp_cpu_keys(&k1, k2); +} + +enum btrfs_tree_block_status +btrfs_check_node(struct btrfs_fs_info *fs_info, +struct btrfs_disk_key *parent_key, struct extent_buffer *buf) +{ + int i; + struct btrfs_key cpukey; + struct btrfs_disk_key key; + u32 nritems = btrfs_header_nritems(buf); + enum btrfs_tree_block_status ret = BTRFS_TREE_BLOCK_INVALID_NRITEMS; + + if (nritems == 0 || nritems > BTRFS_NODEPTRS_PER_BLOCK(fs_info)) + goto fail; + + ret = BTRFS_TREE_BLOCK_INVALID_PARENT_KEY; + if (parent_key && parent_key->type) { + btrfs_node_key(buf, &key, 0); + if (memcmp(parent_key, &key, sizeof(key))) + goto fail; + } + ret = BTRFS_TREE_BLOCK_BAD_KEY_ORDER; + for (i = 0; nritems > 1 && i < nritems - 2; i++) { + btrfs_node_key(buf, &key, i); + btrfs_node_key_to_cpu(buf, &cpukey, i + 1); + if (btrfs_comp_keys(&key, &cpukey) >= 0) + goto fail; + } + return BTRFS_TREE_BLOCK_CLEAN; +fail: + return ret; +} + +enum btrfs_tree_block_status +btrfs_check_leaf(struct btrfs_fs_info *fs_info, +struct btrfs_disk_key *parent_key, struct extent_buffer *buf) +{ + int i; + struct btrfs_key cpukey; + struct btrfs_disk_key key; + u32 nritems = btrfs_header_nritems(buf); + enum btrfs_tree_block_status ret = BTRFS_TREE_BLOCK_INVALID_NRITEMS; + + if (nritems * sizeof(struct btrfs_item) > buf->len) { + fprintf(stderr, "invalid number of items %llu\n", + (unsigned long long)buf->start); + goto fail; + } + + if (btrfs_header_level(buf) != 0) { + ret = BTRFS_TREE_BLOCK_INVALID_LEVEL; + fprintf(stderr, "leaf is not a leaf %llu\n", + (unsigned long long)btrfs_header_bytenr(buf)); + goto fail; + } + if (btrfs_leaf_free_space(buf) < 0) { + ret = BTRFS_TREE_BLOCK_INVALID_FREE_SPACE; + fprintf(stderr, "leaf free space incorrect %llu %d\n", + (unsigned long long)btrfs_header_bytenr(buf), + btrfs_leaf_free_space(buf)); + goto fail; + } + + if (nritems == 0) + return BTRFS_TREE_BLOCK_CLEAN; + + btrfs_item_key(buf, &key, 0); + if (parent_key && parent_key->type && + memcmp(parent_key, &key, sizeof(key))) { + ret = BTRFS_TREE_BLOCK_INVALID_PARENT_KEY; + fprintf(stderr, "leaf parent key incorrect %llu\n", + (unsigned long long)btrfs_header_bytenr(buf)); + goto fail; + } + fo
[PATCH U-BOOT v3 06/30] fs: btrfs: Crossport extent-io.[ch] from btrfs-progs
From: Qu Wenruo This brings the extent_io_tree infrastructure, with which we can finally bring in proper btrfs_fs_info structure to ctree.h. With read/write_extent_buffer() implemented we also backport read/write_eb_member() to ctree.h. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/ctree.h | 55 +++ fs/btrfs/extent-io.c | 801 ++- fs/btrfs/extent-io.h | 164 + 3 files changed, 1019 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/extent-io.h diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 02125e5e10..c7528d1ac3 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -11,8 +11,10 @@ #include #include +#include #include "kernel-shared/btrfs_tree.h" #include "compat.h" +#include "extent-io.h" #define BTRFS_MAX_MIRRORS 3 @@ -48,6 +50,18 @@ #define BTRFS_FS_STATE_DEV_REPLACING 3 #define BTRFS_FS_STATE_DUMMY_FS_INFO 4 +#define read_eb_member(eb, ptr, type, member, result) ( \ + read_extent_buffer(eb, (char *)(result),\ + ((unsigned long)(ptr)) + \ + offsetof(type, member), \ + sizeof(((type *)0)->member))) + +#define write_eb_member(eb, ptr, type, member, result) ( \ + write_extent_buffer(eb, (char *)(result), \ + ((unsigned long)(ptr)) + \ + offsetof(type, member), \ + sizeof(((type *)0)->member))) + #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ static inline u##bits btrfs_##name(const type *s) \ { \ @@ -75,6 +89,47 @@ struct btrfs_root { u64 root_dirid; }; +struct btrfs_mapping_tree { + struct cache_tree cache_tree; +}; + +struct btrfs_device; +struct btrfs_fs_info { + u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; + u8 *new_chunk_tree_uuid; + struct btrfs_root *fs_root; + struct btrfs_root *tree_root; + struct btrfs_root *chunk_root; + struct btrfs_root *csum_root; + + struct rb_root fs_root_tree; + + struct extent_io_tree extent_cache; + struct extent_io_tree free_space_cache; + struct extent_io_tree pinned_extents; + struct extent_io_tree extent_ins; + struct extent_io_tree *excluded_extents; + + struct rb_root block_group_cache_tree; + /* logical->physical extent mapping */ + struct btrfs_mapping_tree mapping_tree; + + u64 generation; + u64 last_trans_committed; + + struct btrfs_super_block *super_copy; + + u64 super_bytenr; + + /* Only support one device yet */ + struct btrfs_devvice *dev; + + /* Cached block sizes */ + u32 nodesize; + u32 sectorsize; + u32 stripesize; +}; + int btrfs_comp_keys(struct btrfs_key *, struct btrfs_key *); int btrfs_comp_keys_type(struct btrfs_key *, struct btrfs_key *); int btrfs_bin_search(union btrfs_tree_node *, struct btrfs_key *, int *); diff --git a/fs/btrfs/extent-io.c b/fs/btrfs/extent-io.c index 2e4599cf64..eec89d152e 100644 --- a/fs/btrfs/extent-io.c +++ b/fs/btrfs/extent-io.c @@ -5,9 +5,14 @@ * 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz */ -#include "btrfs.h" +#include +#include #include #include +#include "btrfs.h" +#include "ctree.h" +#include "extent-io.h" +#include "disk-io.h" u64 btrfs_read_extent_inline(struct btrfs_path *path, struct btrfs_file_extent_item *extent, u64 offset, @@ -124,3 +129,797 @@ err: free(cbuf); return -1ULL; } + +void extent_io_tree_init(struct extent_io_tree *tree) +{ + cache_tree_init(&tree->state); + cache_tree_init(&tree->cache); + tree->cache_size = 0; +} + +static struct extent_state *alloc_extent_state(void) +{ + struct extent_state *state; + + state = malloc(sizeof(*state)); + if (!state) + return NULL; + state->cache_node.objectid = 0; + state->refs = 1; + state->state = 0; + state->xprivate = 0; + return state; +} + +static void btrfs_free_extent_state(struct extent_state *state) +{ + state->refs--; + BUG_ON(state->refs < 0); + if (state->refs == 0) + free(state); +} + +static void free_extent_state_func(struct cache_extent *cache) +{ + struct extent_state *es; + + es = container_of(cache, struct extent_state, cache_node); + btrfs_free_extent_state(es); +} + +static void free_extent_buffer_final(struct extent_buffer *eb); +void extent_io_tree_cleanup(struct extent_io_tree *tree) +{ + cache_tree_free_extents(&tree->state, free_extent_state_func); +} + +static inline void update_extent_state(struct extent_state *state) +{ +
[PATCH U-BOOT v3 02/30] fs: btrfs: Add more checksum algorithms
From: Qu Wenruo This mostly crossports crypto/hash.[ch] from btrfs-progs. The differences are: - No blake2 support No blake2 related library in U-Boot yet. - Use uboot xxhash/sha256 directly No need to implement the code as U-Boot has already provided the interface. This adds the support for the following csums: - SHA256 - XXHASH Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/Makefile | 2 +- fs/btrfs/btrfs.c | 3 ++- fs/btrfs/btrfs.h | 11 - fs/btrfs/crypto/hash.c | 55 ++ fs/btrfs/crypto/hash.h | 17 + fs/btrfs/dir-item.c| 1 + fs/btrfs/disk-io.c | 22 + fs/btrfs/disk-io.h | 20 +++ fs/btrfs/hash.c| 38 - fs/btrfs/super.c | 23 +- 10 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 fs/btrfs/crypto/hash.c create mode 100644 fs/btrfs/crypto/hash.h create mode 100644 fs/btrfs/disk-io.c create mode 100644 fs/btrfs/disk-io.h delete mode 100644 fs/btrfs/hash.c diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 9b3159296f..84b3b5ec0e 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -3,4 +3,4 @@ # 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ - extent-io.o hash.o inode.o root.o subvolume.o super.o + extent-io.o inode.o root.o subvolume.o super.o crypto/hash.o disk-io.o diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index 9f2888bab3..d5a87c175c 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -5,11 +5,12 @@ * 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz */ -#include "btrfs.h" #include #include #include #include +#include "btrfs.h" +#include "crypto/hash.h" struct btrfs_info btrfs_info; diff --git a/fs/btrfs/btrfs.h b/fs/btrfs/btrfs.h index 25a8cf6a87..1aacbc8cbb 100644 --- a/fs/btrfs/btrfs.h +++ b/fs/btrfs/btrfs.h @@ -23,17 +23,6 @@ struct btrfs_info { extern struct btrfs_info btrfs_info; -/* hash.c */ -void btrfs_hash_init(void); -u32 btrfs_crc32c(u32, const void *, size_t); -u32 btrfs_csum_data(char *, u32, size_t); -void btrfs_csum_final(u32, void *); - -static inline u64 btrfs_name_hash(const char *name, int len) -{ - return btrfs_crc32c((u32) ~1, name, len); -} - /* dev.c */ extern struct blk_desc *btrfs_blk_desc; extern struct disk_partition *btrfs_part_info; diff --git a/fs/btrfs/crypto/hash.c b/fs/btrfs/crypto/hash.c new file mode 100644 index 00..fb51f6386c --- /dev/null +++ b/fs/btrfs/crypto/hash.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include + +static u32 btrfs_crc32c_table[256]; + +void btrfs_hash_init(void) +{ + static int inited = 0; + + if (!inited) { + crc32c_init(btrfs_crc32c_table, 0x82F63B78); + inited = 1; + } +} + +int hash_sha256(const u8 *buf, size_t length, u8 *out) +{ + sha256_context ctx; + + sha256_starts(&ctx); + sha256_update(&ctx, buf, length); + sha256_finish(&ctx, out); + + return 0; +} + +int hash_xxhash(const u8 *buf, size_t length, u8 *out) +{ + u64 hash; + + hash = xxh64(buf, length, 0); + put_unaligned_le64(hash, out); + + return 0; +} + +int hash_crc32c(const u8 *buf, size_t length, u8 *out) +{ + u32 crc; + + crc = crc32c_cal((u32)~0, (char *)buf, length, btrfs_crc32c_table); + put_unaligned_le32(~crc, out); + + return 0; +} + +u32 crc32c(u32 seed, const void * data, size_t len) +{ + return crc32c_cal(seed, data, len, btrfs_crc32c_table); +} diff --git a/fs/btrfs/crypto/hash.h b/fs/btrfs/crypto/hash.h new file mode 100644 index 00..d1ba1fa374 --- /dev/null +++ b/fs/btrfs/crypto/hash.h @@ -0,0 +1,17 @@ +#ifndef CRYPTO_HASH_H +#define CRYPTO_HASH_H + +#include + +#define CRYPTO_HASH_SIZE_MAX 32 + +void btrfs_hash_init(void); +int hash_crc32c(const u8 *buf, size_t length, u8 *out); +int hash_xxhash(const u8 *buf, size_t length, u8 *out); +int hash_sha256(const u8 *buf, size_t length, u8 *out); + +u32 crc32c(u32 seed, const void * data, size_t len); + +/* Blake2B is not yet supported due to lack of library */ + +#endif diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index 63b5bf0a86..1ff446a45a 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -6,6 +6,7 @@ */ #include "btrfs.h" +#include "disk-io.h" static int verify_dir_item(struct btrfs_dir_item *item, u32 start, u32 total) { diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c new file mode 100644 index 00..58c32b548e --- /dev/null +++ b/fs/btrfs/disk-io.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include +#include +#include "disk-io.h" +#include "crypto/hash.h" + +int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len) +{ + memset(out, 0, BTRFS_CSUM_SIZE); + + swit
[PATCH U-BOOT v3 03/30] fs: btrfs: Crossport btrfs_read_dev_super() from btrfs-progs
From: Qu Wenruo This patch uses generic code from btrfs-progs to read one super block from block device. To support the btrfs-progs coding style, the following is also crossported: - BTRFS_SETGET_FUNC for btrfs_super_block - btrfs_check_super() function - Move btrfs_read_superblock() to disk-io.[ch] Since super.c only contains pretty small amount of code, and the extra check will be covered in later root read patches. Differences between this implementation and btrfs-progs: - No sbflags/sb_bytenr support Since we only need to read the primary super block (like kernel), sbflags/sb_bytenr used by super block recovery is not needed. This also changes the following behavior of U-Boot btrfs: - Only reads the primary super block The old implementation reads all 3 super blocks, and also one non-existing backup. This is not correct, especially if there is another filesystem created on the device but old superblocks are not rewritten. Just like kernel, we only check the primary super block. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/Makefile | 2 +- fs/btrfs/btrfs.c | 1 + fs/btrfs/compat.h | 63 +++ fs/btrfs/ctree.c | 32 ++ fs/btrfs/ctree.h | 67 fs/btrfs/disk-io.c | 213 + fs/btrfs/disk-io.h | 7 ++ fs/btrfs/super.c | 258 - 8 files changed, 384 insertions(+), 259 deletions(-) create mode 100644 fs/btrfs/compat.h delete mode 100644 fs/btrfs/super.c diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 84b3b5ec0e..bd4b848d1b 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -3,4 +3,4 @@ # 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ - extent-io.o inode.o root.o subvolume.o super.o crypto/hash.o disk-io.o + extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index d5a87c175c..78a32497b5 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -11,6 +11,7 @@ #include #include "btrfs.h" #include "crypto/hash.h" +#include "disk-io.h" struct btrfs_info btrfs_info; diff --git a/fs/btrfs/compat.h b/fs/btrfs/compat.h new file mode 100644 index 00..e7d7dc9f6e --- /dev/null +++ b/fs/btrfs/compat.h @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#ifndef __BTRFS_COMPAT_H__ +#define __BTRFS_COMPAT_H__ + +#include +#include +#include + +/* Provide a compatibility layer to make code syncing easier */ + +/* A simple wraper to for error() used in btrfs-progs */ +__attribute__((format (__printf__, 1, 2))) +static inline void error(const char *fmt, ...) +{ + printf("BTRFS: "); + printf(fmt, __builtin_va_arg_pack()); + printf("\n"); +} + +#define BTRFS_UUID_UNPARSED_SIZE 37 + +/* + * Macros to generate set/get funcs for the struct fields + * assume there is a lefoo_to_cpu for every type, so lets make a simple + * one for u8: + */ +#define le8_to_cpu(v) (v) +#define cpu_to_le8(v) (v) +#define __le8 u8 + +/* + * Read data from device specified by @desc and @part + * + * U-boot equivalent of pread(). + * + * Return the bytes of data read. + * Return <0 for error. + */ +static inline int __btrfs_devread(struct blk_desc *desc, + struct disk_partition *part, + void *buf, size_t size, u64 offset) +{ + lbaint_t sector; + int byte_offset; + int ret; + + sector = offset >> desc->log2blksz; + byte_offset = offset % desc->blksz; + + /* fs_devread() return 0 for error, >0 for success */ + ret = fs_devread(desc, part, sector, byte_offset, size, buf); + if (!ret) + return -EIO; + return size; +} + +static inline void uuid_unparse(const u8 *uuid, char *out) +{ + return uuid_bin_to_str((unsigned char *)uuid, out, 0); +} + +#endif diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 28f98d43ad..1d8f7e168f 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -10,6 +10,38 @@ #include #include +static const struct btrfs_csum { + u16 size; + const char name[14]; +} btrfs_csums[] = { + [BTRFS_CSUM_TYPE_CRC32] = { 4, "crc32c" }, + [BTRFS_CSUM_TYPE_XXHASH]= { 8, "xxhash64" }, + [BTRFS_CSUM_TYPE_SHA256]= { 32, "sha256" }, + [BTRFS_CSUM_TYPE_BLAKE2]= { 32, "blake2" }, +}; + +u16 btrfs_super_csum_size(const struct btrfs_super_block *sb) +{ + const u16 csum_type = btrfs_super_csum_type(sb); + + return btrfs_csums[csum_type].size; +} + +const char *btrfs_super_csum_name(u16 csum_type) +{ + return btrfs_csums[csum_type].name; +} + +size_t btrfs_super_num_csums(void) +{ + return ARRAY_SIZE(btrfs_csums); +} + +u16 btrfs_csum_type_size(u16 csum_type) +{ + return btrfs_csums[csum_type].size; +} + int btrfs_comp_keys(struct btrfs_key *a, struct
[PATCH U-BOOT v3 05/30] fs: btrfs: Crossport extent-cache.[ch] from btrfs-progs
From: Qu Wenruo This patch implements an infrastructure to insert/search/merge an extent range (with variable length). This provides the basis for later extent buffer cache used in btrfs. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/extent-cache.c | 318 fs/btrfs/extent-cache.h | 104 + 2 files changed, 422 insertions(+) create mode 100644 fs/btrfs/extent-cache.c create mode 100644 fs/btrfs/extent-cache.h diff --git a/fs/btrfs/extent-cache.c b/fs/btrfs/extent-cache.c new file mode 100644 index 00..bc8cf3a522 --- /dev/null +++ b/fs/btrfs/extent-cache.c @@ -0,0 +1,318 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/* + * Crossported from the same named file of btrfs-progs. + * + * Minor modification to include headers. + */ +#include +#include +#include +#include +#include +#include "extent-cache.h" +#include "common/rbtree-utils.h" + +struct cache_extent_search_range { + u64 objectid; + u64 start; + u64 size; +}; + +static int cache_tree_comp_range(struct rb_node *node, void *data) +{ + struct cache_extent *entry; + struct cache_extent_search_range *range; + + range = (struct cache_extent_search_range *)data; + entry = rb_entry(node, struct cache_extent, rb_node); + + if (entry->start + entry->size <= range->start) + return 1; + else if (range->start + range->size <= entry->start) + return -1; + else + return 0; +} + +static int cache_tree_comp_nodes(struct rb_node *node1, struct rb_node *node2) +{ + struct cache_extent *entry; + struct cache_extent_search_range range; + + entry = rb_entry(node2, struct cache_extent, rb_node); + range.start = entry->start; + range.size = entry->size; + + return cache_tree_comp_range(node1, (void *)&range); +} + +static int cache_tree_comp_range2(struct rb_node *node, void *data) +{ + struct cache_extent *entry; + struct cache_extent_search_range *range; + + range = (struct cache_extent_search_range *)data; + entry = rb_entry(node, struct cache_extent, rb_node); + + if (entry->objectid < range->objectid) + return 1; + else if (entry->objectid > range->objectid) + return -1; + else if (entry->start + entry->size <= range->start) + return 1; + else if (range->start + range->size <= entry->start) + return -1; + else + return 0; +} + +static int cache_tree_comp_nodes2(struct rb_node *node1, struct rb_node *node2) +{ + struct cache_extent *entry; + struct cache_extent_search_range range; + + entry = rb_entry(node2, struct cache_extent, rb_node); + range.objectid = entry->objectid; + range.start = entry->start; + range.size = entry->size; + + return cache_tree_comp_range2(node1, (void *)&range); +} + +void cache_tree_init(struct cache_tree *tree) +{ + tree->root = RB_ROOT; +} + +static struct cache_extent *alloc_cache_extent(u64 start, u64 size) +{ + struct cache_extent *pe = malloc(sizeof(*pe)); + + if (!pe) + return pe; + + pe->objectid = 0; + pe->start = start; + pe->size = size; + return pe; +} + +int add_cache_extent(struct cache_tree *tree, u64 start, u64 size) +{ + struct cache_extent *pe = alloc_cache_extent(start, size); + int ret; + + if (!pe) + return -ENOMEM; + + ret = insert_cache_extent(tree, pe); + if (ret) + free(pe); + + return ret; +} + +int insert_cache_extent(struct cache_tree *tree, struct cache_extent *pe) +{ + return rb_insert(&tree->root, &pe->rb_node, cache_tree_comp_nodes); +} + +int insert_cache_extent2(struct cache_tree *tree, struct cache_extent *pe) +{ + return rb_insert(&tree->root, &pe->rb_node, cache_tree_comp_nodes2); +} + +struct cache_extent *lookup_cache_extent(struct cache_tree *tree, +u64 start, u64 size) +{ + struct rb_node *node; + struct cache_extent *entry; + struct cache_extent_search_range range; + + range.start = start; + range.size = size; + node = rb_search(&tree->root, &range, cache_tree_comp_range, NULL); + if (!node) + return NULL; + + entry = rb_entry(node, struct cache_extent, rb_node); + return entry; +} + +struct cache_extent *lookup_cache_extent2(struct cache_tree *tree, +u64 objectid, u64 start, u64 size) +{ + struct rb_node *node; + struct cache_extent *entry; + struct cache_extent_search_range range; + + range.objectid = objectid; + range.start = start; + range.size = size; + node = rb_search(&tree->root, &range, cache_tree_comp_range2, NULL); + if (!node) + return NULL; + + entry = rb_entry(no
[PATCH U-BOOT v3 04/30] fs: btrfs: Crossport rbtree-utils from btrfs-progs
From: Qu Wenruo This is needed for incoming extent-cache infrastructure. Signed-off-by: Qu Wenruo Reviewed-by: Marek Behún --- fs/btrfs/Makefile | 3 +- fs/btrfs/common/rbtree-utils.c | 83 ++ fs/btrfs/common/rbtree-utils.h | 53 ++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/common/rbtree-utils.c create mode 100644 fs/btrfs/common/rbtree-utils.h diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index bd4b848d1b..53be6e8835 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -3,4 +3,5 @@ # 2017 Marek Behun, CZ.NIC, marek.be...@nic.cz obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ - extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o + extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o \ + common/rbtree-utils.o extent-cache.o diff --git a/fs/btrfs/common/rbtree-utils.c b/fs/btrfs/common/rbtree-utils.c new file mode 100644 index 00..7a7d7e84e6 --- /dev/null +++ b/fs/btrfs/common/rbtree-utils.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2014 Facebook. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include "rbtree-utils.h" + +int rb_insert(struct rb_root *root, struct rb_node *node, + rb_compare_nodes comp) +{ + struct rb_node **p = &root->rb_node; + struct rb_node *parent = NULL; + int ret; + + while(*p) { + parent = *p; + + ret = comp(parent, node); + if (ret < 0) + p = &(*p)->rb_left; + else if (ret > 0) + p = &(*p)->rb_right; + else + return -EEXIST; + } + + rb_link_node(node, parent, p); + rb_insert_color(node, root); + return 0; +} + +struct rb_node *rb_search(struct rb_root *root, void *key, rb_compare_keys comp, + struct rb_node **next_ret) +{ + struct rb_node *n = root->rb_node; + struct rb_node *parent = NULL; + int ret = 0; + + while(n) { + parent = n; + + ret = comp(n, key); + if (ret < 0) + n = n->rb_left; + else if (ret > 0) + n = n->rb_right; + else + return n; + } + + if (!next_ret) + return NULL; + + if (parent && ret > 0) + parent = rb_next(parent); + + *next_ret = parent; + return NULL; +} + +void rb_free_nodes(struct rb_root *root, rb_free_node free_node) +{ + struct rb_node *node; + + while ((node = rb_first(root))) { + rb_erase(node, root); + free_node(node); + } +} diff --git a/fs/btrfs/common/rbtree-utils.h b/fs/btrfs/common/rbtree-utils.h new file mode 100644 index 00..d977cfd955 --- /dev/null +++ b/fs/btrfs/common/rbtree-utils.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 Facebook. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#ifndef __RBTREE_UTILS__ +#define __RBTREE_UTILS__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* The common insert/search/free functions */ +typedef int (*rb_compare_nodes)(struct rb_node *node1, struct rb_node *node2); +typedef int (*rb_compare_keys)(struct rb_node *node, void *key); +typedef void (*rb_free_node)(struct rb_node *node); + +int rb_insert(struct rb_root *root, struct rb_node *node, + rb_compare_nodes comp); +/* + * In some cases, we need return the next node if we don't find the node we + * specify. At this time, we can use next_ret. + */ +struct rb_node *rb_search(struct
[PATCH U-BOOT v3 00/30] PLEASE TEST fs: btrfs: Re-implement btrfs support using code from btrfs-progs
Hello, this is a cleaned up version of Qu's patches that reimplements U-Boot's btrfs driver with code from btrfs-progs. I have tested this series, found and corrected one bug (failure when accesing files via symlinks), and it looks it is working now, but I would like more people to do some testing. There are a lot of checkpatch warnings and errors left, I shall fix this in the future. Marek Changes since v2: - fixed btrfs_lookup_path() in patch 19 to correctly handle symlinks - commit messages were updated some - for example they used the word "crossport" in 3 formats: "crossport", "cross-port" and "cross port", this was changed to "crossport" - corrected some typos - some English sentences were a bit weirdly written - fixed 2 compiler warnings (one use of maybe uninitialized variable and one printf specifier warning) - indentation in some places was wrong (usage of 8 spaces instead of a tab, for example) - added my Reviewed-by - the last patch, adding btrfs mailing list to MAINTAINRES, also adds Qu as designated reviewer, so that people add him to Cc when they send patches Changes since v1: - Implement btrfs_list_subvols() In v1 it's completely removed thus would cause problem if btrfsolume command is compiled in. - Rebased to latest master Only minor conflicts due to header changes. - Allow next_legnth() to return value > BTRFS_NAME_LEN Below is Qu's explanation, from cover letter of v2: The current btrfs code in U-boot is using a creative way to read on-disk data. It's pretty simple, involving the least amount of code, but pretty different from btrfs-progs nor kernel, making it pretty hard to sync code between different projects. This big patchset will rework the btrfs support, to use code mostly from btrfs-progs, thus all existing btrfs developers will feel at home. During the rework, the following new features are added: - More hash algorithm support SHA256 and XXHASH support are added. BLAKE2 needs more backport, will happen in a separate patchset. - The ability to read degraded RAID1 Although we still only support one device btrfs, the new code base can choose from different copies already. As long as new device scan interface is provided, multi-device support is pretty simple. - More correct handling of compressed extents with offset For compressed extent with offset, we should read the whole compressed extent, decompress them, then copy the referred part. There are some more features incoming, with the new code base it would be much easier to implement: - Data checksum support The check would happen in read_extent_data(), btrfs-progs has the needed facility to locate data csum. - BLAKE2 support Need BLAKE2 library cross ported. For btrfs it's just several lines of modification. - Multi-device support along wit degraded RAID support We only need an interface to scan one device without opening it. The infrastructure is already provided in this patchset. These new features would be submitted after the patchset get merged, since the patchset is already large, I don't want to make it more scary. Although this patchset look horribly large, most of them are code copy from btrfs-progs. E.g extent-cache.[ch], rbtree-utils.[ch], btrfs_btree.h. And ctree.h has over 1000 lines copied just for various accessors. While for disk-io.[ch] and volumes-io.[ch], they have some small modifications to adapt the interface of U-boot. E.g. btrfs_device::fd is replace with blkdev_desc and disk_partition_t. The new code for U-boot are related to the following functions: - btrfs_readlink() - btrfs_lookup_path() - btrfs_read_extent_inline() - btrfs_read_extent_reg() - lookup_data_extent() - btrfs_file_read() - btrfs_list_subvols() Qu Wenruo (30): fs: btrfs: Sync btrfs_btree.h from kernel fs: btrfs: Add more checksum algorithms fs: btrfs: Crossport btrfs_read_dev_super() from btrfs-progs fs: btrfs: Crossport rbtree-utils from btrfs-progs fs: btrfs: Crossport extent-cache.[ch] from btrfs-progs fs: btrfs: Crossport extent-io.[ch] from btrfs-progs fs: btrfs: Crossport structure accessor into ctree.h fs: btrfs: Crossport volumes.[ch] from btrfs-progs fs: btrfs: Crossport read_tree_block() from btrfs-progs fs: btrfs: Rename struct btrfs_path to struct __btrfs_path fs: btrfs: Rename btrfs_root to __btrfs_root fs: btrfs: Crossport struct btrfs_root to ctree.h fs: btrfs: Crossport btrfs_search_slot() from btrfs-progs fs: btrfs: Crossport btrfs_read_sys_array() and btrfs_read_chunk_tree() fs: btrfs: Crossport open_ctree_fs_info() from btrfs-progs fs: btrfs: Rename path resolve related functions to avoid name conflicts fs: btrfs: Use btrfs_readlink() to implement __btrfs_readlink() fs: btrfs: inode: Allow next_length() to return value > BTRFS_NAME_LEN fs: btrfs: Implement btrfs_lookup_path() fs: btrfs: Use btrfs_iter_dir() to replace btrfs_readdir() fs: btrfs: Use btrfs_lookup_path() to implement btrfs_exists() a
Re: [PATCH 1/1] gitlab: show skipped Python tests
On Wed, Jun 24, 2020 at 09:17:51AM -0600, Simon Glass wrote: > Hi Heinrich, > > On Wed, 24 Jun 2020 at 07:56, Heinrich Schuchardt wrote: > > > > On 24.06.20 15:49, Simon Glass wrote: > > > Hi, > > > > > > On Mon, 22 Jun 2020 at 12:46, Tom Rini wrote: > > >> > > >> On Mon, Jun 22, 2020 at 12:23:35PM -0600, Simon Glass wrote: > > >>> Hi Heinrich, > > >>> > > >>> On Mon, 22 Jun 2020 at 10:40, Heinrich Schuchardt > > >>> wrote: > > > > On 22.06.20 18:17, Simon Glass wrote: > > > Hi Heinrich, > > > > > > On Mon, 22 Jun 2020 at 10:07, Heinrich Schuchardt > > > wrote: > > >> > > >> Call pytest3 with argument -ra to display reason why Python tests are > > >> skipped. > > >> > > >> Signed-off-by: Heinrich Schuchardt > > >> --- > > >> .gitlab-ci.yml | 2 +- > > >> 1 file changed, 1 insertion(+), 1 deletion(-) > > >> > > >> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml > > >> index f2e491c117..f53098ea5f 100644 > > >> --- a/.gitlab-ci.yml > > >> +++ b/.gitlab-ci.yml > > >> @@ -46,7 +46,7 @@ stages: > > >> # "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" > > >> if not > > >> - export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH}; > > >>export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci; > > >> - ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID} > > >> + ./test/py/test.py -ra --bd ${TEST_PY_BD} ${TEST_PY_ID} > > >> ${TEST_PY_TEST_SPEC:+"-k ${TEST_PY_TEST_SPEC}"} > > >> --build-dir "$UBOOT_TRAVIS_BUILD_DIR" > > > > > > Do you have a link showing the current output with this patch? > > > > Hello Simon, > > > > here is an example output: > > > > https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112385 > > >>> > > >>> That's what I was afraid of. The skip output is more than the normal > > >>> output, and if we don't intend to fix it, I'd rather not have > > >>> unactionable warnings in the output. > > >>> > > >>> Having said that, we need to enable SPI flash, FPGA and MMC > > >>> environment tests by the look of it. > > >> > > >> On a different note, I think we should look at: > > >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112376 > > >> and: > > >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112380 > > >> > > >> as it shows that the reason we probably skip the test_fs/test_mkdir.py > > >> tests is that since board is literal, we don't match sandbox on > > >> sandbox_flattree. That answers one outstanding question about why we > > >> skip some tests and not others at least. > > > > > > Hmm yes. > > > > > > It is definitely good to have this output so we can figure out what > > > should not be skipped. > > > > > > But outputting things which we know should be skipped just means we > > > won't notice those that are not supposed to be skipped. How do we > > > handle that? > > > > > > Regards, > > > Simon > > > > > If you have a lines like: > > > > .config feature "cmd_fpga_loadbp" not enabled > > board "qemu_arm64" not supported > > > > you know the test is skipped due to configuration. > > OK then can we avoid printing this useless information by default? It's not useless information. It's what I pointed to in another part of the thread as to why we're skipping tests we didn't expect to skip. > > Other messages clearly tell you that something is not correctly set up: > > > > No env__efi_loader_grub_file binary specified in environment > > got empty parameter set ['env__mmc_dev_config'] > > OK then this is what we should display. This one is actually one I dug in to a bit, and I don't like how pytest handles. You can't add a custom parameter checker, AFAICT, you can only have empty params be skip or xfail. I think we could condense the output a little bit as @pytest.mark things get condensed, but pytest.skip in a test do not (as it counts line number). That's what got me looking for a way to mark that a config needs to exist, but that isn't supported. But we could condense some of the network related stuff by having a single test / helper for network configuration rather than duplicating it, and then mark network tests as depending on it. -- Tom signature.asc Description: PGP signature
Re: PINE64 Rock64 - How to get SPI driver working
Sorry for my late response. Thanks for the suggestions. On 22.05.20 at 16:28, Peter Robinson wrote: > Make sure you enable the driver for the actual flash chip too, some of > the popular ones are: > CONFIG_SPI_FLASH_WINBOND=y > CONFIG_SPI_FLASH_MACRONIX=y > CONFIG_SPI_FLASH_SPANSION=y > CONFIG_SPI_FLASH_GIGADEVICE=y I have enabled 'CONFIG_SPI_FLASH_GIGADEVICE'. But still getting the same error code (-2). On board is the GD25Q127C from Gigadevice. The device ID for the operation code 0x9F according to the datasheet should be 0xC84018. I also found this device ID in the SPI-NOR IDS file.
Re: [PATCH 1/1] gitlab: show skipped Python tests
On 24.06.20 17:17, Simon Glass wrote: > Hi Heinrich, > > On Wed, 24 Jun 2020 at 07:56, Heinrich Schuchardt wrote: >> >> On 24.06.20 15:49, Simon Glass wrote: >>> Hi, >>> >>> On Mon, 22 Jun 2020 at 12:46, Tom Rini wrote: On Mon, Jun 22, 2020 at 12:23:35PM -0600, Simon Glass wrote: > Hi Heinrich, > > On Mon, 22 Jun 2020 at 10:40, Heinrich Schuchardt > wrote: >> >> On 22.06.20 18:17, Simon Glass wrote: >>> Hi Heinrich, >>> >>> On Mon, 22 Jun 2020 at 10:07, Heinrich Schuchardt >>> wrote: Call pytest3 with argument -ra to display reason why Python tests are skipped. Signed-off-by: Heinrich Schuchardt --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f2e491c117..f53098ea5f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,7 +46,7 @@ stages: # "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" if not - export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH}; export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci; - ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID} + ./test/py/test.py -ra --bd ${TEST_PY_BD} ${TEST_PY_ID} ${TEST_PY_TEST_SPEC:+"-k ${TEST_PY_TEST_SPEC}"} --build-dir "$UBOOT_TRAVIS_BUILD_DIR" >>> >>> Do you have a link showing the current output with this patch? >> >> Hello Simon, >> >> here is an example output: >> >> https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112385 > > That's what I was afraid of. The skip output is more than the normal > output, and if we don't intend to fix it, I'd rather not have > unactionable warnings in the output. > > Having said that, we need to enable SPI flash, FPGA and MMC > environment tests by the look of it. On a different note, I think we should look at: https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112376 and: https://gitlab.denx.de/u-boot/custodians/u-boot-efi/-/jobs/112380 as it shows that the reason we probably skip the test_fs/test_mkdir.py tests is that since board is literal, we don't match sandbox on sandbox_flattree. That answers one outstanding question about why we skip some tests and not others at least. >>> >>> Hmm yes. >>> >>> It is definitely good to have this output so we can figure out what >>> should not be skipped. >>> >>> But outputting things which we know should be skipped just means we >>> won't notice those that are not supposed to be skipped. How do we >>> handle that? >>> >>> Regards, >>> Simon >>> >> If you have a lines like: >> >> .config feature "cmd_fpga_loadbp" not enabled >> board "qemu_arm64" not supported >> >> you know the test is skipped due to configuration. > > OK then can we avoid printing this useless information by default? > >> >> Other messages clearly tell you that something is not correctly set up: >> >> No env__efi_loader_grub_file binary specified in environment >> got empty parameter set ['env__mmc_dev_config'] > > OK then this is what we should display. There is no switch in pytest to display this selectively. Best regards Heinrich
[PATCH 2/2] efi_loader: size of secure boot variables
The variables SetupMode, AuditMode, DeployedMode are explicitly defined as UINT8 in the UEFI specification. The type of SecureBoot is UINT8 in EDK2. Use variable name secure_boot instead of sec_boot for the value of the UEFI variable SecureBoot. Avoid abbreviations in function descriptions. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_variable.c | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 4d275b23ce..6271dbcf41 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -185,17 +185,17 @@ static const char *parse_attr(const char *str, u32 *attrp, u64 *timep) /** * efi_set_secure_state - modify secure boot state variables - * @sec_boot: value of SecureBoot + * @secure_boot: value of SecureBoot * @setup_mode:value of SetupMode * @audit_mode:value of AuditMode * @deployed_mode: value of DeployedMode * - * Modify secure boot stat-related variables as indicated. + * Modify secure boot status related variables as indicated. * * Return: status code */ -static efi_status_t efi_set_secure_state(int sec_boot, int setup_mode, -int audit_mode, int deployed_mode) +static efi_status_t efi_set_secure_state(u8 secure_boot, u8 setup_mode, +u8 audit_mode, u8 deployed_mode) { u32 attributes; efi_status_t ret; @@ -204,8 +204,8 @@ static efi_status_t efi_set_secure_state(int sec_boot, int setup_mode, EFI_VARIABLE_RUNTIME_ACCESS | READ_ONLY; ret = efi_set_variable_common(L"SecureBoot", &efi_global_variable_guid, - attributes, sizeof(sec_boot), &sec_boot, - false); + attributes, sizeof(secure_boot), + &secure_boot, false); if (ret != EFI_SUCCESS) goto err; -- 2.27.0
[PATCH 1/2] efi_loader: type of efi_secure_mode
Variable efi_secure_mode is meant to hold a value of enum efi_secure_mode. So it should not be defined as int but as enum efi_secure_mode. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_variable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index e097670e28..4d275b23ce 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -27,7 +27,7 @@ enum efi_secure_mode { }; static bool efi_secure_boot; -static int efi_secure_mode; +static enum efi_secure_mode efi_secure_mode; static u8 efi_vendor_keys; #define READ_ONLY BIT(31) -- 2.27.0