Skip to content

Instantly share code, notes, and snippets.

@apritzel
Created August 4, 2016 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apritzel/c3f811b5493805a616698b8e06b2655a to your computer and use it in GitHub Desktop.
Save apritzel/c3f811b5493805a616698b8e06b2655a to your computer and use it in GitHub Desktop.
Script to recreate a DT in U-Boot via the serial console
#!/bin/sh
send() {
read -d\# line
echo "$1"
}
# kick u-boot to tickle the prompt and get the state machine going
echo "printenv bootcmd"
read line
# tear down most existing DT nodes
send "fdt rm /soc"
send "fdt rm /clocks"
send "fdt rm /btlpm"
send "fdt rm /bt"
send "fdt rm /wlan"
send "fdt rm /gpu"
send "fdt rm /dram"
send "fdt rm /dramfreq"
send "fdt rm /dvfs_table"
send "fdt rm /pmu"
send "fdt rm /sunxi-chipid"
send "fdt rm /ion"
send "fdt rm /cpuscfg"
send "fdt rm /prcm"
send "fdt rm /sram_a2"
send "fdt rm /sram_a1"
send "fdt rm /n_brom"
send "fdt rm /s_brom"
send "fdt rm /cpus/idle-states"
# fixup address cells and size cells to 32-bit, thats all we need
send "fdt set / \\#address-cells <1>"
send "fdt set / \\#size-cells <1>"
send "fdt set /memory reg <0x41000000 0x3f000000>"
send "fdt set /interrupt-controller reg <0x01c81000 0x1000 0x01c82000 0x2000 0x01c84000 0x2000 0x01c86000 0x2000>"
send "fdt rm /psci"
send "fdt mknod / psci"
send "fdt set /psci compatible \"arm,psci-0.2\""
send "fdt set /psci method \"smc\""
send "fdt mknod / clocks"
send "fdt set /clocks \\#address-cells <1>"
send "fdt set /clocks \\#size-cells <1>"
send "fdt set /clocks ranges"
send "fdt mknod /clocks osc24M_clk"
send "fdt set /clocks/osc24M_clk linux,phandle <2>"
send "fdt set /clocks/osc24M_clk phandle <2>"
send "fdt set /clocks/osc24M_clk clock-output-names \"osc24M\""
send "fdt set /clocks/osc24M_clk clock-frequency <24000000>"
send "fdt set /clocks/osc24M_clk compatible \"fixed-clock\""
send "fdt set /clocks/osc24M_clk \\#clock-cells <0>"
send "fdt mknod /clocks osc32k_clk"
send "fdt set /clocks/osc32k_clk linux,phandle <12>"
send "fdt set /clocks/osc32k_clk phandle <12>"
send "fdt set /clocks/osc32k_clk clock-output-names \"osc32k\""
send "fdt set /clocks/osc32k_clk clock-frequency <32768>"
send "fdt set /clocks/osc32k_clk compatible \"fixed-clock\""
send "fdt set /clocks/osc32k_clk \\#clock-cells <0>"
send "fdt mknod /clocks pll1"
send "fdt set /clocks/pll1 linux,phandle <13>"
send "fdt set /clocks/pll1 phandle <13>"
send "fdt set /clocks/pll1 clock-output-names \"pll1\""
send "fdt set /clocks/pll1 clocks <2>"
send "fdt set /clocks/pll1 reg <0x01c20000 0x4>"
send "fdt set /clocks/pll1 compatible \"allwinner,sun8i-a23-pll1-clk\""
send "fdt set /clocks/pll1 \\#clock-cells <0>"
send "fdt mknod /clocks pll6"
send "fdt set /clocks/pll6 linux,phandle <10>"
send "fdt set /clocks/pll6 phandle <10>"
send "fdt set /clocks/pll6 clock-output-names \"pll6\" \"pll6x2\""
send "fdt set /clocks/pll6 clocks <2>"
send "fdt set /clocks/pll6 reg <0x01c20028 0x4>"
send "fdt set /clocks/pll6 compatible \"allwinner,sun6i-a31-pll6-clk\""
send "fdt set /clocks/pll6 \\#clock-cells <1>"
send "fdt mknod /clocks pll6d2"
send "fdt set /clocks/pll6d2 linux,phandle <16>"
send "fdt set /clocks/pll6d2 phandle <16>"
send "fdt set /clocks/pll6d2 clock-output-names \"pll6d2\""
send "fdt set /clocks/pll6d2 clocks <10 0>"
send "fdt set /clocks/pll6d2 compatible \"fixed-factor-clock\""
send "fdt set /clocks/pll6d2 \\#clock-cells <0>"
send "fdt mknod /clocks pll8"
send "fdt set /clocks/pll8 linux,phandle <11>"
send "fdt set /clocks/pll8 phandle <11>"
send "fdt set /clocks/pll8 clock-output-names \"pll8\""
send "fdt set /clocks/pll8 compatible \"fixed-clock\""
send "fdt set /clocks/pll8 \\#clock-cells <0>"
send "fdt set /clocks/pll8 clock-frequency <1>"
send "fdt mknod /clocks cpu_clk"
send "fdt set /clocks/cpu_clk linux,phandle <14>"
send "fdt set /clocks/cpu_clk phandle <14>"
send "fdt set /clocks/cpu_clk \\#clock-cells <0>"
send "fdt set /clocks/cpu_clk compatible \"allwinner,sun4i-a10-cpu-clk\""
send "fdt set /clocks/cpu_clk reg <0x01c20050 0x4>"
send "fdt set /clocks/cpu_clk clocks <12 2 13 13>"
send "fdt set /clocks/cpu_clk clock-output-names \"cpu\""
send "fdt mknod /clocks axi_clk"
send "fdt set /clocks/axi_clk linux,phandle <6>"
send "fdt set /clocks/axi_clk phandle <6>"
send "fdt set /clocks/axi_clk \\#clock-cells <0>"
send "fdt set /clocks/axi_clk compatible \"allwinner,sun4i-a10-cpu-clk\""
send "fdt set /clocks/axi_clk reg <0x01c20050 0x4>"
send "fdt set /clocks/axi_clk clocks <14>"
send "fdt set /clocks/axi_clk clock-output-names \"axi\""
send "fdt mknod /clocks ahb1_clk"
send "fdt set /clocks/ahb1_clk linux,phandle <9>"
send "fdt set /clocks/ahb1_clk phandle <9>"
send "fdt set /clocks/ahb1_clk \\#clock-cells <0>"
send "fdt set /clocks/ahb1_clk compatible \"allwinner,sun6i-a31-ahb1-clk\""
send "fdt set /clocks/ahb1_clk reg <0x01c20054 0x4>"
send "fdt set /clocks/ahb1_clk clocks <12 2 6 10 0>"
send "fdt set /clocks/ahb1_clk clock-output-names \"ahb1\""
send "fdt mknod /clocks ahb2_clk"
send "fdt set /clocks/ahb2_clk linux,phandle <15>"
send "fdt set /clocks/ahb2_clk phandle <15>"
send "fdt set /clocks/ahb2_clk \\#clock-cells <0>"
send "fdt set /clocks/ahb2_clk compatible \"allwinner,sun8i-h3-ahb2-clk\""
send "fdt set /clocks/ahb2_clk reg <0x01c2005c 0x4>"
send "fdt set /clocks/ahb2_clk clocks <9 16>"
send "fdt set /clocks/ahb2_clk clock-output-names \"ahb2\""
send "fdt mknod /clocks apb1_clk"
send "fdt set /clocks/apb1_clk linux,phandle <17>"
send "fdt set /clocks/apb1_clk phandle <17>"
send "fdt set /clocks/apb1_clk \\#clock-cells <0>"
send "fdt set /clocks/apb1_clk compatible \"allwinner,sun4i-a10-apb0-clk\""
send "fdt set /clocks/apb1_clk reg <0x01c20054 0x4>"
send "fdt set /clocks/apb1_clk clocks <9>"
send "fdt set /clocks/apb1_clk clock-output-names \"apb1\""
send "fdt mknod /clocks apb2_clk"
send "fdt set /clocks/apb2_clk linux,phandle <18>"
send "fdt set /clocks/apb2_clk phandle <18>"
send "fdt set /clocks/apb2_clk \\#clock-cells <0>"
send "fdt set /clocks/apb2_clk compatible \"allwinner,sun4i-a10-apb1-clk\""
send "fdt set /clocks/apb2_clk reg <0x01c20058 0x4>"
send "fdt set /clocks/apb2_clk clocks <12 2 10 0 10 0>"
send "fdt set /clocks/apb2_clk clock-output-names \"apb2\""
send "fdt mknod /clocks bus_gates"
send "fdt set /clocks/bus_gates linux,phandle <19>"
send "fdt set /clocks/bus_gates phandle <19>"
send "fdt set /clocks/bus_gates \\#clock-cells <1>"
#send "fdt set /clocks/bus_gates compatible \"allwinner,sun8i-h3-bus-gates-clk\""
send "fdt set /clocks/bus_gates compatible \"allwinner,sun7i-a20-ahb-gates-clk\""
send "fdt set /clocks/bus_gates reg <0x01c20060 0x14>"
send "fdt set /clocks/bus_gates clocks <9 15 17 18>"
send "fdt set /clocks/bus_gates clock-names \"ahb1\" \"ahb2\" \"apb1\" \"apb2\""
send "fdt set /clocks/bus_gates clock-indices <8 69>"
send "fdt set /clocks/bus_gates clock-output-names \"bus_mmc0\" \"bus_pio\""
send "fdt mknod /clocks mmc_clk"
send "fdt set /clocks/mmc_clk linux,phandle <7>"
send "fdt set /clocks/mmc_clk phandle <7>"
send "fdt set /clocks/mmc_clk clock-output-names \"mmc0\" \"mmc0_output\" \"mmc0_sample\""
send "fdt set /clocks/mmc_clk clocks <2 10 0 11>"
send "fdt set /clocks/mmc_clk reg <0x01c20088 0x4>"
send "fdt set /clocks/mmc_clk compatible \"allwinner,sun4i-a10-mmc-clk\""
send "fdt set /clocks/mmc_clk \\#clock-cells <1>"
send "fdt mknod / uart0"
send "fdt set /uart0 reg-io-width <4>"
send "fdt set /uart0 reg-shift <2>"
send "fdt set /uart0 clocks <2>"
send "fdt set /uart0 interrupts <0 0 4>"
send "fdt set /uart0 reg <0x01c28000 0x400>"
send 'fdt set /uart0 compatible "snps,dw-apb-uart"'
send "fdt rm /aliases"
send "fdt mknod / aliases"
send "fdt set /aliases serial0 \"/uart0\""
send "fdt mknod / mmc0"
#pinctrl-names = "default";
#pinctrl-0 = <&mmc0_pins_a>, <&mmc0_cd_pin_bananapi>;
send "fdt set /mmc0 cd-gpios <8 5 6 0>"
send "fdt set /mmc0 cd-inverted"
send "fdt set /mmc0 vmmc-supply <5>"
send "fdt set /mmc0 clocks <19 8 7 0 7 1 7 2>"
send "fdt set /mmc0 clock-names \"ahb\" \"mmc\" \"output\" \"sample\""
send "fdt set /mmc0 bus-width <4>"
send "fdt set /mmc0 interrupts <0 60 4>"
send "fdt set /mmc0 reg <0x01c0f000 0x1000>"
send "fdt set /mmc0 \\#size-cells <0>"
send "fdt set /mmc0 \\#address-cells <1>"
send "fdt set /mmc0 compatible \"allwinner,sun5i-a13-mmc\""
send "fdt mknod / reg_vcc3v3"
send "fdt set /reg_vcc3v3 phandle <5>"
send "fdt set /reg_vcc3v3 linux,phandle <5>"
send "fdt set /reg_vcc3v3 regulator-max-microvolt <3300000>"
send "fdt set /reg_vcc3v3 regulator-min-microvolt <3300000>"
send "fdt set /reg_vcc3v3 regulator-name \"vcc3v3\""
send "fdt set /reg_vcc3v3 compatible \"regulator-fixed\""
send "fdt mknod / pinctrl"
send "fdt set /pinctrl \\#gpio-cells <3>"
send "fdt set /pinctrl \\#interrupt-cells <3>"
send "fdt set /pinctrl interrupt-controller"
send "fdt set /pinctrl gpio-controller"
send "fdt set /pinctrl clocks <19 69>"
send "fdt set /pinctrl interrupts <0 11 4 0 17 4 0 21 4>"
send "fdt set /pinctrl reg <0x01c20800 0x400>"
send "fdt set /pinctrl compatible \"allwinner,a64-pinctrl\""
send "fdt set /pinctrl phandle <8>"
send "fdt set /pinctrl linux,phandle <8>"
send "fdt mknod /pinctrl uart0"
send "fdt set /pinctrl/uart0 allwinner,pins \"PB8\" \"PB9\""
send "fdt set /pinctrl/uart0 allwinner,function \"uart0\""
send "fdt set /pinctrl/uart0 allwinner,drive <0>"
send "fdt set /pinctrl/uart0 allwinner,pull <0>"
send "fdt mknod /pinctrl mmc0"
send "fdt set /pinctrl/mmc0 allwinner,pins \"PF0\" \"PF1\" \"PF2\" \"PF3\" \"PF4\" \"PF5\""
send "fdt set /pinctrl/mmc0 allwinner,function \"mmc0\""
send "fdt set /pinctrl/mmc0 allwinner,drive <2>"
send "fdt set /pinctrl/mmc0 allwinner,pull <0>"
send "fdt set /pinctrl/mmc0 linux,phandle <3>"
send "fdt set /pinctrl/mmc0 phandle <3>"
send "fdt mknod /pinctrl mmc0_cd_pin"
send "fdt set /pinctrl/mmc0_cd_pin allwinner,pins \"PF6\""
send "fdt set /pinctrl/mmc0_cd_pin allwinner,function \"gpio_in\""
send "fdt set /pinctrl/mmc0_cd_pin allwinner,drive <0>"
send "fdt set /pinctrl/mmc0_cd_pin allwinner,pull <1>"
send "fdt set /pinctrl/mmc0_cd_pin linux,phandle <4>"
send "fdt set /pinctrl/mmc0_cd_pin phandle <4>"
send "fdt mknod / rtc"
send "fdt set /rtc interrupts <0 40 4 0 41 4>"
send "fdt set /rtc reg <0x01f00000 0x54>"
send "fdt set /rtc compatible \"allwinner,sun6i-a31-rtc\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment