Merge Official Source

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
This commit is contained in:
Tianling Shen 2021-04-10 13:40:38 +08:00
commit 795300f6fa
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
93 changed files with 2297 additions and 724 deletions

View File

@ -0,0 +1,11 @@
--- a/plat/mediatek/mt7622/bl2_boot_nor.c
+++ b/plat/mediatek/mt7622/bl2_boot_nor.c
@@ -12,7 +12,7 @@
#define MT7622_NOR_MAP_BASE 0x30000000
#define FIP_BASE 0x20000
-#define FIP_SIZE 0x80000
+#define FIP_SIZE 0xa0000
const io_block_spec_t mtk_boot_dev_fip_spec = {
.offset = MT7622_NOR_MAP_BASE + FIP_BASE,

View File

@ -61,12 +61,15 @@ MAKE_FLAGS += \
define Package/uboot-envtools/conffiles
/etc/config/ubootenv
/etc/fw_env.config
/etc/fw_sys.config
endef
define Package/uboot-envtools/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/tools/env/fw_printenv $(1)/usr/sbin
$(LN) fw_printenv $(1)/usr/sbin/fw_setenv
$(INSTALL_BIN) ./files/fw_printsys $(1)/usr/sbin
$(INSTALL_BIN) ./files/fw_setsys $(1)/usr/sbin
$(INSTALL_DIR) $(1)/lib
$(INSTALL_DATA) ./files/uboot-envtools.sh $(1)/lib
$(INSTALL_DIR) $(1)/etc/uci-defaults

View File

@ -0,0 +1,2 @@
#!/bin/sh
[ -e /etc/fw_sys.config ] && exec /usr/sbin/fw_printenv -c /etc/fw_sys.config "$@"

View File

@ -0,0 +1,2 @@
#!/bin/sh
[ -e /etc/fw_sys.config ] && exec /usr/sbin/fw_setenv -c /etc/fw_sys.config "$@"

View File

@ -13,11 +13,11 @@ touch /etc/config/ubootenv
board=$(board_name)
case "$board" in
"linksys,e8450-ubi")
linksys,e8450-ubi)
ubootenv_add_uci_config "/dev/ubi0_0" "0x0" "0x1f000" "0x1f000" "1"
ubootenv_add_uci_config "/dev/ubi0_1" "0x0" "0x1f000" "0x1f000" "1"
;;
"bananapi,bpi-r64")
bananapi,bpi-r64)
. /lib/upgrade/platform.sh
local rootdev=$(get_rootdev)
local envdev=/dev/$(get_partition $rootdev ubootenv)
@ -27,6 +27,9 @@ case "$board" in
buffalo,wsr-2533dhp2)
ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x1000" "0x20000"
;;
ubnt,unifi-6-lr-ubootmod)
ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x1000" "0x10000"
;;
esac
config_load ubootenv

View File

@ -18,15 +18,21 @@ zyxel,gs1900-10hp)
idx="$(find_mtd_index u-boot-env)"
[ -n "$idx" ] && \
ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x400" "0x10000"
idx2="$(find_mtd_index u-boot-env2)"
[ -n "$idx2" ] && \
ubootenv_add_uci_sys_config "/dev/mtd$idx2" "0x0" "0x1000" "0x10000"
;;
*)
idx="$(find_mtd_index u-boot-env)"
[ -n "$idx" ] && \
ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
idx2="$(find_mtd_index u-boot-env2)"
[ -n "$idx2" ] && \
ubootenv_add_uci_sys_config "/dev/mtd$idx2" "0x0" "0x1000" "0x10000"
;;
esac
config_load ubootenv
config_foreach ubootenv_add_app_config ubootenv
config_foreach ubootenv_add_app_config
exit 0

View File

@ -3,34 +3,44 @@
# Copyright (C) 2011-2012 OpenWrt.org
#
ubootenv_add_uci_config() {
local dev=$1
local offset=$2
local envsize=$3
local secsize=$4
local numsec=$5
_ubootenv_add_uci_config() {
local cfgtype=$1
local dev=$2
local offset=$3
local envsize=$4
local secsize=$5
local numsec=$6
uci batch <<EOF
add ubootenv ubootenv
set ubootenv.@ubootenv[-1].dev='$dev'
set ubootenv.@ubootenv[-1].offset='$offset'
set ubootenv.@ubootenv[-1].envsize='$envsize'
set ubootenv.@ubootenv[-1].secsize='$secsize'
set ubootenv.@ubootenv[-1].numsec='$numsec'
add ubootenv $cfgtype
set ubootenv.@$cfgtype[-1].dev='$dev'
set ubootenv.@$cfgtype[-1].offset='$offset'
set ubootenv.@$cfgtype[-1].envsize='$envsize'
set ubootenv.@$cfgtype[-1].secsize='$secsize'
set ubootenv.@$cfgtype[-1].numsec='$numsec'
EOF
uci commit ubootenv
}
ubootenv_add_uci_config() {
_ubootenv_add_uci_config "ubootenv" "$@"
}
ubootenv_add_uci_sys_config() {
_ubootenv_add_uci_config "ubootsys" "$@"
}
ubootenv_add_app_config() {
local cfgtype
local dev
local offset
local envsize
local secsize
local numsec
config_get cfgtype "$1" TYPE
config_get dev "$1" dev
config_get offset "$1" offset
config_get envsize "$1" envsize
config_get secsize "$1" secsize
config_get numsec "$1" numsec
grep -q "^[[:space:]]*${dev}[[:space:]]*${offset}" /etc/fw_env.config || echo "$dev $offset $envsize $secsize $numsec" >>/etc/fw_env.config
grep -q "^[[:space:]]*${dev}[[:space:]]*${offset}" "/etc/fw_${cfgtype#uboot}.config" || echo "$dev $offset $envsize $secsize $numsec" >>"/etc/fw_${cfgtype#uboot}.config"
}

View File

@ -54,6 +54,17 @@ define U-Boot/mt7622_bananapi_bpi-r64-sdmmc
DEPENDS:=+trusted-firmware-a-mt7622-sdmmc-2ddr
endef
define U-Boot/mt7622_ubnt_unifi-6-lr
NAME:=Ubiquiti UniFi 6 LR
UBOOT_CONFIG:=mt7622_ubnt_unifi-6-lr
BUILD_DEVICES:=ubnt_unifi-6-lr-ubootmod
BUILD_SUBTARGET:=mt7622
UBOOT_IMAGE:=u-boot.fip
BL2_BOOTDEV:=nor
BL2_DDRBLOB:=2
DEPENDS:=+trusted-firmware-a-mt7622-nor-2ddr
endef
define U-Boot/mt7623a_unielec_u7623
NAME:=UniElec U7623 (mt7623)
BUILD_DEVICES:=unielec_u7623-emmc unielec_u7623-02-emmc-512m-legacy
@ -81,6 +92,7 @@ UBOOT_TARGETS := \
mt7622_bananapi_bpi-r64-sdmmc \
mt7622_linksys_e8450 \
mt7622_rfb1 \
mt7622_ubnt_unifi-6-lr \
mt7623n_bpir2 \
mt7623a_unielec_u7623 \
mt7629_rfb

View File

@ -1,24 +1,23 @@
--- a/board/mediatek/mt7622/mt7622_rfb.c
+++ b/board/mediatek/mt7622/mt7622_rfb.c
@@ -6,10 +6,17 @@
@@ -6,9 +6,16 @@
#include <common.h>
#include <config.h>
+#include <dm.h>
+#include <button.h>
+
#include <env.h>
#include <init.h>
#include <asm/global_data.h>
+#include <linux/delay.h>
+
+#ifndef CONFIG_RESET_BUTTON_LABEL
+#define CONFIG_RESET_BUTTON_LABEL "reset"
+#endif
+
DECLARE_GLOBAL_DATA_PTR;
int board_init(void)
@@ -20,7 +27,15 @@ int board_init(void)
@@ -20,7 +27,19 @@ int board_init(void)
int board_late_init(void)
{
@ -28,8 +27,12 @@
+
+ ret = !!button_get_by_label(CONFIG_RESET_BUTTON_LABEL, &dev);
+
+ if (!ret)
+ if (!ret) {
+#ifdef CONFIG_RESET_BUTTON_SETTLE_DELAY
+ udelay(1000 * CONFIG_RESET_BUTTON_SETTLE_DELAY);
+#endif
+ ret = !button_get_state(dev);
+ }
+
+ gd->env_valid = ret; //to load environment variable from persistent store
env_relocate();

View File

@ -0,0 +1,11 @@
--- a/drivers/mtd/spi/spi-nor-ids.c
+++ b/drivers/mtd/spi/spi-nor-ids.c
@@ -329,6 +329,8 @@ const struct flash_info spi_nor_ids[] =
SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB)
},
{ INFO("w25q256", 0xef4019, 0, 64 * 1024, 512, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
+ { INFO("w25q512jv", 0xef4020, 0, 64 * 1024, 1024, SECT_4K | SPI_NOR_QUAD_READ | SPI_NOR_DUAL_READ |
+ SPI_NOR_HAS_TB | SPI_NOR_HAS_LOCK) },
{ INFO("w25m512jw", 0xef6119, 0, 64 * 1024, 1024, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
{ INFO("w25m512jv", 0xef7119, 0, 64 * 1024, 1024, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
#endif

View File

@ -186,7 +186,7 @@
+boot_tftp=tftpboot $loadaddr $bootfile && bootm $loadaddr
+emmc_write_bl2=mmc dev 0 1 && mmc partconf 0 1 1 1 && mmc erase 0x0 0x400 && mmc write $loadaddr 0x0 0x100 ; mmc partconf 0 1 1 0
+emmc_write_hdr=mmc dev 0 0 && mmc erase 0x0 0x40 && mmc write $loadaddr 0x0 0x40
+emmc_write_bl3=mmc dev 0 0 && mmc erase 0x1000 0x800 && mmc write $loadaddr 0x1000 0x800
+emmc_write_bl3=mmc dev 0 0 && mmc erase 0x1000 0x800 && mmc write $loadaddr 0x1000 0x800 && mmc erase 0x2000 0x800
+emmc_write_production=iminfo $loadaddr && mmc dev 0 && part start mmc 0 $part_default part_addr && part size mmc 0 $part_default part_size && run mmc_write_vol
+emmc_write_recovery=iminfo $loadaddr && mmc dev 0 && part start mmc 0 $part_recovery part_addr && part size mmc 0 $part_recovery part_size && run mmc_write_vol
+emmc_init_bl=run sdmmc_read_emmc_bl2 && run emmc_write_bl2 && run sdmmc_read_emmc_hdr && run emmc_write_hdr && run sdmmc_read_emmc_bl3 && run emmc_write_bl3

View File

@ -0,0 +1,452 @@
--- /dev/null
+++ b/configs/mt7622_ubnt_unifi-6-lr_defconfig
@@ -0,0 +1,138 @@
+CONFIG_ARM=y
+CONFIG_POSITION_INDEPENDENT=y
+CONFIG_ARCH_MEDIATEK=y
+CONFIG_TARGET_MT7622=y
+CONFIG_SYS_TEXT_BASE=0x41e00000
+CONFIG_SYS_MALLOC_F_LEN=0x4000
+CONFIG_USE_DEFAULT_ENV_FILE=y
+CONFIG_ENV_IS_IN_MTD=y
+CONFIG_ENV_MTD_NAME="nor0"
+CONFIG_ENV_SIZE_REDUND=0x0
+CONFIG_ENV_SIZE=0x1000
+CONFIG_ENV_OFFSET=0xc0000
+CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
+CONFIG_BOARD_LATE_INIT=y
+CONFIG_RESET_BUTTON_SETTLE_DELAY=200
+CONFIG_BOOTP_SEND_HOSTNAME=y
+CONFIG_DEFAULT_ENV_FILE="ubnt_unifi-6-lr_env"
+CONFIG_DEBUG_UART_BASE=0x11002000
+CONFIG_DEBUG_UART_CLOCK=25000000
+CONFIG_DEFAULT_DEVICE_TREE="mt7622-ubnt-unifi-6-lr"
+CONFIG_DEBUG_UART=y
+CONFIG_SMBIOS_PRODUCT_NAME=""
+CONFIG_AUTOBOOT_KEYED=y
+CONFIG_BOOTDELAY=30
+CONFIG_AUTOBOOT_MENU_SHOW=y
+CONFIG_CFB_CONSOLE_ANSI=y
+CONFIG_BUTTON=y
+CONFIG_BUTTON_GPIO=y
+CONFIG_GPIO_HOG=y
+CONFIG_CMD_ENV_FLAGS=y
+CONFIG_FIT=y
+CONFIG_FIT_ENABLE_SHA256_SUPPORT=y
+CONFIG_LOGLEVEL=7
+CONFIG_LOG=y
+CONFIG_DEFAULT_FDT_FILE="mt7622-ubnt-unifi-6-lr"
+CONFIG_SYS_PROMPT="MT7622> "
+# CONFIG_LEGACY_IMAGE_FORMAT is not set
+# CONFIG_BOOTM_PLAN9 is not set
+# CONFIG_BOOTM_RTEMS is not set
+# CONFIG_BOOTM_VXWORKS is not set
+# CONFIG_EFI is not set
+# CONFIG_EFI_LOADER is not set
+CONFIG_CMD_BOOTMENU=y
+# CONFIG_CMD_BOOTEFI is not set
+CONFIG_CMD_BOOTP=y
+CONFIG_CMD_BUTTON=y
+CONFIG_CMD_CDP=y
+CONFIG_CMD_DHCP=y
+CONFIG_CMD_DNS=y
+CONFIG_CMD_ECHO=y
+# CONFIG_CMD_ELF is not set
+# CONFIG_CMD_BOOTEFI_BOOTMGR is not set
+CONFIG_CMD_ENV_READMEM=y
+CONFIG_CMD_ERASEENV=y
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_HASH=y
+CONFIG_CMD_ITEST=y
+CONFIG_CMD_LED=y
+CONFIG_CMD_LINK_LOCAL=y
+# CONFIG_CMD_MBR is not set
+CONFIG_CMD_MTD=y
+CONFIG_CMD_MTDPART=y
+# CONFIG_CMD_PCI is not set
+CONFIG_CMD_SF_TEST=y
+CONFIG_CMD_PING=y
+CONFIG_CMD_PXE=y
+CONFIG_CMD_SMC=y
+CONFIG_CMD_TFTPBOOT=y
+CONFIG_CMD_TFTPSRV=y
+# CONFIG_CMD_UNLZ4 is not set
+CONFIG_CMD_ASKENV=y
+# CONFIG_CMD_PSTORE is not set
+CONFIG_CMD_RARP=y
+CONFIG_CMD_SETEXPR=y
+CONFIG_CMD_SLEEP=y
+CONFIG_CMD_SOURCE=y
+CONFIG_CMD_UUID=y
+CONFIG_DISPLAY_CPUINFO=y
+CONFIG_DM_ETH=y
+CONFIG_DM_ETH_PHY=y
+CONFIG_DM_GPIO=y
+CONFIG_DM_MDIO=y
+CONFIG_DM_MTD=y
+CONFIG_DM_REGULATOR=y
+CONFIG_DM_REGULATOR_FIXED=y
+CONFIG_DM_REGULATOR_GPIO=y
+# CONFIG_DM_MMC is not set
+CONFIG_DM_SERIAL=y
+CONFIG_DM_SPI=y
+CONFIG_DM_SPI_FLASH=y
+CONFIG_HUSH_PARSER=y
+# CONFIG_PARTITION_UUIDS is not set
+CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+# CONFIG_LED is not set
+# CONFIG_LZ4 is not set
+CONFIG_VERSION_VARIABLE=y
+CONFIG_NETCONSOLE=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
+CONFIG_CLK=y
+CONFIG_PHY=y
+CONFIG_PHY_FIXED=y
+CONFIG_PHYLIB_10G=y
+CONFIG_PHY_AQUANTIA=y
+CONFIG_PHY_ADDR_ENABLE=y
+CONFIG_PHY_ADDR=8
+CONFIG_MEDIATEK_ETH=y
+CONFIG_MTD=y
+# CONFIG_MMC is not set
+CONFIG_PINCTRL=y
+CONFIG_PINCONF=y
+CONFIG_PINCTRL_MT7622=y
+CONFIG_POWER_DOMAIN=y
+CONFIG_PRE_CONSOLE_BUFFER=y
+CONFIG_PRE_CON_BUF_ADDR=0x4007EF00
+CONFIG_MTK_POWER_DOMAIN=y
+CONFIG_RAM=y
+CONFIG_MTK_SERIAL=y
+CONFIG_SPI=y
+CONFIG_MTK_SNFI_SPI=y
+CONFIG_MTK_SNOR=y
+CONFIG_SYSRESET_WATCHDOG=y
+CONFIG_WDT_MTK=y
+CONFIG_HEXDUMP=y
+CONFIG_RANDOM_UUID=y
+CONFIG_REGEX=y
+CONFIG_SPI_FLASH=y
+CONFIG_SPI_FLASH_BAR=y
+CONFIG_SPI_FLASH_MTD=y
+CONFIG_SPI_FLASH_UNLOCK_ALL=y
+CONFIG_SPI_FLASH_EON=y
+CONFIG_SPI_FLASH_GIGADEVICE=y
+CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_SPI_FLASH_SPANSION=y
+CONFIG_SPI_FLASH_STMICRO=y
+CONFIG_SPI_FLASH_SST=y
+CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_SPI_FLASH_XMC=y
--- /dev/null
+++ b/arch/arm/dts/mt7622-ubnt-unifi-6-lr.dts
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ * Author: Sam Shih <sam.shih@mediatek.com>
+ */
+
+/dts-v1/;
+#include "mt7622.dtsi"
+#include "mt7622-u-boot.dtsi"
+
+/ {
+ #address-cells = <1>;
+ #size-cells = <1>;
+ model = "mt7622-ubnt-unifi-6-lr";
+ compatible = "mediatek,mt7622", "ubnt,unifi-6-lr";
+
+ chosen {
+ stdout-path = &uart0;
+ tick-timer = &timer0;
+ };
+
+ aliases {
+ spi0 = &snor;
+ };
+
+ gpio-keys {
+ compatible = "gpio-keys";
+ u-boot,dm-pre-reloc;
+
+ reset {
+ label = "reset";
+ gpios = <&gpio 62 GPIO_ACTIVE_LOW>;
+ u-boot,dm-pre-reloc;
+ };
+ };
+
+ memory@40000000 {
+ device_type = "memory";
+ reg = <0x40000000 0x20000000>;
+ };
+
+ reg_1p8v: regulator-1p8v {
+ compatible = "regulator-fixed";
+ regulator-name = "fixed-1.8V";
+ regulator-min-microvolt = <1800000>;
+ regulator-max-microvolt = <1800000>;
+ regulator-boot-on;
+ regulator-always-on;
+ };
+
+ reg_3p3v: regulator-3p3v {
+ compatible = "regulator-fixed";
+ regulator-name = "fixed-3.3V";
+ regulator-min-microvolt = <3300000>;
+ regulator-max-microvolt = <3300000>;
+ regulator-boot-on;
+ regulator-always-on;
+ };
+
+ reg_5v: regulator-5v {
+ compatible = "regulator-fixed";
+ regulator-name = "fixed-5V";
+ regulator-min-microvolt = <5000000>;
+ regulator-max-microvolt = <5000000>;
+ regulator-boot-on;
+ regulator-always-on;
+ };
+};
+
+&pcie {
+ pinctrl-names = "default";
+ pinctrl-0 = <&pcie0_pins>, <&pcie1_pins>;
+ status = "okay";
+
+ pcie@0,0 {
+ status = "okay";
+ };
+
+ pcie@1,0 {
+ status = "okay";
+ };
+};
+
+&pinctrl {
+ eth_pins: eth-pins {
+ mux {
+ function = "eth";
+ groups = "mdc_mdio", "rgmii_via_gmac2";
+ };
+ };
+
+ pcie0_pins: pcie0-pins {
+ mux {
+ function = "pcie";
+ groups = "pcie0_pad_perst",
+ "pcie0_1_waken",
+ "pcie0_1_clkreq";
+ };
+ };
+
+ pcie1_pins: pcie1-pins {
+ mux {
+ function = "pcie";
+ groups = "pcie1_pad_perst",
+ "pcie1_0_waken",
+ "pcie1_0_clkreq";
+ };
+ };
+
+ snfi_pins: snfi-pins {
+ mux {
+ function = "flash";
+ groups = "snfi";
+ };
+ };
+
+ snor_pins: snor-pins {
+ mux {
+ function = "flash";
+ groups = "spi_nor";
+ };
+ };
+
+ uart0_pins: uart0 {
+ mux {
+ function = "uart";
+ groups = "uart0_0_tx_rx" ;
+ };
+ };
+
+ watchdog_pins: watchdog-default {
+ mux {
+ function = "watchdog";
+ groups = "watchdog";
+ };
+ };
+};
+
+&snfi {
+ pinctrl-names = "default", "snfi";
+ pinctrl-0 = <&snor_pins>;
+ pinctrl-1 = <&snfi_pins>;
+ status = "okay";
+
+ spi-flash@0 {
+ compatible = "jedec,spi-nor";
+ reg = <0>;
+ u-boot,dm-pre-reloc;
+ };
+};
+
+&snor {
+ pinctrl-names = "default";
+ pinctrl-0 = <&snor_pins>;
+ status = "okay";
+
+ spi-flash@0 {
+ compatible = "jedec,spi-nor";
+ reg = <0>;
+ spi-tx-bus-width = <1>;
+ spi-rx-bus-width = <4>;
+ u-boot,dm-pre-reloc;
+ };
+};
+
+&uart0 {
+ pinctrl-names = "default";
+ pinctrl-0 = <&uart0_pins>;
+ status = "okay";
+};
+
+&watchdog {
+ pinctrl-names = "default";
+ pinctrl-0 = <&watchdog_pins>;
+ status = "okay";
+};
+
+&eth {
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&eth_pins>;
+
+ mediatek,gmac-id = <0>;
+ phy-mode = "sgmii";
+ phy-handle = <&gphy>;
+
+ fixed-link {
+ speed = <1000>;
+ full-duplex;
+ };
+
+ mdio-bus {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ gphy: ethernet-phy@8 {
+ /* Marvell AQRate AQR112W - no driver */
+ compatible = "ethernet-phy-ieee802.3-c45";
+ reg = <0x8>;
+ };
+ };
+};
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1008,6 +1008,7 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \
mt7623a-unielec-u7623-02-emmc.dtb \
mt7622-bananapi-bpi-r64.dtb \
mt7622-linksys-e8450-ubi.dtb \
+ mt7622-ubnt-unifi-6-lr.dtb \
mt7623n-bananapi-bpi-r2.dtb \
mt7629-rfb.dtb \
mt8512-bm1-emmc.dtb \
--- /dev/null
+++ b/ubnt_unifi-6-lr_env
@@ -0,0 +1,51 @@
+mtdparts=nor0:128k(bl2),640k(fip),64k(u-boot-env),256k(factory),64k(eeprom),15232k(recovery),-(firmware)
+ethaddr_factory=mtd read nor0 $loadaddr 0x110000 0x10000 && env readmem -b ethaddr $loadaddr 0x6 ; setenv ethaddr_factory
+ipaddr=192.168.1.1
+serverip=192.168.1.254
+loadaddr=0x40080000
+bootcmd=run boot_nor
+bootdelay=0
+bootfile=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-ubootmod-initramfs-recovery.itb
+bootfile_bl2=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-ubootmod-preloader.bin
+bootfile_fip=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-ubootmod-bl31-uboot.fip
+bootfile_upg=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-ubootmod-squashfs-sysupgrade.itb
+bootmenu_confirm_return=askenv - Press ENTER to return to menu ; bootmenu 60
+bootmenu_default=0
+bootmenu_delay=0
+bootmenu_title= ( ( ( OpenWrt ) ) )
+bootmenu_0=Initialize environment.=run _firstboot
+bootmenu_0d=Run default boot command.=run boot_default
+bootmenu_1=Boot system via TFTP.=run boot_tftp ; run bootmenu_confirm_return
+bootmenu_2=Boot production system from flash.=run boot_production ; run bootmenu_confirm_return
+bootmenu_3=Boot recovery system from flash.=run boot_recovery ; run bootmenu_confirm_return
+bootmenu_4=Load production system via TFTP then write to flash.=setenv noboot 1 ; run boot_tftp_production ; setenv noboot ; run bootmenu_confirm_return
+bootmenu_5=Load recovery system via TFTP then write to flash.=setenv noboot 1 ; run boot_tftp_recovery ; setenv noboot ; run bootmenu_confirm_return
+bootmenu_6=Load BL31+U-Boot FIP via TFTP then write to flash.=run boot_tftp_write_fip ; run bootmenu_confirm_return
+bootmenu_7=Load BL2 preloader via TFTP then write to flash.=run boot_tftp_write_preloader ; run bootmenu_confirm_return
+bootmenu_8=Reboot.=reset
+bootmenu_9=Reset all settings to factory defaults.=run reset_factory ; reset
+boot_first=if button reset ; then run boot_tftp_forever ; fi ; bootmenu
+boot_default=run bootcmd ; run boot_recovery ; run boot_tftp_forever
+boot_production=run nor_read_production && bootm $loadaddr
+boot_production_or_recovery=run boot_production ; run boot_recovery
+boot_recovery=run nor_read_recovery ; bootm $loadaddr
+boot_serial_write_fip=loadx $loadaddr 115200 && run boot_write_fip
+boot_serial_write_preloader=loadx $loadaddr 115200 && run boot_write_preloader
+boot_tftp_forever=while true ; do run boot_tftp_recovery ; sleep 1 ; done
+boot_tftp_production=tftpboot $loadaddr $bootfile_upg && iminfo $loadaddr && run nor_write_production ; if env exists noboot ; then else bootm $loadaddr ; fi
+boot_tftp_recovery=tftpboot $loadaddr $bootfile && iminfo $loadaddr && run nor_write_recovery ; if env exists noboot ; then else bootm $loadaddr ; fi
+boot_tftp=tftpboot $loadaddr $bootfile && bootm $loadaddr
+boot_tftp_write_fip=tftpboot $loadaddr $bootfile_fip && run boot_write_fip
+boot_tftp_write_preloader=tftpboot $loadaddr $bootfile_bl2 && run boot_write_preloader
+boot_nor=run boot_production_or_recovery
+boot_write_fip=mtd erase nor0 0x20000 0x80000 && mtd write nor0 $loadaddr 0x20000 0x80000
+boot_write_preloader=mtd erase nor0 0x0 0x20000 && mtd write nor0 $loadaddr 0x0 0x20000
+reset_factory=mtd erase nor0 0xc0000 0x10000 && reset
+nor_read_production=mtd read nor0 $loadaddr 0x1000000 0x1000 && imsz $loadaddr image_size && mtd read nor0 $loadaddr 0x1000000 $image_size
+nor_read_recovery=mtd read nor0 $loadaddr 0x120000 0x1000 && imsz $loadaddr image_size && mtd read nor0 $loadaddr 0x120000 $image_size
+nor_write_production=mtd write nor0 $loadaddr 0x1000000 $filesize
+nor_write_recovery=mtd write nor0 $loadaddr 0x120000 $filesize
+_init_env=setenv _init_env ; saveenv
+_firstboot=setenv _firstboot ; run _switch_to_menu ; run ethaddr_factory ; run _init_env ; run boot_first
+_switch_to_menu=setenv _switch_to_menu ; setenv bootdelay 3 ; setenv bootmenu_delay 3 ; setenv bootmenu_0 $bootmenu_0d ; setenv bootmenu_0d ; run _bootmenu_update_title
+_bootmenu_update_title=setenv _bootmenu_update_title ; setenv bootmenu_title "$bootmenu_title $ver"
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -77,6 +77,7 @@
#ifdef CONFIG_EFI_SETUP_EARLY
#include <efi_loader.h>
#endif
+#include <spi_flash.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -410,6 +411,21 @@ static int initr_onenand(void)
}
#endif
+#if defined(CONFIG_SPI_FLASH)
+/* probe SPI FLASH */
+static int initr_spiflash(void)
+{
+ struct udevice *new;
+
+ spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS,
+ CONFIG_SF_DEFAULT_CS,
+ CONFIG_SF_DEFAULT_SPEED,
+ CONFIG_SF_DEFAULT_MODE,
+ &new);
+ return 0;
+}
+#endif
+
#ifdef CONFIG_MMC
static int initr_mmc(void)
{
@@ -697,6 +713,9 @@ static init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_CMD_ONENAND
initr_onenand,
#endif
+#ifdef CONFIG_SPI_FLASH
+ initr_spiflash,
+#endif
#ifdef CONFIG_MMC
initr_mmc,
#endif

View File

@ -8,9 +8,9 @@ PKG_LICENSE_FILES:=
PKG_SOURCE_URL:=https://github.com/openwrt/mt76
PKG_SOURCE_PROTO:=git
PKG_SOURCE_DATE:=2021-04-04
PKG_SOURCE_VERSION:=f8c6c7cbf10f06d10bb7bbdabfd7517f9f311335
PKG_MIRROR_HASH:=de5c6e8d2a9572f6ee4614056a1ff2c2059883414edbeba9efdb0e8571609cc8
PKG_SOURCE_DATE:=2021-04-07
PKG_SOURCE_VERSION:=813db729c02ffa74fdda6d461afeb5aabc5706bb
PKG_MIRROR_HASH:=63bd913f8ba3e85ae7a4575737a2c66377ebf59fa543e025150c650dd9ae13f2
PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name>
PKG_BUILD_PARALLEL:=1

View File

@ -0,0 +1,52 @@
# SPDX-License-Identifier: GPL-2.0-only
include $(TOPDIR)/rules.mk
PKG_NAME:=bcm4908img
PKG_RELEASE:=1
PKG_BUILD_DEPENDS := bcm4908img/host
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/host-build.mk
define Package/bcm4908img
SECTION:=utils
CATEGORY:=Base system
TITLE:=Utility handling BCM4908 images
MAINTAINER:=Rafał Miłecki <rafal@milecki.pl>
DEPENDS:=@TARGET_bcm4908
endef
define Package/bcm4908img/description
CFE bootloader for BCM4908 uses custom image format. It consists of:
1. Optional cferom image
2. bootfs JFFS2 partition (cferam, kernel, DTB and optional helper files)
3. padding
4. rootfs simply appended to the bootfs + padding
5. tail with checksum and basic device info
This util allows creating, modifying and extracting from BCM4908 images.
endef
define Host/Prepare
$(CP) ./src/* $(HOST_BUILD_DIR)
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
CFLAGS="$(TARGET_CFLAGS) -Wall"
endef
define Package/bcm4908img/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bcm4908img $(1)/usr/bin/
endef
define Host/Install
$(INSTALL_BIN) $(HOST_BUILD_DIR)/bcm4908img $(STAGING_DIR_HOST)/bin/
endef
$(eval $(call BuildPackage,bcm4908img))
$(eval $(call HostBuild))

View File

@ -0,0 +1,7 @@
all: bcm4908img
bcm4908img:
$(CC) $(CFLAGS) -o $@ bcm4908img.c -Wall
clean:
rm -f bcm4908img

View File

@ -6,6 +6,7 @@
#include <byteswap.h>
#include <endian.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@ -54,6 +55,8 @@
#define WFI_FLAG_HAS_PMC 0x1
#define WFI_FLAG_SUPPORTS_BTRM 0x2
#define UBI_EC_HDR_MAGIC 0x55424923
static int debug;
struct bcm4908img_tail {
@ -64,11 +67,23 @@ struct bcm4908img_tail {
uint32_t flags;
};
/* Info about BCM4908 image */
/**
* struct bcm4908img_info - info about BCM4908 image
*
* Standard BCM4908 image consists of:
* 1. (Optional) vedor header
* 2. (Optional) cferom
* 3. bootfs
* 4. padding firmware
* 5. rootfs
* 6. BCM4908 tail
*/
struct bcm4908img_info {
size_t file_size;
size_t vendor_header_size; /* Vendor header size */
size_t cferom_size;
size_t cferom_offset;
size_t bootfs_offset;
size_t padding_offset;
size_t rootfs_offset;
uint32_t crc32; /* Calculated checksum */
struct bcm4908img_tail tail;
};
@ -200,10 +215,11 @@ static int bcm4908img_calc_crc32(FILE *fp, struct bcm4908img_info *info) {
size_t length;
size_t bytes;
fseek(fp, info->vendor_header_size, SEEK_SET);
/* Start with cferom (or bootfs) - skip vendor header */
fseek(fp, info->cferom_offset, SEEK_SET);
info->crc32 = 0xffffffff;
length = info->file_size - info->vendor_header_size - sizeof(struct bcm4908img_tail);
length = info->file_size - info->cferom_offset - sizeof(struct bcm4908img_tail);
while (length && (bytes = fread(buf, 1, bcm4908img_min(sizeof(buf), length), fp)) > 0) {
info->crc32 = bcm4908img_crc32(info->crc32, buf, bytes);
length -= bytes;
@ -233,6 +249,19 @@ struct chk_header {
char board_id[0];
};
static bool bcm4908img_is_all_ff(const void *buf, size_t length)
{
const uint8_t *in = buf;
int i;
for (i = 0; i < length; i++) {
if (in[i] != 0xff)
return false;
}
return true;
}
static int bcm4908img_parse(FILE *fp, struct bcm4908img_info *info) {
struct bcm4908img_tail *tail = &info->tail;
struct chk_header *chk;
@ -263,14 +292,16 @@ static int bcm4908img_parse(FILE *fp, struct bcm4908img_info *info) {
}
chk = (void *)buf;
if (be32_to_cpu(chk->magic) == 0x2a23245e)
info->vendor_header_size = be32_to_cpu(chk->header_len);
info->cferom_offset = be32_to_cpu(chk->header_len);
/* Sizes */
/* Offsets */
for (; info->vendor_header_size + info->cferom_size <= info->file_size; info->cferom_size += 0x20000) {
if (fseek(fp, info->vendor_header_size + info->cferom_size, SEEK_SET)) {
for (info->bootfs_offset = info->cferom_offset;
info->bootfs_offset < info->file_size;
info->bootfs_offset += 0x20000) {
if (fseek(fp, info->bootfs_offset, SEEK_SET)) {
err = -errno;
fprintf(stderr, "Failed to fseek to the 0x%zx\n", info->cferom_size);
fprintf(stderr, "Failed to fseek to the 0x%zx\n", info->bootfs_offset);
return err;
}
if (fread(&tmp16, 1, sizeof(tmp16), fp) != sizeof(tmp16)) {
@ -280,17 +311,47 @@ static int bcm4908img_parse(FILE *fp, struct bcm4908img_info *info) {
if (be16_to_cpu(tmp16) == 0x8519)
break;
}
if (info->vendor_header_size + info->cferom_size >= info->file_size) {
fprintf(stderr, "Failed to find cferom size (no bootfs found)\n");
if (info->bootfs_offset >= info->file_size) {
fprintf(stderr, "Failed to find bootfs offset\n");
return -EPROTO;
}
for (info->rootfs_offset = info->bootfs_offset;
info->rootfs_offset < info->file_size;
info->rootfs_offset += 0x20000) {
uint32_t *magic = (uint32_t *)&buf[0];
if (fseek(fp, info->rootfs_offset, SEEK_SET)) {
err = -errno;
fprintf(stderr, "Failed to fseek: %d\n", err);
return err;
}
length = info->padding_offset ? sizeof(*magic) : 256;
bytes = fread(buf, 1, length, fp);
if (bytes != length) {
fprintf(stderr, "Failed to read %zu bytes\n", length);
return -EIO;
}
if (!info->padding_offset && bcm4908img_is_all_ff(buf, length))
info->padding_offset = info->rootfs_offset;
if (be32_to_cpu(*magic) == UBI_EC_HDR_MAGIC)
break;
}
if (info->rootfs_offset >= info->file_size) {
fprintf(stderr, "Failed to find rootfs offset\n");
return -EPROTO;
}
/* CRC32 */
fseek(fp, info->vendor_header_size, SEEK_SET);
/* Start with cferom (or bootfs) - skip vendor header */
fseek(fp, info->cferom_offset, SEEK_SET);
info->crc32 = 0xffffffff;
length = info->file_size - info->vendor_header_size - sizeof(*tail);
length = info->file_size - info->cferom_offset - sizeof(*tail);
while (length && (bytes = fread(buf, 1, bcm4908img_min(sizeof(buf), length), fp)) > 0) {
info->crc32 = bcm4908img_crc32(info->crc32, buf, bytes);
length -= bytes;
@ -349,8 +410,12 @@ static int bcm4908img_info(int argc, char **argv) {
goto err_close;
}
printf("Vendor header length:\t%zu\n", info.vendor_header_size);
printf("cferom size:\t0x%zx\n", info.cferom_size);
if (info.bootfs_offset != info.cferom_offset)
printf("cferom offset:\t%zu\n", info.cferom_offset);
printf("bootfs offset:\t0x%zx\n", info.bootfs_offset);
if (info.padding_offset)
printf("padding offset:\t0x%zx\n", info.padding_offset);
printf("rootfs offset:\t0x%zx\n", info.rootfs_offset);
printf("Checksum:\t0x%08x\n", info.crc32);
err_close:
@ -502,8 +567,8 @@ out:
static int bcm4908img_extract(int argc, char **argv) {
struct bcm4908img_info info;
const char *pathname = NULL;
const char *type = NULL;
uint8_t buf[1024];
const char *type;
size_t offset;
size_t length;
size_t bytes;
@ -535,16 +600,26 @@ static int bcm4908img_extract(int argc, char **argv) {
goto err_close;
}
if (!strcmp(type, "cferom")) {
offset = 0;
length = info.cferom_size;
if (!type) {
err = -EINVAL;
fprintf(stderr, "No data to extract specified\n");
goto err_close;
} else if (!strcmp(type, "cferom")) {
offset = info.cferom_offset;
length = info.bootfs_offset - offset;
if (!length) {
err = -ENOENT;
fprintf(stderr, "This BCM4908 image doesn't contain cferom\n");
goto err_close;
}
} else if (!strcmp(type, "bootfs")) {
offset = info.bootfs_offset;
length = (info.padding_offset ? info.padding_offset : info.rootfs_offset) - offset;
} else if (!strcmp(type, "rootfs")) {
offset = info.rootfs_offset;
length = info.file_size - offset - sizeof(struct bcm4908img_tail);
} else if (!strcmp(type, "firmware")) {
offset = info.vendor_header_size + info.cferom_size;
offset = info.bootfs_offset;
length = info.file_size - offset - sizeof(struct bcm4908img_tail);
} else {
err = -EINVAL;
@ -554,7 +629,7 @@ static int bcm4908img_extract(int argc, char **argv) {
if (!length) {
err = -EINVAL;
fprintf(stderr, "No data to extract specified\n");
fprintf(stderr, "Failed to find requested data in input image\n");
goto err_close;
}
@ -648,7 +723,7 @@ static int bcm4908img_bootfs_ls(FILE *fp, struct bcm4908img_info *info) {
size_t bytes;
int err = 0;
for (offset = info->vendor_header_size + info->cferom_size; ; offset += (je32_to_cpu(node.totlen) + 0x03) & ~0x03) {
for (offset = info->bootfs_offset; ; offset += (je32_to_cpu(node.totlen) + 0x03) & ~0x03) {
char name[FILENAME_MAX + 1];
if (fseek(fp, offset, SEEK_SET)) {
@ -719,7 +794,7 @@ static int bcm4908img_bootfs_mv(FILE *fp, struct bcm4908img_info *info, int argc
return -EINVAL;
}
for (offset = info->vendor_header_size + info->cferom_size; ; offset += (je32_to_cpu(node.totlen) + 0x03) & ~0x03) {
for (offset = info->bootfs_offset; ; offset += (je32_to_cpu(node.totlen) + 0x03) & ~0x03) {
char name[FILENAME_MAX];
uint32_t crc32;

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "ar7240.dtsi"
#include "ar724x_senao_loader.dtsi"
#include "ar724x_senao_loader-64k.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "ar7242.dtsi"
#include "ar724x_senao_loader.dtsi"
#include "ar724x_senao_loader-4k.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "ar7242.dtsi"
#include "ar724x_senao_loader.dtsi"
#include "ar724x_senao_loader-4k.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

View File

@ -0,0 +1,84 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include <dt-bindings/mtd/partitions/uimage.h>
/ {
virtual_flash {
compatible = "mtd-concat";
devices = <&fwconcat0 &fwconcat1>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
compatible = "openwrt,uimage", "denx,uimage";
openwrt,ih-magic = <0x73714f4b>;
label = "firmware";
reg = <0x0 0x0>;
};
};
};
};
&spi {
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <20000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x0 0x40000>;
read-only;
};
partition@40000 {
label = "u-boot-env";
reg = <0x40000 0x10000>;
};
partition@50000 {
label = "custom";
reg = <0x50000 0x50000>;
read-only;
};
partition@a0000 {
label = "loader";
reg = <0xa0000 0x1000>;
};
fwconcat1: partition@a1000 {
label = "fwconcat1";
reg = <0xa1000 0xff000>;
};
fwconcat0: partition@1a0000 {
label = "fwconcat0";
reg = <0x1a0000 0x4d0000>;
};
partition@670000 {
label = "failsafe";
reg = <0x670000 0x180000>;
read-only;
};
art: partition@7f0000 {
label = "art";
reg = <0x7f0000 0x10000>;
read-only;
};
};
};
};

View File

@ -15,7 +15,7 @@
partition@0 {
compatible = "openwrt,uimage", "denx,uimage";
openwrt,ih-magic = <IH_MAGIC_OKLI>;
openwrt,ih-magic = <0x73714f4b>;
label = "firmware";
reg = <0x0 0x0>;
};
@ -56,7 +56,6 @@
partition@a0000 {
label = "loader";
reg = <0xa0000 0x10000>;
read-only;
};
fwconcat1: partition@b0000 {
@ -64,15 +63,9 @@
reg = <0xb0000 0xf0000>;
};
partition@1a0000 {
label = "fakeroot";
reg = <0x1a0000 0x10000>;
read-only;
};
fwconcat0: partition@1b0000 {
fwconcat0: partition@1a0000 {
label = "fwconcat0";
reg = <0x1b0000 0x4c0000>;
reg = <0x1a0000 0x4d0000>;
};
partition@670000 {

View File

@ -15,7 +15,7 @@
partition@0 {
compatible = "openwrt,uimage", "denx,uimage";
openwrt,ih-magic = <IH_MAGIC_OKLI>;
openwrt,ih-magic = <0x73714f4b>;
label = "firmware";
reg = <0x0 0x0>;
};
@ -60,7 +60,6 @@
partition@a0000 {
label = "loader";
reg = <0x0a0000 0x010000>;
read-only;
};
fwconcat1: partition@b0000 {
@ -68,15 +67,9 @@
reg = <0x0b0000 0x170000>;
};
partition@220000 {
label = "fakeroot";
reg = <0x220000 0x010000>;
read-only;
};
fwconcat0: partition@230000 {
fwconcat0: partition@220000 {
label = "fwconcat0";
reg = <0x230000 0xbc0000>;
reg = <0x220000 0xbd0000>;
};
partition@df0000 {

View File

@ -85,16 +85,6 @@
pll-data = <0x82000000 0x80000101 0x80001313>;
};
&pcie0 {
status = "okay";
wifi@0,0,0 {
compatible = "qcom,ath10k";
reg = <0x0 0 0 0 0>;
qca,no-eeprom;
};
};
&wmac {
status = "okay";

View File

@ -108,13 +108,3 @@
qca955x-sgmii-fixup;
};
&pcie0 {
status = "okay";
wifi@0,0,0 {
compatible = "qcom,ath10k";
reg = <0x0 0 0 0 0>;
qca,no-eeprom;
};
};

View File

@ -1,13 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
#include "qca955x.dtsi"
#include "qca955x_senao_loader.dtsi"
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
/ {
model = "ALLNET ALL-WAP02860AC";
compatible = "allnet,all-wap02860ac", "qca,qca9558";
model = "ALLNET ALL-WAP02860AC";
aliases {
label-mac-device = &eth0;
@ -22,8 +22,9 @@
reset {
label = "reset";
linux,code = <KEY_RESTART>;
gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
debounce-interval = <60>;
linux,code = <KEY_RESTART>;
};
};
@ -58,11 +59,12 @@
&eth0 {
status = "okay";
pll-data = <0x8e000000 0x80000101 0x80001313>;
phy-handle = <&phy5>;
phy-mode = "rgmii-rxid";
mtd-mac-address = <&art 0x0>;
phy-handle = <&phy5>;
phy-mode = "rgmii-id";
pll-data = <0x82000000 0x80000101 0x80001313>;
};
&mdio0 {
@ -75,67 +77,11 @@
};
};
&pcie0 {
status = "okay";
wifi@0,0 {
compatible = "qcom,ath10k";
reg = <0 0 0 0 0>;
};
};
&pll {
clocks = <&extosc>;
};
&spi {
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x000000 0x040000>;
read-only;
};
partition@40000 {
label = "u-boot-env";
reg = <0x040000 0x010000>;
};
partition@50000 {
label = "custom";
reg = <0x050000 0x050000>;
read-only;
};
partition@a0000 {
compatible = "denx,uimage";
label = "firmware";
reg = <0x0a0000 0xcd0000>;
};
partition@d70000 {
label = "failsafe";
reg = <0xd70000 0x280000>;
read-only;
};
art: partition@ff0000 {
label = "art";
reg = <0xff0000 0x010000>;
read-only;
};
};
&partitions {
art: partition@ff0000 {
label = "art";
reg = <0xff0000 0x010000>;
read-only;
};
};
@ -145,5 +91,4 @@
mtd-cal-data = <&art 0x1000>;
mtd-mac-address = <&art 0x0>;
mtd-mac-address-increment = <1>;
qca-no-eeprom;
};

View File

@ -17,7 +17,7 @@
partition@0 {
compatible = "openwrt,uimage", "denx,uimage";
openwrt,ih-magic = <IH_MAGIC_OKLI>;
openwrt,ih-magic = <0x73714f4b>;
label = "firmware";
reg = <0x0 0x0>;
};
@ -25,6 +25,15 @@
};
};
&pcie0 {
status = "okay";
wifi@0,0,0 {
compatible = "qcom,ath10k";
reg = <0x0 0 0 0 0>;
};
};
&spi {
status = "okay";
@ -58,7 +67,6 @@
partition@a0000 {
label = "loader";
reg = <0x0a0000 0x010000>;
read-only;
};
fwconcat1: partition@b0000 {
@ -66,15 +74,9 @@
reg = <0x0b0000 0x170000>;
};
partition@220000 {
label = "fakeroot";
reg = <0x220000 0x010000>;
read-only;
};
fwconcat0: partition@230000 {
fwconcat0: partition@220000 {
label = "fwconcat0";
reg = <0x230000 0xb40000>;
reg = <0x220000 0xb50000>;
};
partition@d70000 {

View File

@ -1341,7 +1341,7 @@ static int ar934x_nfc_attach_chip(struct nand_chip *nand)
if (ret)
return ret;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
} else if (nand->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT) {
} else if (nand->ecc.engine_type != NAND_ECC_ENGINE_TYPE_SOFT) {
dev_err(dev, "unknown ECC mode %d\n", nand->ecc.engine_type);
#else
} else if (nand->ecc.mode != NAND_ECC_SOFT) {

View File

@ -0,0 +1,64 @@
# U-Boot with the datachk patchset requires image sizes, offsets,
# and checksums to be provided in the U-Boot environment.
# This script is based on the dualboot version for devices that come with 2 OS partitions.
# For Senao boards with a "failsafe" partition image, the process is almost the same.
# Instead of booting a secondary instalation on checksum failure,
# the failsafe image is booted instead.
# These boards also use the OKLI lzma kernel loader and mtd-concat
# So the kernel check is for the loader, the rootfs check is for kernel + rootfs
platform_do_upgrade_failsafe_datachk() {
local setenv_script="/tmp/fw_env_upgrade"
local flash_base=0x9f000000
local kernel_mtd=$(find_mtd_index ${KERNEL_PART:-kernel})
local rootfs_mtd=$(find_mtd_index ${ROOTFS_PART:-rootfs})
local kernel_offset=$(cat /sys/class/mtd/mtd${kernel_mtd}/offset)
local rootfs_offset=$(cat /sys/class/mtd/mtd${rootfs_mtd}/offset)
if [ -n "$IMAGE_LIST" ]; then
KERNEL_FILE=$($IMAGE_LIST | grep $KERNEL_FILE)
ROOTFS_FILE=$($IMAGE_LIST | grep $ROOTFS_FILE)
fi
local kernel_size=$($IMAGE_CMD $KERNEL_FILE | wc -c)
local rootfs_size=$($IMAGE_CMD $ROOTFS_FILE | wc -c)
# rootfs without JFFS2
local rootfs_blocks=$((rootfs_size / 4096))
rootfs_size=$((rootfs_blocks * 4096))
local kernel_md5=$($IMAGE_CMD $KERNEL_FILE | md5sum | cut -d ' ' -f1)
local rootfs_md5=$($IMAGE_CMD $ROOTFS_FILE | dd bs=4k count=$rootfs_blocks iflag=fullblock | md5sum | cut -d ' ' -f1)
# prepare new u-boot-env vars
printf "vmlinux_start_addr 0x%08x\n" $((flash_base + kernel_offset)) >> $setenv_script
printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $setenv_script
printf "vmlinux_checksum %s\n" ${kernel_md5} >> $setenv_script
printf "rootfs_start_addr 0x%08x\n" $((flash_base + rootfs_offset)) >> $setenv_script
printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $setenv_script
printf "rootfs_checksum %s\n" ${rootfs_md5} >> $setenv_script
# store u-boot-env
mkdir -p /var/lock
fw_setenv -s $setenv_script || {
echo 'failed to update U-Boot environment'
exit 1
}
# sysupgrade
sleep 2
sync
echo 3 > /proc/sys/vm/drop_caches
$IMAGE_CMD $KERNEL_FILE | mtd $MTD_ARGS write - ${KERNEL_PART:-kernel}
sleep 2
sync
if [ -n "$UPGRADE_BACKUP" ]; then
$IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j $UPGRADE_BACKUP write - ${ROOTFS_PART:-rootfs}
else
$IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS write - ${ROOTFS_PART:-rootfs}
fi
}

View File

@ -47,6 +47,21 @@ platform_do_upgrade() {
adtran,bsap1840)
redboot_fis_do_upgrade "$1" vmlinux_2
;;
allnet,all-wap02860ac|\
engenius,eap1200h|\
engenius,eap300-v2|\
engenius,eap600|\
engenius,ecb600|\
engenius,ens202ext-v1|\
engenius,enstationac-v1)
IMAGE_LIST="tar tzf $1"
IMAGE_CMD="tar xzOf $1"
KERNEL_PART="loader"
ROOTFS_PART="fwconcat0"
KERNEL_FILE="uImage-lzma.bin"
ROOTFS_FILE="root.squashfs"
platform_do_upgrade_failsafe_datachk "$1"
;;
jjplus,ja76pf2)
redboot_fis_do_upgrade "$1" linux
;;

View File

@ -4,6 +4,7 @@ include $(INCLUDE_DIR)/image.mk
KERNEL_LOADADDR = 0x80060000
DEVICE_VARS += LOADER_FLASH_OFFS LOADER_TYPE
DEVICE_VARS += LOADER_FLASH_MAX LOADER_KERNEL_MAGIC
DEVICE_VARS += NETGEAR_BOARD_ID NETGEAR_HW_ID
DEVICE_VARS += RAS_BOARD RAS_ROOTFS_SIZE RAS_VERSION
@ -30,7 +31,10 @@ define Build/loader-kernel
endef
define Build/loader-okli-compile
$(call Build/loader-common,FLASH_OFFS=$(LOADER_FLASH_OFFS) FLASH_MAX=0)
$(call Build/loader-common, \
FLASH_OFFS=$(LOADER_FLASH_OFFS) \
FLASH_MAX=$(LOADER_FLASH_MAX) \
KERNEL_MAGIC=$(LOADER_KERNEL_MAGIC) )
endef
# Arguments: <output name> <kernel offset>

View File

@ -3,30 +3,38 @@ DEVICE_VARS += SENAO_IMGNAME
# This needs to make /tmp/_sys/sysupgrade.tgz an empty file prior to
# sysupgrade, as otherwise it will implant the old configuration from
# OEM firmware when writing rootfs from factory.bin
# rootfs size and checksum is taken from a squashfs header
# the header does not exist, therefore, supply the size and md5
define Build/senao-tar-gz
-[ -f "$@" ] && \
mkdir -p $@.tmp && \
touch $@.tmp/failsafe.bin && \
echo '#!/bin/sh' > $@.tmp/before-upgrade.sh && \
echo ': > /tmp/_sys/sysupgrade.tgz' >> $@.tmp/before-upgrade.sh && \
echo -n $$(( $$(cat $@ | wc -c) / 4096 * 4096 )) > $@.len && \
dd if=$@ bs=$$(cat $@.len) count=1 | md5sum - | cut -d ' ' -f 1 > $@.md5 && \
echo '#!/bin/sh' > $@.tmp/after-upgrade.sh && \
printf 'fw_setenv rootfs_size 0x%08x\n' $$(cat $@.len) >> $@.tmp/after-upgrade.sh && \
printf 'fw_setenv rootfs_checksum %s\n' $$(cat $@.md5) >> $@.tmp/after-upgrade.sh && \
$(CP) $(KDIR)/loader-$(DEVICE_NAME).uImage \
$@.tmp/openwrt-$(word 1,$(1))-uImage-lzma.bin && \
$(CP) $@ $@.tmp/openwrt-$(word 1,$(1))-root.squashfs && \
$(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
$(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
-C $@.tmp . | gzip -9n > $@ && \
rm -rf $@.tmp
rm -rf $@.tmp $@.len $@.md5
endef
define Device/senao_loader_okli
KERNEL := kernel-bin | append-dtb | lzma | uImage lzma -M 0x4f4b4c49
KERNEL := kernel-bin | append-dtb | lzma | uImage lzma -M 0x73714f4b
LOADER_KERNEL_MAGIC := 0x73714f4b
LOADER_TYPE := bin
COMPILE := loader-$(1).bin loader-$(1).uImage
COMPILE/loader-$(1).bin := loader-okli-compile
COMPILE/loader-$(1).uImage := append-loader-okli $(1) | pad-to 64k | lzma | \
uImage lzma
IMAGES += factory.bin
IMAGE/factory.bin := append-squashfs-fakeroot-be | pad-to $$$$(BLOCKSIZE) | \
append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
IMAGE/factory.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
check-size | senao-tar-gz $$$$(SENAO_IMGNAME)
IMAGE/sysupgrade.bin := $$(IMAGE/factory.bin) | append-metadata
endef

View File

@ -317,11 +317,14 @@ endef
TARGET_DEVICES += alfa-network_r36a
define Device/allnet_all-wap02860ac
$(Device/senao_loader_okli)
SOC := qca9558
DEVICE_VENDOR := ALLNET
DEVICE_MODEL := ALL-WAP02860AC
DEVICE_PACKAGES := ath10k-firmware-qca988x-ct kmod-ath10k-ct
IMAGE_SIZE := 13120k
IMAGE_SIZE := 11584k
LOADER_FLASH_OFFS := 0x220000
SENAO_IMGNAME := senao-allwap02860ac
endef
TARGET_DEVICES += allnet_all-wap02860ac
@ -1021,8 +1024,8 @@ define Device/engenius_eap1200h
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := EAP1200H
DEVICE_PACKAGES := ath10k-firmware-qca988x-ct kmod-ath10k-ct
IMAGE_SIZE := 11520k
LOADER_FLASH_OFFS := 0x230000
IMAGE_SIZE := 11584k
LOADER_FLASH_OFFS := 0x220000
SENAO_IMGNAME := ar71xx-generic-eap1200h
endef
TARGET_DEVICES += engenius_eap1200h
@ -1033,8 +1036,8 @@ define Device/engenius_eap300-v2
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := EAP300
DEVICE_VARIANT := v2
IMAGE_SIZE := 12032k
LOADER_FLASH_OFFS := 0x230000
IMAGE_SIZE := 12096k
LOADER_FLASH_OFFS := 0x220000
SENAO_IMGNAME := senao-eap300v2
endef
TARGET_DEVICES += engenius_eap300-v2
@ -1044,8 +1047,8 @@ define Device/engenius_eap600
SOC := ar9344
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := EAP600
IMAGE_SIZE := 12032k
LOADER_FLASH_OFFS := 0x230000
IMAGE_SIZE := 12096k
LOADER_FLASH_OFFS := 0x220000
SENAO_IMGNAME := senao-eap600
endef
TARGET_DEVICES += engenius_eap600
@ -1081,8 +1084,8 @@ define Device/engenius_ecb600
SOC := ar9344
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := ECB600
IMAGE_SIZE := 12032k
LOADER_FLASH_OFFS := 0x230000
IMAGE_SIZE := 12096k
LOADER_FLASH_OFFS := 0x220000
SENAO_IMGNAME := senao-ecb600
endef
TARGET_DEVICES += engenius_ecb600
@ -1094,8 +1097,8 @@ define Device/engenius_ens202ext-v1
DEVICE_MODEL := ENS202EXT
DEVICE_VARIANT := v1
DEVICE_PACKAGES := rssileds
IMAGE_SIZE := 12032k
LOADER_FLASH_OFFS := 0x230000
IMAGE_SIZE := 12096k
LOADER_FLASH_OFFS := 0x220000
SENAO_IMGNAME := senao-ens202ext
endef
TARGET_DEVICES += engenius_ens202ext-v1
@ -1107,8 +1110,8 @@ define Device/engenius_enstationac-v1
DEVICE_MODEL := EnStationAC
DEVICE_VARIANT := v1
DEVICE_PACKAGES := ath10k-firmware-qca988x-ct kmod-ath10k-ct rssileds
IMAGE_SIZE := 11520k
LOADER_FLASH_OFFS := 0x230000
IMAGE_SIZE := 11584k
LOADER_FLASH_OFFS := 0x220000
SENAO_IMGNAME := ar71xx-generic-enstationac
endef
TARGET_DEVICES += engenius_enstationac-v1

View File

@ -13,6 +13,7 @@ LOADADDR := 0x80060000
LOADER := loader.bin
LOADER_NAME := $(basename $(notdir $(LOADER)))
LOADER_DATA :=
KERNEL_MAGIC :=
TARGET_DIR :=
FLASH_OFFS :=
FLASH_MAX :=
@ -41,6 +42,7 @@ loader-compile: $(PKG_BUILD_DIR)/.prepared
LZMA_TEXT_START=$(LZMA_TEXT_START) \
LOADADDR=$(LOADADDR) \
LOADER_DATA=$(LOADER_DATA) \
KERNEL_MAGIC=$(KERNEL_MAGIC) \
FLASH_OFFS=$(FLASH_OFFS) \
FLASH_MAX=$(FLASH_MAX) \
BOARD="$(BOARD)" \

View File

@ -18,6 +18,7 @@
LOADADDR :=
LZMA_TEXT_START := 0x80a00000
LOADER_DATA :=
KERNEL_MAGIC :=
BOARD :=
FLASH_OFFS :=
FLASH_MAX :=
@ -54,6 +55,10 @@ OBJECTS += data.o
CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(LOADADDR)
endif
ifneq ($(strip $(KERNEL_MAGIC)),)
CFLAGS += -DCONFIG_KERNEL_MAGIC=$(KERNEL_MAGIC)
endif
ifneq ($(strip $(KERNEL_CMDLINE)),)
CFLAGS += -DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"'
endif

View File

@ -189,7 +189,11 @@ static void lzma_init_data(void)
p = flash_base + flash_ofs;
magic = get_be32(p);
#ifdef CONFIG_KERNEL_MAGIC
if (magic == CONFIG_KERNEL_MAGIC) {
#else
if (magic == IH_MAGIC_OKLI) {
#endif
hdr = (struct image_header *) p;
break;
}

View File

@ -33,24 +33,26 @@ TARGET_DEVICES += dlink_dir-615-e4
define Device/engenius_eap350-v1
$(Device/senao_loader_okli)
BLOCKSIZE := 4k
SOC := ar7242
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := EAP350
DEVICE_VARIANT := v1
IMAGE_SIZE := 4864k
LOADER_FLASH_OFFS := 0x1b0000
IMAGE_SIZE := 4928k
LOADER_FLASH_OFFS := 0x1a0000
SENAO_IMGNAME := senao-eap350
endef
TARGET_DEVICES += engenius_eap350-v1
define Device/engenius_ecb350-v1
$(Device/senao_loader_okli)
BLOCKSIZE := 4k
SOC := ar7242
DEVICE_VENDOR := EnGenius
DEVICE_MODEL := ECB350
DEVICE_VARIANT := v1
IMAGE_SIZE := 4864k
LOADER_FLASH_OFFS := 0x1b0000
IMAGE_SIZE := 4928k
LOADER_FLASH_OFFS := 0x1a0000
SENAO_IMGNAME := senao-ecb350
endef
TARGET_DEVICES += engenius_ecb350-v1
@ -62,8 +64,8 @@ define Device/engenius_enh202-v1
DEVICE_MODEL := ENH202
DEVICE_VARIANT := v1
DEVICE_PACKAGES := rssileds
IMAGE_SIZE := 4864k
LOADER_FLASH_OFFS := 0x1b0000
IMAGE_SIZE := 4928k
LOADER_FLASH_OFFS := 0x1a0000
SENAO_IMGNAME := senao-enh202
endef
TARGET_DEVICES += engenius_enh202-v1

View File

@ -5,6 +5,8 @@ IMAGES_DIR := ../../..
DEFAULT_PACKAGES += wpad-basic-wolfssl
KERNEL_TESTING_PATCHVER:=5.10
define Target/Description
Build firmware images for MikroTik devices based on Qualcomm Atheros
MIPS SoCs (AR71xx, AR72xx, AR91xx, AR93xx, QCA95xx).

View File

@ -0,0 +1,64 @@
# U-Boot with the datachk patchset requires image sizes, offsets,
# and checksums to be provided in the U-Boot environment.
# This script is based on the dualboot version for devices that come with 2 OS partitions.
# For Senao boards with a "failsafe" partition image, the process is almost the same.
# Instead of booting a secondary instalation on checksum failure,
# the failsafe image is booted instead.
# These boards also use the OKLI lzma kernel loader and mtd-concat
# So the kernel check is for the loader, the rootfs check is for kernel + rootfs
platform_do_upgrade_failsafe_datachk() {
local setenv_script="/tmp/fw_env_upgrade"
local flash_base=0x9f000000
local kernel_mtd=$(find_mtd_index ${KERNEL_PART:-kernel})
local rootfs_mtd=$(find_mtd_index ${ROOTFS_PART:-rootfs})
local kernel_offset=$(cat /sys/class/mtd/mtd${kernel_mtd}/offset)
local rootfs_offset=$(cat /sys/class/mtd/mtd${rootfs_mtd}/offset)
if [ -n "$IMAGE_LIST" ]; then
KERNEL_FILE=$($IMAGE_LIST | grep $KERNEL_FILE)
ROOTFS_FILE=$($IMAGE_LIST | grep $ROOTFS_FILE)
fi
local kernel_size=$($IMAGE_CMD $KERNEL_FILE | wc -c)
local rootfs_size=$($IMAGE_CMD $ROOTFS_FILE | wc -c)
# rootfs without JFFS2
local rootfs_blocks=$((rootfs_size / 4096))
rootfs_size=$((rootfs_blocks * 4096))
local kernel_md5=$($IMAGE_CMD $KERNEL_FILE | md5sum | cut -d ' ' -f1)
local rootfs_md5=$($IMAGE_CMD $ROOTFS_FILE | dd bs=4k count=$rootfs_blocks iflag=fullblock | md5sum | cut -d ' ' -f1)
# prepare new u-boot-env vars
printf "vmlinux_start_addr 0x%08x\n" $((flash_base + kernel_offset)) >> $setenv_script
printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $setenv_script
printf "vmlinux_checksum %s\n" ${kernel_md5} >> $setenv_script
printf "rootfs_start_addr 0x%08x\n" $((flash_base + rootfs_offset)) >> $setenv_script
printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $setenv_script
printf "rootfs_checksum %s\n" ${rootfs_md5} >> $setenv_script
# store u-boot-env
mkdir -p /var/lock
fw_setenv -s $setenv_script || {
echo 'failed to update U-Boot environment'
exit 1
}
# sysupgrade
sleep 2
sync
echo 3 > /proc/sys/vm/drop_caches
$IMAGE_CMD $KERNEL_FILE | mtd $MTD_ARGS write - ${KERNEL_PART:-kernel}
sleep 2
sync
if [ -n "$UPGRADE_BACKUP" ]; then
$IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j $UPGRADE_BACKUP write - ${ROOTFS_PART:-rootfs}
else
$IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS write - ${ROOTFS_PART:-rootfs}
fi
}

View File

@ -5,6 +5,9 @@
PART_NAME=firmware
REQUIRE_IMAGE_METADATA=1
RAMFS_COPY_BIN='fw_setenv'
RAMFS_COPY_DATA='/etc/fw_env.config'
platform_check_image() {
return 0
}
@ -13,6 +16,17 @@ platform_do_upgrade() {
local board=$(board_name)
case "$board" in
engenius,eap350-v1|\
engenius,ecb350-v1|\
engenius,enh202-v1)
IMAGE_LIST="tar tzf $1"
IMAGE_CMD="tar xzOf $1"
KERNEL_PART="loader"
ROOTFS_PART="fwconcat0"
KERNEL_FILE="uImage-lzma.bin"
ROOTFS_FILE="root.squashfs"
platform_do_upgrade_failsafe_datachk "$1"
;;
*)
default_do_upgrade "$1"
;;

View File

@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk
ARCH:=aarch64
BOARD:=bcm4908
BOARDNAME:=Broadcom BCM4908 (ARMv8A CPUs Brahma-B53)
FEATURES:=squashfs nand usb pci pcie gpio source-only
FEATURES:=squashfs nand usb pci pcie gpio
CPU_TYPE:=cortex-a53
SUBTARGETS:=generic
@ -20,6 +20,8 @@ include $(INCLUDE_DIR)/target.mk
KERNELNAME:=Image dtbs
DEFAULT_PACKAGES += kmod-usb-ohci kmod-usb2 kmod-usb3
DEFAULT_PACKAGES += \
bcm4908img \
kmod-usb-ohci kmod-usb2 kmod-usb3
$(eval $(call BuildTarget))

View File

@ -0,0 +1,213 @@
# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
RAMFS_COPY_BIN="bcm4908img"
PART_NAME=firmware
# $(1): file to read from
# $(2): offset in bytes
# $(3): length in bytes
get_content() {
dd if="$1" skip=$2 bs=1 count=$3 2>/dev/null
}
# $(1): file to read from
# $(2): offset in bytes
get_hex_u32_be() {
dd if="$1" skip=$2 bs=1 count=4 2>/dev/null | hexdump -v -e '1/1 "%02x"'
}
platform_expected_image() {
local machine=$(board_name)
case "$machine" in
asus,gt-ac5300) echo "asus GT-AC5300";;
netgear,r8000p) echo "chk U12H359T00_NETGEAR";;
tplink,archer-c2300-v1) echo "";;
esac
}
platform_identify() {
local magic
local size
magic=$(get_hex_u32_be "$1" 0)
case "$magic" in
2a23245e)
echo "chk"
return
;;
esac
size=$(wc -c "$1" | cut -d ' ' -f 1)
magic=$(get_content "$1" $((size - 20 - 64 + 8)) 12)
case "$magic" in
GT-AC5300)
echo "asus"
return
;;
esac
echo "unknown"
}
platform_check_image() {
[ "$#" -gt 1 ] && return 1
local expected_image=$(platform_expected_image)
local error=0
bcm4908img info -i "$1" > /dev/null || {
echo "Failed to validate BCM4908 image" >&2
notify_firmware_broken
return 1
}
bcm4908img bootfs -i "$1" ls | grep -q "1-openwrt" || {
# OpenWrt images have 1-openwrt dummy file in the bootfs.
# Don't allow backup if it's missing
notify_firmware_no_backup
}
case "$(platform_identify "$1")" in
asus)
local size=$(wc -c "$1" | cut -d ' ' -f 1)
local productid=$(get_content "$1" $((size - 20 - 64 + 8)) 12)
[ -n "$expected_image" -a "asus $productid" != "$expected_image" ] && {
echo "Firmware productid mismatch ($productid)" >&2
error=1
}
;;
chk)
local header_len=$((0x$(get_hex_u32_be "$1" 4)))
local board_id_len=$(($header_len - 40))
local board_id=$(dd if="$1" skip=40 bs=1 count=$board_id_len 2>/dev/null | hexdump -v -e '1/1 "%c"')
[ -n "$expected_image" -a "chk $board_id" != "$expected_image" ] && {
echo "Firmware board_id mismatch ($board_id)" >&2
error=1
}
;;
*)
echo "Invalid image type. Please use firmware specific for this device." >&2
notify_firmware_broken
error=1
;;
esac
return $error
}
# $1: cferam index increment value
platform_calc_new_cferam() {
local inc="$1"
local dir="/tmp/sysupgrade-bcm4908"
local mtd=$(find_mtd_part bootfs)
[ -z "$mtd" ] && {
echo "Failed to find bootfs partition" >&2
return
}
rm -fR $dir
mkdir -p $dir
mount -t jffs2 -o ro $mtd $dir || {
echo "Failed to mount bootfs partition $mtd" >&2
rm -fr $dir
return
}
local idx=$(ls $dir/cferam.??? | sed -n 's/.*cferam\.\(\d\d\d\)/\1/p')
[ -z "$idx" ] && {
echo "Failed to find cferam current index" >&2
rm -fr $dir
return
}
umount $dir
rm -fr $dir
idx=$(((idx + inc) % 1000))
echo $(printf "cferam.%03d" $idx)
}
platform_do_upgrade_ubi() {
local dir="/tmp/sysupgrade-bcm4908"
local inc=1
# Verify new bootfs size
local mtd_bootfs_size=$(grep "\"bootfs\"" /proc/mtd | sed "s/mtd[0-9]*:[ \t]*\([^ \t]*\).*/\1/")
[ -z "$mtd_bootfs_size" ] && {
echo "Unable to find \"bootfs\" partition size"
return
}
mtd_bootfs_size=$((0x$mtd_bootfs_size))
local img_bootfs_size=$(bcm4908img extract -i "$1" -t bootfs | wc -c)
[ $img_bootfs_size -gt $mtd_bootfs_size ] && {
echo "New bootfs doesn't fit MTD partition."
return
}
# Find cferam name for new firmware
# For UBI we always flash "firmware" so don't increase cferam index if
# there is "fallback". That could result in cferam.999 & cferam.001
[ -n "$(find_mtd_index backup)" -o -n "$(find_mtd_index fallback)" ] && inc=0
local cferam=$(platform_calc_new_cferam $inc)
[ -z "$cferam" ] && exit 1
# Prepare new firmware
bcm4908img bootfs -i "$1" mv cferam.000 $cferam || {
echo "Failed to rename cferam.000 to $cferam" >&2
exit 1
}
# Extract rootfs for further flashing
rm -fr $dir
mkdir -p $dir
bcm4908img extract -i "$1" -t rootfs > $dir/root || {
echo "Failed to extract rootfs" >&2
rm -fr $dir
exit 1
}
# Flash bootfs MTD partition with new one
mtd erase bootfs || {
echo "Failed to erase bootfs" >&2
rm -fr $dir
exit 1
}
bcm4908img extract -i "$1" -t bootfs | mtd write - bootfs || {
echo "Failed to flash bootfs" >&2
rm -fr $dir
exit 1
}
nand_do_upgrade $dir/root
}
platform_do_upgrade() {
# Try NAND aware UBI upgrade for OpenWrt images
# Below call will exit on success
bcm4908img bootfs -i "$1" ls | grep -q "1-openwrt" && platform_do_upgrade_ubi "$1"
echo "Writing whole image to NAND flash. All erase counters will be lost."
# Find cferam name for new firmware
local cferam=$(platform_calc_new_cferam 1)
[ -z "$cferam" ] && exit 1
# Prepare new firmware
bcm4908img bootfs -i "$1" mv cferam.000 $cferam || {
echo "Failed to rename cferam.000 to $cferam" >&2
exit 1
}
# Jush flash firmware partition as is
[ -n "$(find_mtd_index backup)" ] && PART_NAME=backup
[ -n "$(find_mtd_index fallback)" ] && PART_NAME=fallback
mtd erase $PART_NAME
default_do_upgrade "$1" "bcm4908img extract -t firmware"
}

View File

@ -4,6 +4,7 @@ include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk
DEVICE_VARS += ASUS_PRODUCTID ASUS_BUILD_NO ASUS_FW_REV ASUS_EXT_NO
DEVICE_VARS += NETGEAR_BOARD_ID NETGEAR_REGION
define Build/bcm4908asus
$(STAGING_DIR_HOST)/bin/bcm4908asus create -i $@ \
@ -20,7 +21,7 @@ define Build/bcm4908img
cp $(KDIR)/bcm63xx-cfe/$(subst _,$(comma),$(DEVICE_NAME))/cferam.000 $@-bootfs/
cp $(IMAGE_KERNEL) $@-bootfs/vmlinux.lz
$(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad --little-endian --squash-uids \
$(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad=0x800000 --little-endian --squash-uids \
-v -e 128KiB -o $@-bootfs.jffs2 -d $@-bootfs -m none -n
$(STAGING_DIR_HOST)/bin/bcm4908img create $@.new -f $@-bootfs.jffs2 \
-a 0x20000 -f $@
@ -47,6 +48,7 @@ define Device/Default
DEVICE_IMG_NAME = $$(DEVICE_IMG_PREFIX)-$$(1).$$(2)
BLOCKSIZE := 128k
PAGESIZE := 2048
IMAGE/bin := append-ubi | bcm4908img
endef
define Device/asus_gt-ac5300
@ -67,7 +69,9 @@ define Device/netgear_r8000p
DEVICE_MODEL := R8000P
DEVICE_DTS := broadcom/bcm4908/bcm4906-netgear-r8000p
IMAGES := bin
IMAGE/bin := append-ubi | bcm4908img
IMAGE/chk := append-ubi | bcm4908img | netgear-chk
NETGEAR_BOARD_ID := U12H359T00_NETGEAR
NETGEAR_REGION := 1
endef
TARGET_DEVICES += netgear_r8000p
@ -78,6 +82,7 @@ define Device/tplink_archer-c2300-v1
DEVICE_DTS := broadcom/bcm4908/bcm4906-tplink-archer-c2300-v1
IMAGES := bin
IMAGE/bin := append-ubi | bcm4908img
BROKEN := y
endef
TARGET_DEVICES += tplink_archer-c2300-v1

View File

@ -112,20 +112,19 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
dsectors = (dsectors>sectors)?sectors:dsectors;
dsize = dsectors << SECTOR_SHIFT;
printk(KERN_DEBUG "FIT: volume size: %llu sectors (%llu bytes)\n", dsectors, dsize);
size = fdt_totalsize(init_fit);
printk(KERN_DEBUG "FIT: FDT structure size: %u bytes\n", size);
/* silently skip non-external-data legacy FIT images */
if (size > PAGE_SIZE) {
printk(KERN_ERR "FIT: FDT structure beyond page boundaries, use 'mkimage -E ...'!\n");
put_page(page);
return -ENOTSUPP;
return 0;
}
if (size >= dsize) {
state->access_beyond_eod = 1;
put_page(page);
state->access_beyond_eod = (size >= dsize);
return 0;
return -EFBIG;
}
fit = kmemdup(init_fit, size, GFP_KERNEL);
@ -158,7 +157,7 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
config_description = fdt_getprop(fit, node, FIT_DESC_PROP, &config_description_len);
config_loadables = fdt_getprop(fit, node, FIT_LOADABLE_PROP, &config_loadables_len);
printk(KERN_DEBUG "FIT: Default configuration: %s%s%s%s\n", config_default,
printk(KERN_DEBUG "FIT: Default configuration: \"%s\"%s%s%s\n", config_default,
config_description?" (":"", config_description?:"", config_description?")":"");
images = fdt_path_offset(fit, FIT_IMAGES_PATH);
@ -190,7 +189,7 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
image_description = fdt_getprop(fit, node, FIT_DESC_PROP, &image_description_len);
printk(KERN_DEBUG "FIT: %16s sub-image 0x%08x - 0x%08x '%s' %s%s%s\n",
printk(KERN_DEBUG "FIT: %16s sub-image 0x%08x - 0x%08x \"%s\" %s%s%s\n",
image_type, image_pos, image_pos + image_len, image_name,
image_description?"(":"", image_description?:"", image_description?") ":"");
@ -230,7 +229,7 @@ int parse_fit_partitions(struct parsed_partitions *state, u64 fit_start_sector,
state->parts[*slot].has_info = true;
if (config_loadables && !strcmp(image_name, config_loadables)) {
printk(KERN_DEBUG "FIT: selecting configured loadable %s to be root filesystem\n", image_name);
printk(KERN_DEBUG "FIT: selecting configured loadable \"%s\" to be root filesystem\n", image_name);
state->parts[*slot].flags |= ADDPART_FLAG_ROOTDEV;
}
}

View File

@ -21,28 +21,173 @@
#include <linux/types.h>
#include <linux/byteorder/generic.h>
#include <linux/slab.h>
#include <linux/libfdt.h>
#include <linux/of_fdt.h>
#include "mtdsplit.h"
struct fdt_header {
uint32_t magic; /* magic word FDT_MAGIC */
uint32_t totalsize; /* total size of DT block */
uint32_t off_dt_struct; /* offset to structure */
uint32_t off_dt_strings; /* offset to strings */
uint32_t off_mem_rsvmap; /* offset to memory reserve map */
uint32_t version; /* format version */
uint32_t last_comp_version; /* last compatible version */
// string macros from git://git.denx.de/u-boot.git/include/image.h
/* version 2 fields below */
uint32_t boot_cpuid_phys; /* Which physical CPU id we're
booting on */
/* version 3 fields below */
uint32_t size_dt_strings; /* size of the strings block */
#define FIT_IMAGES_PATH "/images"
#define FIT_DATA_PROP "data"
#define FIT_DATA_POSITION_PROP "data-position"
#define FIT_DATA_OFFSET_PROP "data-offset"
#define FIT_DATA_SIZE_PROP "data-size"
/* version 17 fields below */
uint32_t size_dt_struct; /* size of the structure block */
};
// functions from git://git.denx.de/u-boot.git/common/image-fit.c
/**
* fit_image_get_data - get data property and its size for a given component image node
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @data: double pointer to void, will hold data property's data address
* @size: pointer to size_t, will hold data property's data size
*
* fit_image_get_data() finds data property in a given component image node.
* If the property is found its data start address and size are returned to
* the caller.
*
* returns:
* 0, on success
* -1, on failure
*/
static int fit_image_get_data(const void *fit, int noffset,
const void **data, size_t *size)
{
int len;
*data = fdt_getprop(fit, noffset, FIT_DATA_PROP, &len);
if (*data == NULL) {
*size = 0;
return -1;
}
*size = len;
return 0;
}
/**
* Get 'data-offset' property from a given image node.
*
* @fit: pointer to the FIT image header
* @noffset: component image node offset
* @data_offset: holds the data-offset property
*
* returns:
* 0, on success
* -ENOENT if the property could not be found
*/
static int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset)
{
const fdt32_t *val;
val = fdt_getprop(fit, noffset, FIT_DATA_OFFSET_PROP, NULL);
if (!val)
return -ENOENT;
*data_offset = fdt32_to_cpu(*val);
return 0;
}
/**
* Get 'data-position' property from a given image node.
*
* @fit: pointer to the FIT image header
* @noffset: component image node offset
* @data_position: holds the data-position property
*
* returns:
* 0, on success
* -ENOENT if the property could not be found
*/
static int fit_image_get_data_position(const void *fit, int noffset,
int *data_position)
{
const fdt32_t *val;
val = fdt_getprop(fit, noffset, FIT_DATA_POSITION_PROP, NULL);
if (!val)
return -ENOENT;
*data_position = fdt32_to_cpu(*val);
return 0;
}
/**
* Get 'data-size' property from a given image node.
*
* @fit: pointer to the FIT image header
* @noffset: component image node offset
* @data_size: holds the data-size property
*
* returns:
* 0, on success
* -ENOENT if the property could not be found
*/
static int fit_image_get_data_size(const void *fit, int noffset, int *data_size)
{
const fdt32_t *val;
val = fdt_getprop(fit, noffset, FIT_DATA_SIZE_PROP, NULL);
if (!val)
return -ENOENT;
*data_size = fdt32_to_cpu(*val);
return 0;
}
/**
* fit_image_get_data_and_size - get data and its size including
* both embedded and external data
* @fit: pointer to the FIT format image header
* @noffset: component image node offset
* @data: double pointer to void, will hold data property's data address
* @size: pointer to size_t, will hold data property's data size
*
* fit_image_get_data_and_size() finds data and its size including
* both embedded and external data. If the property is found
* its data start address and size are returned to the caller.
*
* returns:
* 0, on success
* otherwise, on failure
*/
static int fit_image_get_data_and_size(const void *fit, int noffset,
const void **data, size_t *size)
{
bool external_data = false;
int offset;
int len;
int ret;
if (!fit_image_get_data_position(fit, noffset, &offset)) {
external_data = true;
} else if (!fit_image_get_data_offset(fit, noffset, &offset)) {
external_data = true;
/*
* For FIT with external data, figure out where
* the external images start. This is the base
* for the data-offset properties in each image.
*/
offset += ((fdt_totalsize(fit) + 3) & ~3);
}
if (external_data) {
ret = fit_image_get_data_size(fit, noffset, &len);
if (!ret) {
*data = fit + offset;
*size = len;
}
} else {
ret = fit_image_get_data(fit, noffset, data, size);
}
return ret;
}
static int
mtdsplit_fit_parse(struct mtd_info *mtd,
@ -56,8 +201,11 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
size_t offset;
size_t fit_offset, fit_size;
size_t rootfs_offset, rootfs_size;
size_t data_size, img_total, max_size = 0;
struct mtd_partition *parts;
int ret;
int ret, ndepth, noffset, images_noffset;
const void *img_data;
void *fit;
of_property_read_string(np, "openwrt,cmdline-match", &cmdline_match);
if (cmdline_match && !strstr(saved_command_line, cmdline_match))
@ -99,31 +247,87 @@ mtdsplit_fit_parse(struct mtd_info *mtd,
return -ENODEV;
}
/* Search for the rootfs partition after the FIT image */
ret = mtd_find_rootfs_from(mtd, fit_offset + fit_size, mtd->size,
&rootfs_offset, NULL);
if (ret) {
pr_info("no rootfs found after FIT image in \"%s\"\n",
mtd->name);
return ret;
/*
* Classic uImage.FIT has all data embedded into the FDT
* data structure. Hence the total size of the image equals
* the total size of the FDT structure.
* Modern uImage.FIT may have only references to data in FDT,
* hence we need to parse FDT structure to find the end of the
* last external data refernced.
*/
if (fit_size > 0x1000) {
/* Search for the rootfs partition after the FIT image */
ret = mtd_find_rootfs_from(mtd, fit_offset + fit_size, mtd->size,
&rootfs_offset, NULL);
if (ret) {
pr_info("no rootfs found after FIT image in \"%s\"\n",
mtd->name);
return ret;
}
rootfs_size = mtd->size - rootfs_offset;
parts = kzalloc(2 * sizeof(*parts), GFP_KERNEL);
if (!parts)
return -ENOMEM;
parts[0].name = KERNEL_PART_NAME;
parts[0].offset = fit_offset;
parts[0].size = mtd_rounddown_to_eb(fit_size, mtd) + mtd->erasesize;
parts[1].name = ROOTFS_PART_NAME;
parts[1].offset = rootfs_offset;
parts[1].size = rootfs_size;
*pparts = parts;
return 2;
} else {
/* Search for rootfs_data after FIT external data */
fit = kzalloc(fit_size, GFP_KERNEL);
ret = mtd_read(mtd, offset, fit_size, &retlen, fit);
if (ret) {
pr_err("read error in \"%s\" at offset 0x%llx\n",
mtd->name, (unsigned long long) offset);
return ret;
}
images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
if (images_noffset < 0) {
pr_err("Can't find images parent node '%s' (%s)\n",
FIT_IMAGES_PATH, fdt_strerror(images_noffset));
return -ENODEV;
}
for (ndepth = 0,
noffset = fdt_next_node(fit, images_noffset, &ndepth);
(noffset >= 0) && (ndepth > 0);
noffset = fdt_next_node(fit, noffset, &ndepth)) {
if (ndepth == 1) {
ret = fit_image_get_data_and_size(fit, noffset, &img_data, &data_size);
if (ret)
return 0;
img_total = data_size + (img_data - fit);
max_size = (max_size > img_total) ? max_size : img_total;
}
}
parts = kzalloc(sizeof(*parts), GFP_KERNEL);
if (!parts)
return -ENOMEM;
parts[0].name = ROOTFS_SPLIT_NAME;
parts[0].offset = fit_offset + mtd_rounddown_to_eb(max_size, mtd) + mtd->erasesize;
parts[0].size = mtd->size - parts[0].offset;
*pparts = parts;
kfree(fit);
return 1;
}
rootfs_size = mtd->size - rootfs_offset;
parts = kzalloc(2 * sizeof(*parts), GFP_KERNEL);
if (!parts)
return -ENOMEM;
parts[0].name = KERNEL_PART_NAME;
parts[0].offset = fit_offset;
parts[0].size = mtd_rounddown_to_eb(fit_size, mtd) + mtd->erasesize;
parts[1].name = ROOTFS_PART_NAME;
parts[1].offset = rootfs_offset;
parts[1].size = rootfs_size;
*pparts = parts;
return 2;
}
static const struct of_device_id mtdsplit_fit_of_match_table[] = {

View File

@ -0,0 +1,85 @@
From f9760b158f610b1792a222cc924073724c061bfb Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Wed, 7 Apr 2021 22:37:57 +0100
Subject: [PATCH 1/2] mtd: super: don't reply on mtdblock device minor
To: linux-mtd@lists.infradead.org
Cc: Vignesh Raghavendra <vigneshr@ti.com>,
Richard Weinberger <richard@nod.at>,
Miquel Raynal <miquel.raynal@bootlin.com>,
David Woodhouse <dwmw2@infradead.org>
For blktrans devices with partitions (ie. part_bits != 0) the
assumption that the minor number of the mtdblock device matches
the mtdnum doesn't hold true.
Properly resolve mtd device from blktrans layer instead.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/mtd/mtdsuper.c | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
--- a/drivers/mtd/mtdsuper.c
+++ b/drivers/mtd/mtdsuper.c
@@ -9,6 +9,7 @@
*/
#include <linux/mtd/super.h>
+#include <linux/mtd/blktrans.h>
#include <linux/namei.h>
#include <linux/export.h>
#include <linux/ctype.h>
@@ -121,7 +122,8 @@ int get_tree_mtd(struct fs_context *fc,
{
#ifdef CONFIG_BLOCK
struct block_device *bdev;
- int ret, major;
+ struct mtd_blktrans_dev *blktrans_dev;
+ int ret, major, part_bits;
#endif
int mtdnr;
@@ -169,21 +171,38 @@ int get_tree_mtd(struct fs_context *fc,
/* try the old way - the hack where we allowed users to mount
* /dev/mtdblock$(n) but didn't actually _use_ the blockdev
*/
- bdev = lookup_bdev(fc->source);
+ bdev = blkdev_get_by_path(fc->source, FMODE_READ, NULL);
if (IS_ERR(bdev)) {
ret = PTR_ERR(bdev);
errorf(fc, "MTD: Couldn't look up '%s': %d", fc->source, ret);
return ret;
}
- pr_debug("MTDSB: lookup_bdev() returned 0\n");
+ pr_debug("MTDSB: blkdev_get_by_path() returned 0\n");
major = MAJOR(bdev->bd_dev);
- mtdnr = MINOR(bdev->bd_dev);
- bdput(bdev);
- if (major == MTD_BLOCK_MAJOR)
- return mtd_get_sb_by_nr(fc, mtdnr, fill_super);
+ if (major == MTD_BLOCK_MAJOR) {
+ if (!bdev->bd_disk) {
+ blkdev_put(bdev, FMODE_READ);
+ BUG();
+ return -EINVAL;
+ }
+
+ blktrans_dev = (struct mtd_blktrans_dev *)(bdev->bd_disk->private_data);
+ if (!blktrans_dev || !blktrans_dev->tr) {
+ blkdev_put(bdev, FMODE_READ);
+ BUG();
+ return -EINVAL;
+ }
+ mtdnr = blktrans_dev->devnum;
+ part_bits = blktrans_dev->tr->part_bits;
+ blkdev_put(bdev, FMODE_READ);
+ if (MINOR(bdev->bd_dev) != (mtdnr << part_bits))
+ return -EINVAL;
+ return mtd_get_sb_by_nr(fc, mtdnr, fill_super);
+ }
+ blkdev_put(bdev, FMODE_READ);
#endif /* CONFIG_BLOCK */
if (!(fc->sb_flags & SB_SILENT))

View File

@ -0,0 +1,103 @@
From 0bccc3722bdd88e8ae995e77ef9f7b77ee4cbdee Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Wed, 7 Apr 2021 22:45:54 +0100
Subject: [PATCH 2/2] mtd: blktrans: call add disks after mtd device
To: linux-mtd@lists.infradead.org
Cc: Vignesh Raghavendra <vigneshr@ti.com>,
Richard Weinberger <richard@nod.at>,
Miquel Raynal <miquel.raynal@bootlin.com>,
David Woodhouse <dwmw2@infradead.org>
Calling device_add_disk while holding mtd_table_mutex leads
to deadlock in case part_bits!=0 as block partition parsers
will try to open the newly created disks, trying to acquire
mutex once again.
Move device_add_disk to additional function called after
add partitions of an MTD device have been added and locks
have been released.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/mtd/mtd_blkdevs.c | 33 ++++++++++++++++++++++++++-------
drivers/mtd/mtdcore.c | 3 +++
include/linux/mtd/blktrans.h | 1 +
3 files changed, 30 insertions(+), 7 deletions(-)
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -457,13 +457,6 @@ int add_mtd_blktrans_dev(struct mtd_blkt
if (new->readonly)
set_disk_ro(gd, 1);
- device_add_disk(&new->mtd->dev, gd, NULL);
-
- if (new->disk_attributes) {
- ret = sysfs_create_group(&disk_to_dev(gd)->kobj,
- new->disk_attributes);
- WARN_ON(ret);
- }
return 0;
error4:
kfree(new->tag_set);
@@ -475,6 +468,32 @@ error1:
return ret;
}
+void register_mtd_blktrans_devs(struct mtd_info *mtd)
+{
+ struct mtd_blktrans_ops *tr;
+ struct mtd_blktrans_dev *dev, *next;
+ struct mtd_info *top_mtd;
+ int ret;
+
+ list_for_each_entry(tr, &blktrans_majors, list) {
+ list_for_each_entry_safe(dev, next, &tr->devs, list) {
+ top_mtd = dev->mtd;
+ while (top_mtd->parent)
+ top_mtd = top_mtd->parent;
+
+ if (mtd->index != top_mtd->index)
+ continue;
+
+ device_add_disk(&dev->mtd->dev, dev->disk, NULL);
+ if (dev->disk_attributes) {
+ ret = sysfs_create_group(&disk_to_dev(dev->disk)->kobj,
+ dev->disk_attributes);
+ WARN_ON(ret);
+ }
+ }
+ }
+}
+
int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
{
unsigned long flags;
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -32,6 +32,7 @@
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
+#include <linux/mtd/blktrans.h>
#include "mtdcore.h"
@@ -858,6 +859,8 @@ int mtd_device_parse_register(struct mtd
register_reboot_notifier(&mtd->reboot_notifier);
}
+ register_mtd_blktrans_devs(mtd);
+
out:
if (ret && device_is_registered(&mtd->dev))
del_mtd_device(mtd);
--- a/include/linux/mtd/blktrans.h
+++ b/include/linux/mtd/blktrans.h
@@ -76,6 +76,7 @@ extern int deregister_mtd_blktrans(struc
extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
extern int mtd_blktrans_cease_background(struct mtd_blktrans_dev *dev);
+extern void register_mtd_blktrans_devs(struct mtd_info *mtd);
#endif /* __MTD_TRANS_H__ */

View File

@ -122,20 +122,25 @@
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -396,7 +396,7 @@ int ubiblock_create(struct ubi_volume_in
@@ -396,7 +396,11 @@ int ubiblock_create(struct ubi_volume_in
dev->leb_size = vi->usable_leb_size;
/* Initialize the gendisk of this ubiblock device */
- gd = alloc_disk(1);
+#ifdef CONFIG_FIT_PARTITION
+ gd = alloc_disk(0);
+#else
gd = alloc_disk(1);
+#endif
if (!gd) {
pr_err("UBI: block: alloc_disk failed\n");
ret = -ENODEV;
@@ -413,6 +413,7 @@ int ubiblock_create(struct ubi_volume_in
@@ -413,6 +417,9 @@ int ubiblock_create(struct ubi_volume_in
goto out_put_disk;
}
gd->private_data = dev;
+#ifdef CONFIG_FIT_PARTITION
+ gd->flags |= GENHD_FL_EXT_DEVT;
+#endif
sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
set_capacity(gd, disk_capacity);
dev->gd = gd;
@ -175,3 +180,40 @@
typedef struct _gpt_header {
__le64 signature;
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -334,7 +334,11 @@ static void mtdblock_remove_dev(struct m
static struct mtd_blktrans_ops mtdblock_tr = {
.name = "mtdblock",
.major = MTD_BLOCK_MAJOR,
+#ifdef CONFIG_FIT_PARTITION
+ .part_bits = 1,
+#else
.part_bits = 0,
+#endif
.blksize = 512,
.open = mtdblock_open,
.flush = mtdblock_flush,
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -407,18 +407,8 @@ int add_mtd_blktrans_dev(struct mtd_blkt
gd->first_minor = (new->devnum) << tr->part_bits;
gd->fops = &mtd_block_ops;
- if (tr->part_bits)
- if (new->devnum < 26)
- snprintf(gd->disk_name, sizeof(gd->disk_name),
- "%s%c", tr->name, 'a' + new->devnum);
- else
- snprintf(gd->disk_name, sizeof(gd->disk_name),
- "%s%c%c", tr->name,
- 'a' - 1 + new->devnum / 26,
- 'a' + new->devnum % 26);
- else
- snprintf(gd->disk_name, sizeof(gd->disk_name),
- "%s%d", tr->name, new->devnum);
+ snprintf(gd->disk_name, sizeof(gd->disk_name),
+ "%s%d", tr->name, new->devnum);
set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);

View File

@ -0,0 +1,68 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/dts-v1/;
#include "mt7622-ubnt-unifi-6-lr.dtsi"
/ {
model = "Ubiquiti UniFi 6 LR (U-Boot mod)";
compatible = "ubnt,unifi-6-lr-ubootmod", "mediatek,mt7622";
};
&nor_partitions {
partition@0 {
label = "bl2";
reg = <0x0 0x20000>;
};
partition@20000 {
label = "fip";
reg = <0x20000 0xa0000>;
};
partition@c0000 {
label = "u-boot-env";
reg = <0xc0000 0x10000>;
};
factory: partition@d0000 {
label = "factory";
reg = <0xd0000 0x40000>;
read-only;
};
eeprom: partition@110000 {
label = "eeprom";
reg = <0x110000 0x10000>;
read-only;
};
partition@120000 {
label = "recovery";
reg = <0x120000 0xee0000>;
};
partition@1000000 {
compatible = "denx,fit";
label = "firmware";
reg = <0x1000000 0x3000000>;
};
};
&wmac {
mediatek,mtd-eeprom = <&factory 0x0>;
mtd-mac-address = <&eeprom 0x0>;
status = "okay";
};
&slot0 {
wifi@0,0 {
reg = <0x0 0 0 0 0>;
mediatek,mtd-eeprom = <&factory 0x20000>;
mtd-mac-address = <&eeprom 0x6>;
ieee80211-freq-limit = <5000000 6000000>;
};
};
&gmac0 {
mtd-mac-address = <&eeprom 0x0>;
};

View File

@ -1,78 +1,72 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/dts-v1/;
#include <dt-bindings/input/input.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/leds/common.h>
#include "mt7622.dtsi"
#include "mt6380.dtsi"
#include "mt7622-ubnt-unifi-6-lr.dtsi"
/ {
model = "Ubiquiti UniFi 6 LR";
compatible = "ubnt,unifi-6-lr", "mediatek,mt7622";
};
aliases {
led-boot = &led_blue;
led-failsafe = &led_blue;
led-running = &led_blue;
led-upgrade = &led_blue;
label-mac-device = &gmac0;
serial0 = &uart0;
&nor_partitions {
partition@0 {
label = "preloader";
reg = <0x0 0x40000>;
};
chosen {
stdout-path = "serial0:115200n8";
bootargs = "earlycon=uart8250,mmio32,0x11002000 swiotlb=512 console=ttyS0,115200n8";
partition@40000 {
label = "atf";
reg = <0x40000 0x20000>;
};
cpus {
cpu@0 {
proc-supply = <&mt6380_vcpu_reg>;
sram-supply = <&mt6380_vm_reg>;
};
cpu@1 {
proc-supply = <&mt6380_vcpu_reg>;
sram-supply = <&mt6380_vm_reg>;
};
partition@60000 {
label = "u-boot";
reg = <0x60000 0x60000>;
};
gpio-keys {
compatible = "gpio-keys";
reset {
label = "reset";
linux,code = <KEY_RESTART>;
gpios = <&pio 62 GPIO_ACTIVE_LOW>;
};
partition@c0000 {
label = "u-boot-env";
reg = <0xc0000 0x10000>;
};
memory {
reg = <0 0x40000000 0 0x3f000000>;
factory: partition@d0000 {
label = "factory";
reg = <0xd0000 0x40000>;
read-only;
};
reg_1p8v: regulator-1p8v {
compatible = "regulator-fixed";
regulator-name = "fixed-1.8V";
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
eeprom: partition@110000 {
label = "eeprom";
reg = <0x110000 0x10000>;
read-only;
};
reg_3p3v: regulator-3p3v {
compatible = "regulator-fixed";
regulator-name = "fixed-3.3V";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-boot-on;
regulator-always-on;
partition@120000 {
label = "bs";
reg = <0x120000 0x10000>;
};
partition@130000 {
label = "cfg";
reg = <0x130000 0x100000>;
read-only;
};
partition@230000 {
compatible = "denx,fit";
label = "firmware";
reg = <0x230000 0x1ee0000>;
};
partition@2110000 {
label = "kernel1";
reg = <0x2110000 0x1ee0000>;
};
};
&pcie0 {
pinctrl-names = "default";
pinctrl-0 = <&pcie0_pins>;
&wmac {
mediatek,mtd-eeprom = <&factory 0x0>;
mtd-mac-address = <&eeprom 0x0>;
status = "okay";
};
@ -85,243 +79,6 @@
};
};
&pio {
eth_pins: eth-pins {
mux {
function = "eth";
groups = "mdc_mdio", "rgmii_via_gmac2";
};
};
pcie0_pins: pcie0-pins {
mux {
function = "pcie";
groups = "pcie0_pad_perst",
"pcie0_1_waken",
"pcie0_1_clkreq";
};
};
pcie1_pins: pcie1-pins {
mux {
function = "pcie";
groups = "pcie1_pad_perst",
"pcie1_0_waken",
"pcie1_0_clkreq";
};
};
pmic_bus_pins: pmic-bus-pins {
mux {
function = "pmic";
groups = "pmic_bus";
};
};
spi_nor_pins: spi-nor-pins {
mux {
function = "flash";
groups = "spi_nor";
};
};
uart0_pins: uart0-pins {
mux {
function = "uart";
groups = "uart0_0_tx_rx" ;
};
};
uart3_pins: uart3-pins {
mux {
function = "uart";
groups = "uart3_1_tx_rx" ;
};
};
i2c0_pins: i2c0-pins {
mux {
function = "i2c";
groups = "i2c0";
};
};
watchdog_pins: watchdog-pins {
mux {
function = "watchdog";
groups = "watchdog";
};
};
};
&bch {
status = "okay";
};
&btif {
status = "disabled";
};
&eth {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&eth_pins>;
gmac0: mac@0 {
compatible = "mediatek,eth-mac";
reg = <0>;
phy-mode = "2500base-x";
mtd-mac-address = <&eeprom 0x0>;
fixed-link {
speed = <2500>;
full-duplex;
};
};
mdio: mdio-bus {
#address-cells = <1>;
#size-cells = <0>;
ethernet-phy@8 {
/* Marvell AQRate AQR112W - no driver */
compatible = "ethernet-phy-ieee802.3-c45";
reg = <0x8>;
};
};
};
&pwrap {
pinctrl-names = "default";
pinctrl-0 = <&pmic_bus_pins>;
status = "okay";
};
&nor_flash {
pinctrl-names = "default";
pinctrl-0 = <&spi_nor_pins>;
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <50000000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "preloader";
reg = <0x0 0x40000>;
read-only;
};
partition@40000 {
label = "atf";
reg = <0x40000 0x20000>;
read-only;
};
partition@60000 {
label = "u-boot";
reg = <0x60000 0x60000>;
read-only;
};
partition@c0000 {
label = "u-boot-env";
reg = <0xc0000 0x10000>;
};
factory: partition@d0000 {
label = "factory";
reg = <0xd0000 0x40000>;
read-only;
};
eeprom: partition@110000 {
label = "eeprom";
reg = <0x110000 0x10000>;
read-only;
};
partition@120000 {
label = "bs";
reg = <0x120000 0x10000>;
};
partition@130000 {
label = "cfg";
reg = <0x130000 0x100000>;
read-only;
};
partition@230000 {
compatible = "denx,fit";
label = "firmware";
reg = <0x230000 0x1ee0000>;
};
partition@2110000 {
label = "kernel1";
reg = <0x2110000 0x1ee0000>;
};
};
};
};
&uart0 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins>;
status = "okay";
};
&uart3 {
pinctrl-names = "default";
pinctrl-0 = <&uart3_pins>;
status = "okay";
/* MT7915 Bluetooth */
};
&i2c0 {
pinctrl-names = "default";
pinctrl-0 = <&i2c0_pins>;
status = "okay";
led-controller@30 {
compatible = "ubnt,ledbar";
reg = <0x30>;
enable-gpio = <&pio 59 0>;
red {
label = "red";
};
green {
label = "green";
};
led_blue: blue {
label = "blue";
};
};
};
&watchdog {
pinctrl-names = "default";
pinctrl-0 = <&watchdog_pins>;
status = "okay";
};
&wmac {
mediatek,mtd-eeprom = <&factory 0x0>;
&gmac0 {
mtd-mac-address = <&eeprom 0x0>;
status = "okay";
};

View File

@ -0,0 +1,253 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/dts-v1/;
#include <dt-bindings/input/input.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/leds/common.h>
#include "mt7622.dtsi"
#include "mt6380.dtsi"
/ {
aliases {
led-boot = &led_blue;
led-failsafe = &led_blue;
led-running = &led_blue;
led-upgrade = &led_blue;
label-mac-device = &gmac0;
serial0 = &uart0;
};
chosen {
stdout-path = "serial0:115200n8";
bootargs = "earlycon=uart8250,mmio32,0x11002000 swiotlb=512 console=ttyS0,115200n8";
};
cpus {
cpu@0 {
proc-supply = <&mt6380_vcpu_reg>;
sram-supply = <&mt6380_vm_reg>;
};
cpu@1 {
proc-supply = <&mt6380_vcpu_reg>;
sram-supply = <&mt6380_vm_reg>;
};
};
gpio-keys {
compatible = "gpio-keys";
reset {
label = "reset";
linux,code = <KEY_RESTART>;
gpios = <&pio 62 GPIO_ACTIVE_LOW>;
};
};
memory {
reg = <0 0x40000000 0 0x3f000000>;
};
reg_1p8v: regulator-1p8v {
compatible = "regulator-fixed";
regulator-name = "fixed-1.8V";
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
};
reg_3p3v: regulator-3p3v {
compatible = "regulator-fixed";
regulator-name = "fixed-3.3V";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
regulator-boot-on;
regulator-always-on;
};
};
&pcie0 {
pinctrl-names = "default";
pinctrl-0 = <&pcie0_pins>;
status = "okay";
};
&pio {
eth_pins: eth-pins {
mux {
function = "eth";
groups = "mdc_mdio", "rgmii_via_gmac2";
};
};
pcie0_pins: pcie0-pins {
mux {
function = "pcie";
groups = "pcie0_pad_perst",
"pcie0_1_waken",
"pcie0_1_clkreq";
};
};
pcie1_pins: pcie1-pins {
mux {
function = "pcie";
groups = "pcie1_pad_perst",
"pcie1_0_waken",
"pcie1_0_clkreq";
};
};
pmic_bus_pins: pmic-bus-pins {
mux {
function = "pmic";
groups = "pmic_bus";
};
};
spi_nor_pins: spi-nor-pins {
mux {
function = "flash";
groups = "spi_nor";
};
};
uart0_pins: uart0-pins {
mux {
function = "uart";
groups = "uart0_0_tx_rx" ;
};
};
uart3_pins: uart3-pins {
mux {
function = "uart";
groups = "uart3_1_tx_rx" ;
};
};
i2c0_pins: i2c0-pins {
mux {
function = "i2c";
groups = "i2c0";
};
};
watchdog_pins: watchdog-pins {
mux {
function = "watchdog";
groups = "watchdog";
};
};
};
&bch {
status = "okay";
};
&btif {
status = "disabled";
};
&eth {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&eth_pins>;
gmac0: mac@0 {
compatible = "mediatek,eth-mac";
reg = <0>;
phy-mode = "2500base-x";
fixed-link {
speed = <2500>;
full-duplex;
};
};
mdio: mdio-bus {
#address-cells = <1>;
#size-cells = <0>;
ethernet-phy@8 {
/* Marvell AQRate AQR112W - no driver */
compatible = "ethernet-phy-ieee802.3-c45";
reg = <0x8>;
};
};
};
&pwrap {
pinctrl-names = "default";
pinctrl-0 = <&pmic_bus_pins>;
status = "okay";
};
&nor_flash {
pinctrl-names = "default";
pinctrl-0 = <&spi_nor_pins>;
status = "okay";
flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <50000000>;
nor_partitions: partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
};
};
};
&uart0 {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins>;
status = "okay";
};
&uart3 {
pinctrl-names = "default";
pinctrl-0 = <&uart3_pins>;
status = "okay";
/* MT7915 Bluetooth */
};
&i2c0 {
pinctrl-names = "default";
pinctrl-0 = <&i2c0_pins>;
status = "okay";
led-controller@30 {
compatible = "ubnt,ledbar";
reg = <0x30>;
enable-gpio = <&pio 59 0>;
red {
label = "red";
};
green {
label = "green";
};
led_blue: blue {
label = "blue";
};
};
};
&watchdog {
pinctrl-names = "default";
pinctrl-0 = <&watchdog_pins>;
status = "okay";
};

View File

@ -204,3 +204,21 @@ define Device/ubnt_unifi-6-lr
DEVICE_PACKAGES := kmod-mt7915e
endef
TARGET_DEVICES += ubnt_unifi-6-lr
define Device/ubnt_unifi-6-lr-ubootmod
DEVICE_VENDOR := Ubiquiti
DEVICE_MODEL := UniFi 6 LR
DEVICE_VARIANT := U-Boot mod
DEVICE_DTS := mt7622-ubnt-unifi-6-lr-ubootmod
DEVICE_DTS_DIR := ../dts
DEVICE_PACKAGES := kmod-mt7915e
KERNEL := kernel-bin | lzma
KERNEL_INITRAMFS_SUFFIX := -recovery.itb
KERNEL_INITRAMFS := kernel-bin | lzma | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | pad-to 64k
IMAGES := sysupgrade.itb
IMAGE/sysupgrade.itb := append-kernel | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb external-static-with-rootfs | pad-rootfs | append-metadata
ARTIFACTS := preloader.bin bl31-uboot.fip
ARTIFACT/preloader.bin := bl2 nor-2ddr
ARTIFACT/bl31-uboot.fip := bl31-uboot ubnt_unifi-6-lr
endef
TARGET_DEVICES += ubnt_unifi-6-lr-ubootmod

View File

@ -18,7 +18,8 @@ mediatek_setup_interfaces()
ucidef_add_switch "switch0" \
"0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
;;
ubnt,unifi-6-lr)
ubnt,unifi-6-lr|\
ubnt,unifi-6-lr-ubootmod)
ucidef_set_interfaces_lan "eth0"
;;
*)

View File

@ -1207,6 +1207,7 @@ endef
TARGET_DEVICES += zyxel_keenetic
define Device/zyxel_keenetic-lite-b
$(Device/uimage-lzma-loader)
SOC := rt5350
IMAGE_SIZE := 7872k
DEVICE_VENDOR := ZyXEL

View File

@ -61,7 +61,6 @@
partition@f0000 {
label = "u-boot-env2";
reg = <0x00f0000 0x0010000>;
read-only;
};
partition@100000 {

View File

@ -79,7 +79,6 @@
partition@50000 {
label = "u-boot-env2";
reg = <0x50000 0x10000>;
read-only;
};
partition@60000 {
label = "jffs";

View File

@ -79,7 +79,6 @@
partition@90000 {
label = "u-boot-env2";
reg = <0x90000 0x10000>;
read-only;
};
partition@a0000 {

View File

@ -77,7 +77,6 @@
partition@c0000 {
label = "u-boot-env2";
reg = <0x000c0000 0x40000>;
read-only;
};
partition@280000 {
label = "firmware";

View File

@ -61,7 +61,6 @@
partition@c0000 {
label = "u-boot-env2";
reg = <0x000c0000 0x40000>;
read-only;
};
partition@280000 {
label = "firmware";

View File

@ -24,81 +24,80 @@ endef
define Host/Compile
mkdir -p $(HOST_BUILD_DIR)/bin
$(call cc,add_header)
$(call cc,addpattern)
$(call cc,asustrx)
$(call cc,add_header,-Wall)
$(call cc,addpattern,-Wall)
$(call cc,asustrx,-Wall)
$(call cc,bcm4908asus,-Wall)
$(call cc,bcm4908img,-Wall)
$(call cc,bcm4908kernel,-Wall)
$(call cc,buffalo-enc buffalo-lib,-Wall)
$(call cc,buffalo-tag buffalo-lib,-Wall)
$(call cc,buffalo-tftp buffalo-lib,-Wall)
$(call cc,dgfirmware)
$(call cc,dgfirmware,-Wall)
$(call cc,dgn3500sum,-Wall)
$(call cc,dns313-header,-Wall)
$(call cc,edimax_fw_header,-Wall)
$(call cc,encode_crc)
$(call cc,encode_crc,-Wall)
$(call cc,fix-u-media-header cyg_crc32,-Wall)
$(call cc,hcsmakeimage bcmalgo)
$(call cc,imagetag imagetag_cmdline cyg_crc32)
$(call cc,hcsmakeimage bcmalgo,-Wall)
$(call cc,imagetag imagetag_cmdline cyg_crc32,-Wall)
$(call cc,jcgimage,-lz -Wall)
$(call cc,lxlfw)
$(call cc,lzma2eva,-lz)
$(call cc,makeamitbin)
$(call cc,mkbrncmdline)
$(call cc,mkbrnimg)
$(call cc,lxlfw,-Wall)
$(call cc,lzma2eva,-lz -Wall)
$(call cc,makeamitbin,-Wall)
$(call cc,mkbrncmdline,-Wall)
$(call cc,mkbrnimg,-Wall)
$(call cc,mkbuffaloimg,-Wall)
$(call cc,mkcameofw,-Wall)
$(call cc,mkcasfw)
$(call cc,mkchkimg)
$(call cc,mkcsysimg)
$(call cc,mkdapimg)
$(call cc,mkdapimg2)
$(call cc,mkcasfw,-Wall)
$(call cc,mkchkimg,-Wall)
$(call cc,mkcsysimg,-Wall)
$(call cc,mkdapimg,-Wall)
$(call cc,mkdapimg2,-Wall)
$(call cc,mkdhpimg buffalo-lib,-Wall)
$(call cc,mkdlinkfw mkdlinkfw-lib,-lz -Wall --std=c99)
$(call cc,mkdniimg)
$(call cc,mkedimaximg)
$(call cc,mkdniimg,-Wall)
$(call cc,mkedimaximg,-Wall)
$(call cc,mkfwimage,-lz -Wall -Werror -Wextra -D_FILE_OFFSET_BITS=64)
$(call cc,mkfwimage2,-lz)
$(call cc,mkheader_gemtek,-lz)
$(call cc,mkhilinkfw,-lcrypto)
$(call cc,mkfwimage2,-lz -Wall)
$(call cc,mkheader_gemtek,-lz -Wall)
$(call cc,mkhilinkfw,-lcrypto -Wall)
$(call cc,mkmerakifw sha1,-Wall)
$(call cc,mkmerakifw-old,-Wall)
$(call cc,mkmylofw)
$(call cc,mkplanexfw sha1)
$(call cc,mkmylofw,-Wall)
$(call cc,mkplanexfw sha1,-Wall)
$(call cc,mkporayfw,-Wall)
$(call cc,mkrasimage,--std=gnu99)
$(call cc,mkrtn56uimg,-lz)
$(call cc,mkrasimage,--std=gnu99 -Wall)
$(call cc,mkrtn56uimg,-lz -Wall)
$(call cc,mksenaofw md5,-Wall --std=gnu99)
$(call cc,mksercommfw,-Wall)
$(call cc,mktitanimg)
$(call cc,mktitanimg,-Wall)
$(call cc,mktplinkfw mktplinkfw-lib md5,-Wall -fgnu89-inline)
$(call cc,mktplinkfw2 mktplinkfw-lib md5,-fgnu89-inline)
$(call cc,mktplinkfw2 mktplinkfw-lib md5,-Wall -fgnu89-inline)
$(call cc,mkwrggimg md5,-Wall)
$(call cc,mkwrgimg md5,-Wall)
$(call cc,mkzcfw cyg_crc32)
$(call cc,mkzynfw)
$(call cc,motorola-bin)
$(call cc,nand_ecc)
$(call cc,mkzcfw cyg_crc32,-Wall)
$(call cc,mkzynfw,-Wall)
$(call cc,motorola-bin,-Wall)
$(call cc,nand_ecc,-Wall)
$(call cc,nec-enc,-Wall --std=gnu99)
$(call cc,osbridge-crc)
$(call cc,osbridge-crc,-Wall)
$(call cc,oseama md5,-Wall)
$(call cc,otrx)
$(call cc,otrx,-Wall)
$(call cc,pc1crypt)
$(call cc,ptgen cyg_crc32)
$(call cc,seama md5)
$(call cc,ptgen cyg_crc32,-Wall)
$(call cc,seama md5,-Wall)
$(call cc,sign_dlink_ru md5,-Wall)
$(call cc,spw303v)
$(call cc,spw303v,-Wall)
$(call cc,srec2bin)
$(call cc,tplink-safeloader md5,-Wall --std=gnu99)
$(call cc,trx)
$(call cc,trx2edips)
$(call cc,trx2usr)
$(call cc,trx,-Wall)
$(call cc,trx2edips,-Wall)
$(call cc,trx2usr,-Wall)
$(call cc,uimage_padhdr,-Wall -lz)
$(call cc,wrt400n cyg_crc32)
$(call cc,xorimage)
$(call cc,wrt400n cyg_crc32,-Wall)
$(call cc,xorimage,-Wall)
$(call cc,zyimage,-Wall)
$(call cc,zyxbcm)
$(call cc,zyxbcm,-Wall)
endef
define Host/Install

View File

@ -65,7 +65,7 @@ static uint32_t crc32buf(unsigned char *buf, size_t len)
}
struct header {
unsigned char model[16];
char model[16];
uint32_t crc;
};

View File

@ -132,7 +132,7 @@ static void parse_options(int argc, char **argv) {
productid = optarg;
break;
case 'v':
if (sscanf(optarg, "%hu.%hu.%hu.%hu", &version[0], &version[1], &version[2], &version[3]) != 4)
if (sscanf(optarg, "%hhu.%hhu.%hhu.%hhu", &version[0], &version[1], &version[2], &version[3]) != 4)
fprintf(stderr, "Version %s doesn't match suppored 4-digits format\n", optarg);
break;
}
@ -150,7 +150,8 @@ static void usage() {
int main(int argc, char **argv) {
struct trx_header hdr;
struct asustrx_tail tail = { };
FILE *in, *out;
FILE *out = NULL;
FILE *in = NULL;
uint8_t buf[1024];
size_t bytes;
size_t length = 0;

View File

@ -98,7 +98,6 @@ uint16_t get_hcs ( ldr_header_t* hd )
uint8_t hcs_minor;
uint8_t hcs_major;
uint16_t n = 0xffff;
uint16_t m = 0;
int state = 0;
int i,j;
for ( i = 0; i < 0x54; i++ )
@ -226,7 +225,7 @@ int dump_header ( ldr_header_t* hd )
printf ( "HNW:\t\t0x%04X\n",reverse_endian16 ( hd->her_znaet_chto ) ); //Hell knows what
printf ( "CRC:\t\t0x%08X\n",reverse_endian32 ( hd->crc ) );
printf ( "=== Binary Header Dump===\n" );
int i,j;
int i;
uint8_t* head = ( uint8_t* ) hd;
for ( i=0;i<=sizeof ( ldr_header_t );i++ )
{

View File

@ -74,34 +74,34 @@ typedef uint16_t cyg_uint16;
// Compute a CRC, using the POSIX 1003 definition
__externC cyg_uint32
cyg_posix_crc32(unsigned char *s, int len);
cyg_posix_crc32(void *s, int len);
// Gary S. Brown's 32 bit CRC
__externC cyg_uint32
cyg_crc32(unsigned char *s, int len);
cyg_crc32(void *s, int len);
// Gary S. Brown's 32 bit CRC, but accumulate the result from a
// previous CRC calculation
__externC cyg_uint32
cyg_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);
cyg_crc32_accumulate(cyg_uint32 crc, void *s, int len);
// Ethernet FCS Algorithm
__externC cyg_uint32
cyg_ether_crc32(unsigned char *s, int len);
cyg_ether_crc32(void *s, int len);
// Ethernet FCS algorithm, but accumulate the result from a previous
// CRC calculation.
__externC cyg_uint32
cyg_ether_crc32_accumulate(cyg_uint32 crc, unsigned char *s, int len);
cyg_ether_crc32_accumulate(cyg_uint32 crc, void *s, int len);
// 16 bit CRC with polynomial x^16+x^12+x^5+1
__externC cyg_uint16
cyg_crc16(unsigned char *s, int len);
cyg_crc16(void *s, int len);
#endif // _SERVICES_CRC_CRC_H_

View File

@ -96,8 +96,9 @@ static const cyg_uint16 crc16_tab[] = {
};
cyg_uint16
cyg_crc16(unsigned char *buf, int len)
cyg_crc16(void *ptr, int len)
{
unsigned char *buf = ptr;
int i;
cyg_uint16 cksum;

View File

@ -127,8 +127,9 @@ static const cyg_uint32 crc32_tab[] = {
/* This is the standard Gary S. Brown's 32 bit CRC algorithm, but
accumulate the CRC into the result of a previous CRC. */
cyg_uint32
cyg_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)
cyg_crc32_accumulate(cyg_uint32 crc32val, void *ptr, int len)
{
unsigned char *s = ptr;
int i;
for (i = 0; i < len; i++) {
@ -139,7 +140,7 @@ cyg_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)
/* This is the standard Gary S. Brown's 32 bit CRC algorithm */
cyg_uint32
cyg_crc32(unsigned char *s, int len)
cyg_crc32(void *s, int len)
{
return (cyg_crc32_accumulate(0,s,len));
}
@ -148,8 +149,9 @@ cyg_crc32(unsigned char *s, int len)
result from a previous CRC calculation. This uses the Ethernet FCS
algorithm.*/
cyg_uint32
cyg_ether_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)
cyg_ether_crc32_accumulate(cyg_uint32 crc32val, void *ptr, int len)
{
unsigned char *s = ptr;
int i;
if (s == 0) return 0L;
@ -164,7 +166,7 @@ cyg_ether_crc32_accumulate(cyg_uint32 crc32val, unsigned char *s, int len)
/* Return a 32-bit CRC of the contents of the buffer, using the
Ethernet FCS algorithm. */
cyg_uint32
cyg_ether_crc32(unsigned char *s, int len)
cyg_ether_crc32(void *s, int len)
{
return cyg_ether_crc32_accumulate(0,s,len);
}

View File

@ -104,7 +104,7 @@ int main(int argc, char** argv)
char *endptr, *buffer, *p;
int count; // size of file in bytes
unsigned short sum = 0, sum1 = 0;
char sumbuf[9];
char sumbuf[8 + 8 + 1];
if(argc < 3) {
printf("ERROR: Argument missing!\n\nUsage %s filename starting offset in hex [PID code]\n\n", argv[0]);

View File

@ -102,9 +102,11 @@ static const uint32_t crc32_table[256] = {
};
static uint32_t crc32(uint32_t crc,
const unsigned char *buf,
const void *data,
unsigned int len)
{
const uint8_t *buf = data;
crc = crc ^ 0xffffffffUL;
do {
crc = crc32_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
@ -112,7 +114,7 @@ static uint32_t crc32(uint32_t crc,
return crc ^ 0xffffffffUL;
}
static void be_wr(unsigned char *buf, uint32_t val)
static void be_wr(char *buf, uint32_t val)
{
buf[0] = (val >> 24) & 0xFFU;
buf[1] = (val >> 16) & 0xFFU;
@ -126,16 +128,13 @@ int main(int argc, char **argv)
int fdout;
struct stat sb;
uint32_t filesize;
uint32_t padding;
int ret = 0;
const char *pathin;
const char *pathout;
unsigned char *buffer;
unsigned char *infop;
char *buffer;
uint32_t sum;
size_t bufsize;
size_t bytes;
int i;
if (argc < 3) {
printf("Too few arguments.\n");
@ -150,12 +149,11 @@ int main(int argc, char **argv)
return ret;
filesize = sb.st_size;
padding = filesize % 4;
printf("INFILE: %s, size: %08x bytes\n", pathin, filesize);
/* File + extended header size */
bufsize = filesize + HEADER_SIZE;
printf("Allocate %08x bytes\n", bufsize);
printf("Allocate %08zx bytes\n", bufsize);
buffer = malloc(bufsize);
if (!buffer) {
printf("OOM: could not allocate buffer\n");
@ -180,9 +178,6 @@ int main(int argc, char **argv)
}
close(fdin);
/* PREP HEADER AND FOOTER */
infop = buffer;
be_wr(buffer + OFFSET_MAGIC, IH_MAGIC);
/* FIXME: use actual time */
@ -223,7 +218,7 @@ int main(int argc, char **argv)
be_wr(buffer + OFFSET_HCRC, sum);
printf("header checksum: 0x%08x\n", sum);
printf("OUTFILE: %s, size: %08x bytes\n", pathout, bufsize);
printf("OUTFILE: %s, size: %08zx bytes\n", pathout, bufsize);
fdout = open(pathout, O_RDWR|O_CREAT|O_TRUNC,S_IRWXU|S_IRGRP);
if (!fdout) {
printf("ERROR: could not open output file\n");

View File

@ -31,15 +31,15 @@
#define PART_NAME_LENGTH 16
typedef struct header {
uint8_t magic[MAGIC_LENGTH];
uint8_t version[256];
char magic[MAGIC_LENGTH];
char version[256];
u_int32_t crc;
u_int32_t pad;
} __attribute__ ((packed)) header_t;
typedef struct part {
uint8_t magic[MAGIC_LENGTH];
uint8_t name[PART_NAME_LENGTH];
char magic[MAGIC_LENGTH];
char name[PART_NAME_LENGTH];
uint8_t pad[12];
u_int32_t memaddr;
u_int32_t index;

View File

@ -82,8 +82,8 @@ int tagfile(const char *kernel, const char *rootfs, const char *bin, \
struct bcm_tag tag;
struct kernelhdr khdr;
FILE *kernelfile = NULL, *rootfsfile = NULL, *binfile = NULL, *cfefile = NULL;
size_t cfeoff, cfelen, kerneloff, kernellen, rootfsoff, rootfslen, \
read, imagelen, rootfsoffpadlen = 0, kernelfslen, kerneloffpadlen = 0, oldrootfslen, \
size_t cfelen, kerneloff, kernellen, rootfsoff, rootfslen, \
read, imagelen, rootfsoffpadlen = 0, oldrootfslen, \
rootfsend;
uint8_t readbuf[1024];
uint32_t imagecrc = IMAGETAG_CRC_START;
@ -91,7 +91,6 @@ int tagfile(const char *kernel, const char *rootfs, const char *bin, \
uint32_t rootfscrc = IMAGETAG_CRC_START;
uint32_t kernelfscrc = IMAGETAG_CRC_START;
uint32_t fwaddr = 0;
uint8_t crc_val;
const uint32_t deadcode = htonl(DEADCODE);
int i;
int is_pirelli = 0;
@ -126,7 +125,6 @@ int tagfile(const char *kernel, const char *rootfs, const char *bin, \
fwaddr = flash_start + image_offset;
if (cfefile) {
cfeoff = flash_start;
cfelen = getlen(cfefile);
/* Seek to the start of the file after tag */
fseek(binfile, sizeof(tag), SEEK_SET);
@ -138,7 +136,6 @@ int tagfile(const char *kernel, const char *rootfs, const char *bin, \
}
} else {
cfeoff = 0;
cfelen = 0;
}
@ -239,7 +236,6 @@ int tagfile(const char *kernel, const char *rootfs, const char *bin, \
oldrootfslen = getlen(rootfsfile);
rootfslen = oldrootfslen;
rootfslen = ( (rootfslen % block_size) > 0 ? (((rootfslen / block_size) + 1) * block_size) : rootfslen );
kerneloffpadlen = rootfslen - oldrootfslen;
oldrootfslen = rootfslen;
kerneloff = rootfsoff + rootfslen;
@ -391,7 +387,6 @@ int tagfile(const char *kernel, const char *rootfs, const char *bin, \
int main(int argc, char **argv)
{
int c, i;
char *kernel, *rootfs, *bin;
uint32_t flash_start, image_offset, block_size, load_address, entry;
flash_start = image_offset = block_size = load_address = entry = 0;

View File

@ -52,12 +52,13 @@ static void init_crc32()
}
}
static uint32_t crc32buf(unsigned char *buf, size_t len)
static uint32_t crc32buf(const void *buf, size_t len)
{
uint32_t crc = 0xFFFFFFFF;
const uint8_t *in = buf;
for (; len; len--, buf++)
crc = crc32[(uint8_t)crc ^ *buf] ^ (crc >> BPB);
for (; len; len--, in++)
crc = crc32[(uint8_t)crc ^ *in] ^ (crc >> BPB);
return ~crc;
}

View File

@ -463,8 +463,9 @@ csum8_get(struct csum_state *css)
void
csum16_update(uint8_t *p, uint32_t len, struct csum_state *css)
csum16_update(void *data, uint32_t len, struct csum_state *css)
{
uint8_t *p = data;
uint16_t t;
if (css->odd) {
@ -524,8 +525,10 @@ csum_init(struct csum_state *css, int size)
}
void
csum_update(uint8_t *p, uint32_t len, struct csum_state *css)
csum_update(void *data, uint32_t len, struct csum_state *css)
{
uint8_t *p = data;
switch (css->size) {
case CSUM_TYPE_8:
csum8_update(p,len,css);
@ -554,6 +557,10 @@ csum_get(struct csum_state *css)
break;
case CSUM_TYPE_32:
ret = csum32_get(css);
break;
default:
ERR("invalid checksum size\n");
return 0;
}
return ret;
@ -564,19 +571,21 @@ csum_get(struct csum_state *css)
* routines to write data to the output file
*/
int
write_out_data(FILE *outfile, uint8_t *data, size_t len,
write_out_data(FILE *outfile, void *data, size_t len,
struct csum_state *css)
{
uint8_t *ptr = data;
errno = 0;
fwrite(data, len, 1, outfile);
fwrite(ptr, len, 1, outfile);
if (errno) {
ERRS("unable to write output file");
return ERR_FATAL;
}
if (css) {
csum_update(data, len, css);
csum_update(ptr, len, css);
}
return 0;
@ -755,6 +764,9 @@ write_out_header(FILE *outfile)
res = write_out_data(outfile, (uint8_t *)&tmp.nfs,
sizeof(tmp.nfs), NULL);
break;
default:
ERR("invalid header type\n");
return -EINVAL;
}
return res;
@ -763,8 +775,7 @@ write_out_header(FILE *outfile)
int
write_out_images(FILE *outfile)
{
struct image_desc *desc;
int i, res;
int res;
res = image_writeout(outfile, &kernel_image);
if (res)
@ -839,7 +850,6 @@ parse_opt_image(char ch, char *arg)
{
char buf[MAX_ARG_LEN];
char *argv[MAX_ARG_COUNT];
int argc;
char *p;
struct image_desc *desc = NULL;
int i;
@ -864,7 +874,7 @@ parse_opt_image(char ch, char *arg)
if (!desc)
return ERR_FATAL;
argc = parse_arg(arg, buf, argv);
parse_arg(arg, buf, argv);
i = 0;
p = argv[i++];
@ -886,9 +896,6 @@ parse_opt_image(char ch, char *arg)
int
process_images(void)
{
struct image_desc *desc;
uint32_t offs = 0;
int i;
int res;
kernel_image.out_size = board->max_kernel_size;

View File

@ -423,8 +423,9 @@ csum8_get(struct csum_state *css)
void
csum16_update(uint8_t *p, uint32_t len, struct csum_state *css)
csum16_update(void *data, uint32_t len, struct csum_state *css)
{
uint8_t *p = data;
uint16_t t;
if (css->odd) {
@ -468,8 +469,10 @@ csum_init(struct csum_state *css, int size)
void
csum_update(uint8_t *p, uint32_t len, struct csum_state *css)
csum_update(void *data, uint32_t len, struct csum_state *css)
{
uint8_t *p = data;
switch (css->size) {
case CSUM_SIZE_8:
csum8_update(p,len,css);
@ -493,6 +496,9 @@ csum_get(struct csum_state *css)
case CSUM_SIZE_16:
ret = csum16_get(css);
break;
default:
ERR("invalid checksum size\n");
return 0;
}
return ret;
@ -503,19 +509,21 @@ csum_get(struct csum_state *css)
* routines to write data to the output file
*/
int
write_out_data(FILE *outfile, uint8_t *data, size_t len,
write_out_data(FILE *outfile, void *data, size_t len,
struct csum_state *css)
{
uint8_t *ptr = data;
errno = 0;
fwrite(data, len, 1, outfile);
fwrite(ptr, len, 1, outfile);
if (errno) {
ERRS("unable to write output file");
return ERR_FATAL;
}
if (css) {
csum_update(data, len, css);
csum_update(ptr, len, css);
}
return 0;
@ -792,7 +800,6 @@ parse_opt_block(char ch, char *arg)
{
char buf[MAX_ARG_LEN];
char *argv[MAX_ARG_COUNT];
int argc;
char *p;
struct csys_block *block;
int i;
@ -854,7 +861,7 @@ parse_opt_block(char ch, char *arg)
return ERR_FATAL;
}
argc = parse_arg(arg, buf, argv);
parse_arg(arg, buf, argv);
i = 0;
p = argv[i++];

View File

@ -68,7 +68,8 @@ main(int ac, char *av[])
int fixmode = 0;
int have_regionversion = 0;
FILE *ifile, *ofile;
FILE *ifile = NULL;
FILE *ofile = NULL;
int c;
uint32_t cksum;
uint32_t bcnt;

View File

@ -92,7 +92,8 @@ main(int ac, char *av[])
char region[MAX_REG_LEN];
int kernel = 0;
FILE *ifile, *ofile;
FILE *ifile = NULL;
FILE *ofile = NULL;
int c;
uint32_t cksum;

View File

@ -50,7 +50,6 @@ static char *board_id;
void usage(int status)
{
FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
struct board_info *board;
fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
fprintf(stream,
@ -188,7 +187,6 @@ int main(int argc, char *argv[])
res = EXIT_SUCCESS;
out_flush:
fflush(outfile);
err_close_out:

View File

@ -65,7 +65,6 @@ typedef struct image_info {
} image_info_t;
static image_info_t im;
static int debug = 0;
static int zero_part_baseaddr = 0;
static void write_header(void* mem, const char* version)

View File

@ -98,7 +98,7 @@ struct cpx_board {
#define CPX_BOARD_AR23XX(_did, _flash, _mod, _name, _desc) \
CPX_BOARD(_did, _flash, _mod, _name, _desc, 0x10000, 0x10000)
#define ALIGN(x,y) ((x)+((y)-1)) & ~((y)-1)
#define ALIGN(x,y) (((x)+((y)-1)) & ~((y)-1))
char *progname;
char *ofname = NULL;
@ -478,18 +478,20 @@ process_partitions(void)
* routines to write data to the output file
*/
int
write_out_data(FILE *outfile, uint8_t *data, size_t len, uint32_t *crc)
write_out_data(FILE *outfile, void *data, size_t len, uint32_t *crc)
{
uint8_t *ptr = data;
errno = 0;
fwrite(data, len, 1, outfile);
fwrite(ptr, len, 1, outfile);
if (errno) {
errmsg(1,"unable to write output file");
return -1;
}
if (crc) {
update_crc(data, len, crc);
update_crc(ptr, len, crc);
}
return 0;
@ -848,14 +850,13 @@ parse_opt_id(char ch, char *arg)
{
char buf[MAX_ARG_LEN];
char *argv[MAX_ARG_COUNT];
int argc;
char *p;
if (required_arg(ch, arg)) {
goto err_out;
}
argc = parse_arg(arg, buf, argv);
parse_arg(arg, buf, argv);
/* processing vendor ID*/
p = argv[0];
@ -1011,7 +1012,6 @@ parse_opt_partition(char ch, char *arg)
{
char buf[MAX_ARG_LEN];
char *argv[MAX_ARG_COUNT];
int argc;
char *p;
struct mylo_partition *part;
struct fw_part *fp;
@ -1028,7 +1028,7 @@ parse_opt_partition(char ch, char *arg)
fp = &fw_parts[fw_num_partitions++];
part = &fp->mylo;
argc = parse_arg(arg, buf, argv);
parse_arg(arg, buf, argv);
/* processing partition address */
p = argv[0];

View File

@ -105,7 +105,6 @@ static struct board_info *find_board(char *id)
void usage(int status)
{
FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
struct board_info *board;
fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
fprintf(stream,
@ -248,7 +247,6 @@ int main(int argc, char *argv[])
res = EXIT_SUCCESS;
out_flush:
fflush(outfile);
err_close_out:

View File

@ -67,7 +67,7 @@ typedef struct image_header {
uint8_t ih_type;
uint8_t ih_comp;
union {
uint8_t ih_name[IH_NMLEN];
char ih_name[IH_NMLEN];
asus_t asus;
} tail;
} image_header_t;
@ -102,7 +102,6 @@ static void
usage(const char *progname, int status)
{
FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
int i;
fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
fprintf(stream, "\n"
@ -116,12 +115,12 @@ usage(const char *progname, int status)
int
process_image(char *progname, char *filename, op_mode_t opmode)
{
int fd, len;
void *data, *ptr;
int fd;
void *ptr;
char namebuf[IH_NMLEN];
struct stat sbuf;
uint32_t checksum, offset_kernel, offset_sqfs, offset_end,
offset_sec_header, offset_eb, offset_image_end;
uint32_t offset_kernel, offset_sqfs, offset_end,
offset_sec_header, offset_eb, offset_image_end;
squashfs_sb_t *sqs;
image_header_t *hdr;
@ -252,7 +251,8 @@ int
main(int argc, char **argv)
{
int opt;
char *filename, *progname;
char *filename = NULL;
char *progname;
op_mode_t opmode = NONE;
progname = argv[0];

View File

@ -40,7 +40,6 @@ void print_help(void)
void mknspimg_print_hdr(struct nsp_img_hdr *hdr)
{
struct nsp_img_hdr_chksum *chksum;
struct nsp_img_hdr_section_info *sect_info;
struct nsp_img_hdr_sections *section;
int i;
@ -118,14 +117,11 @@ int main(int argc, char* argv[], char* env[])
int cmdline_err;
char* cmdline_error_msg;
char* filen_kernel;
char* filen_files;
char* filen_out;
int i,count; /* loop variables */
int num_sects = 2; /* We require exactly two image with -i option
(see CMDLINE_CFG structure above) */
int desc_count=0;
int total = 0;
int header_size=0;
@ -158,8 +154,6 @@ int main(int argc, char* argv[], char* env[])
header_version=atoi(argv[cmdline_getarg(cmdline_getarg_list('h'),0)]);
}
/* Set up arguments */
filen_kernel = argv[cmdline_getarg(cmdline_getarg_list('i'),0)];
filen_files = argv[cmdline_getarg(cmdline_getarg_list('i'),1)];
filen_out = argv[cmdline_getarg(cmdline_getarg_list('o'),0)];
/* Command line arguments have been parsed. Start doing our work. */
@ -290,7 +284,7 @@ int main(int argc, char* argv[], char* env[])
else
padding = align - ((section->raw_size+ section->offset) % align);
section->total_size=section->raw_size + padding;
section->total_size=section->raw_size + padding;
}
else{
#define EXTRA_BLOCK 0x10000

View File

@ -184,7 +184,6 @@ static struct flash_layout layouts[] = {
static void usage(int status)
{
FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
struct board_info *board;
fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
fprintf(stream,

View File

@ -114,7 +114,7 @@ static void get_digest(struct wrgg03_header *header, char *data, int size)
MD5_Update(&ctx, (char *)&header->devname, sizeof(header->devname));
MD5_Update(&ctx, data, size);
MD5_Final(header->digest, &ctx);
MD5_Final((unsigned char *)header->digest, &ctx);
}
int main(int argc, char *argv[])

View File

@ -100,7 +100,7 @@ static void get_digest(struct wrg_header *header, char *data, int size)
MD5_Update(&ctx, (char *)&header->devname, sizeof(header->devname));
MD5_Update(&ctx, data, size);
MD5_Final(header->digest, &ctx);
MD5_Final((unsigned char *)header->digest, &ctx);
}
int main(int argc, char *argv[])

View File

@ -127,7 +127,6 @@ static struct board_info *find_board(char *id)
static void usage(int status)
{
FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
struct board_info *board;
fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
fprintf(stream,
@ -276,8 +275,6 @@ static int build_fw(void)
char *buf;
char *p;
int ret = EXIT_FAILURE;
int writelen = 0;
uint32_t crc;
struct fw_header *hdr;
struct fw_tail *tail;
@ -361,11 +358,6 @@ static int build_fw(void)
int main(int argc, char *argv[])
{
int ret = EXIT_FAILURE;
int err;
FILE *outfile;
progname = basename(argv[0]);
while ( 1 ) {
int c;

View File

@ -444,8 +444,10 @@ csum_init(struct csum_state *css)
void
csum_update(uint8_t *p, uint32_t len, struct csum_state *css)
csum_update(void *data, uint32_t len, struct csum_state *css)
{
uint8_t *p = data;
if (len == 0)
return;
@ -499,19 +501,21 @@ csum_buf(uint8_t *p, uint32_t len)
* routines to write data to the output file
*/
int
write_out_data(FILE *outfile, uint8_t *data, size_t len,
write_out_data(FILE *outfile, void *data, size_t len,
struct csum_state *css)
{
uint8_t *ptr = data;
errno = 0;
fwrite(data, len, 1, outfile);
fwrite(ptr, len, 1, outfile);
if (errno) {
ERR("unable to write output file");
return -1;
}
if (css) {
csum_update(data, len, css);
csum_update(ptr, len, css);
}
return 0;
@ -541,7 +545,7 @@ write_out_padding(FILE *outfile, size_t len, uint8_t padc,
int
write_out_data_align(FILE *outfile, uint8_t *data, size_t len, size_t align,
write_out_data_align(FILE *outfile, void *data, size_t len, size_t align,
struct csum_state *css)
{
size_t padlen;
@ -611,7 +615,7 @@ write_out_mmap(FILE *outfile, struct fw_mmap *mmap, struct csum_state *css)
mh->count=0;
/* Build user data section */
data = buf+sizeof(*mh);
data = (char *)buf + sizeof(*mh);
data += sprintf(data, "Vendor 1 %d", board->vendor);
*data++ = '\0';
data += sprintf(data, "Model 1 %d", BE16_TO_HOST(board->model));
@ -922,7 +926,6 @@ parse_opt_block(char ch, char *arg)
{
char buf[MAX_ARG_LEN];
char *argv[MAX_ARG_COUNT];
int argc;
char *p;
struct fw_block *block;
int i;
@ -951,7 +954,7 @@ parse_opt_block(char ch, char *arg)
break;
}
argc = parse_arg(arg, buf, argv);
parse_arg(arg, buf, argv);
i = 0;
p = argv[i++];

View File

@ -58,7 +58,6 @@ static char *ofname;
void usage(int status)
{
FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
struct board_info *board;
fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
fprintf(stream,
@ -164,7 +163,6 @@ int main(int argc, char *argv[])
res = EXIT_SUCCESS;
out_flush:
fflush(outfile);
err_close_out:

View File

@ -215,7 +215,6 @@ static int decrypt;
void usage(int status)
{
FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;
struct board_info *board;
fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
fprintf(stream,
@ -340,7 +339,6 @@ int main(int argc, char *argv[])
res = EXIT_SUCCESS;
out_flush:
fflush(outfile);
err_close_out:

View File

@ -225,8 +225,9 @@ void sha1_process( sha1_context *ctx, uchar data[64] )
ctx->state[4] += E;
}
void sha1_update( sha1_context *ctx, uchar *input, uint length )
void sha1_update( sha1_context *ctx, void *data, uint length )
{
uchar *input = data;
ulong left, fill;
if( ! length ) return;

View File

@ -26,7 +26,7 @@ sha1_context;
* Core SHA-1 functions
*/
void sha1_starts( sha1_context *ctx );
void sha1_update( sha1_context *ctx, uchar *input, uint length );
void sha1_update( sha1_context *ctx, void *input, uint length );
void sha1_finish( sha1_context *ctx, uchar digest[20] );
/*

View File

@ -117,10 +117,12 @@ static char fake_data[] = {
};
uint32_t crc32(uint32_t crc, uint8_t *data, size_t len)
uint32_t crc32(uint32_t crc, const void *data, size_t len)
{
const uint8_t *in = data;
while (len--)
crc = (crc >> 8) ^ crc32tab[(crc ^ *data++) & 0xFF];
crc = (crc >> 8) ^ crc32tab[(crc ^ *in++) & 0xFF];
return crc;
}
@ -167,7 +169,6 @@ int main(int argc, char **argv)
char *ifn = NULL;
char *ofn = NULL;
int c;
int v0, v1, v2;
size_t n;
int first_block = 1;

View File

@ -433,9 +433,8 @@ int srecLine(char *pSrecLine)
int srec2bin(int argc,char *argv[],int verbose)
{
int i,rlen,sts;
int rlen,sts;
FILE *fp;
char ac;
char buff[256];
bit32u TAG_BIG = 0xDEADBE42;
bit32u TAG_LITTLE = 0xFEEDFA42;

View File

@ -140,6 +140,10 @@ int main(int argc, char *argv[])
rewind(fpIn);
/* read the whole file*/
res = fread(buf, 1, length, fpIn);
if (res != length) {
fprintf(stderr, "Unable to fread from input file\n");
return EXIT_FAILURE;
}
p = (struct trx_header *)buf;
if (LOAD32_LE(p->magic) != TRX_MAGIC) {

View File

@ -29,15 +29,17 @@ static char default_pattern[] = "12345678";
static int is_hex_pattern;
int xor_data(uint8_t *data, size_t len, const uint8_t *pattern, int p_len, int p_off)
int xor_data(void *data, size_t len, const void *pattern, int p_len, int p_off)
{
int offset = p_off;
const uint8_t *key = pattern;
uint8_t *d = data;
while (len--) {
*data ^= pattern[offset];
data++;
offset = (offset + 1) % p_len;
*d ^= key[p_off];
d++;
p_off = (p_off + 1) % p_len;
}
return offset;
return p_off;
}
@ -61,7 +63,6 @@ int main(int argc, char **argv)
char hex_pattern[128];
unsigned int hex_buf;
int c;
int v0, v1, v2;
size_t n;
int p_len, p_off = 0;