Flash OpenWrt into D-Link DWR-M921 (Realtek Chip)

Still not working after distclean. I replaced the original squashfs and linux. Here is my Makefile content after modifying it. Let me know if this is the correct thing

# 
# Copyright (C) 2006-2010 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk

BlockSize=128k
ifeq ($(CONFIG_MTD_NAND_RTK_BLOCK_SIZE),0x80000)
BlockSize=512k
endif
ifeq ($(CONFIG_MTD_NAND_RTK_BLOCK_SIZE),0x20000)
BlockSize=128k
endif

define mkcmdline
board=$(1) console=$(2),$(3) linuxpart=0x$(4) hwpart=0x$(5)
endef

SINGLE_PROFILES :=

define SingleProfile

  define Image/Build/Profile/$(1)/initramfs
	$(call Image/BuildLoader,loader-$(SUBTARGET)-$(1),bin,$(call mkcmdline,$(1),$(2),$(3)) $(4),$(5))
	cvimg-$(SUBTARGET) linux $(KDIR)/loader-$(SUBTARGET)-$(1).bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ramfs.bin $(5) $(6)
  endef
ifeq ($(CONFIG_MTD_NAND_RTK),y)
  define Image/Build/Profile/$(1)/squashfs-ro
	$(call Image/BuildLoader,loader-$(SUBTARGET)-$(1),bin,$(call mkcmdline,$(1),$(2),$(3),$(6),$(7)),$(5))

	cvimg-$(SUBTARGET) linux-ro $(KDIR)/loader-$(SUBTARGET)-$(1).bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin $(5) $(6)
	dd if=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin of=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_4k.bin bs=$(BlockSize) conv=sync
	cat $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_4k.bin $(KDIR)/root.squashfs-4k > $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_4k_cat.bin
	cvimg-$(SUBTARGET) fix_chksum  $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_4k_cat.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw.bin
	rm -rf $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_4k.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_4k_cat.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin
  endef
else
  define Image/Build/Profile/$(1)/squashfs-ro
	$(call Image/BuildLoader,loader-$(SUBTARGET)-$(1),bin,$(call mkcmdline,$(1),$(2),$(3),$(6),$(7)),$(5))

	cvimg-$(SUBTARGET) linux-ro $(KDIR)/loader-$(SUBTARGET)-$(1).bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin $(5) $(6)
	dd if=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin of=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_4k.bin bs=4k conv=sync
	dd if=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin of=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_64k.bin bs=64k conv=sync
	cat $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_4k.bin $(KDIR)/root.squashfs-4k > $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_4k_cat.bin
	cat $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_64k.bin $(KDIR)/root.squashfs-64k > $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_64k_cat.bin
	cvimg-$(SUBTARGET) fix_chksum  $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_4k_cat.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-4k-fw.bin
	cvimg-$(SUBTARGET) fix_chksum  $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_64k_cat.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-64k-fw.bin
	cp $(BIN_DIR)/$(IMG_PREFIX)-$(1)-4k-fw.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw.bin
	rm -rf $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_4k.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_4k_cat.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin
	rm -rf $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_64k.bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-fw_64k_cat.bin
  endef

endif
  SINGLE_PROFILES += $(1)

endef

define MultiProfile

  define Image/Build/Profile/$(1)/initramfs
	$(foreach p,$(2),
		$$(call Image/Build/Profile/$p/initramfs)
	)
  endef

  define Image/Build/Profile/$(1)/squashfs
	$(foreach p,$(2),
		$$(call Image/Build/Profile/$p/squashfs)
	)
  endef

endef

define Image/Prepare
	lzma e $(KDIR)/vmlinux -lc1 -lp2 -pb2 $(KDIR)/vmlinux.bin.lzma
endef

LOADER_MAKE := $(NO_TRACE_MAKE) -C lzma-loader KDIR=$(KDIR) LINUX_DIR=$(LINUX_DIR)

define Build/Clean
	$(LOADER_MAKE) clean
endef

define Image/BuildLoader
	-rm -rf $(KDIR)/lzma-loader
	$(LOADER_MAKE) LOADER=$(1).$(2) KERNEL_CMDLINE="$(3)" \
		LZMA_TEXT_START=$(4) LOADADDR=0x80000000 \
		LOADER_DATA="$(KDIR)/vmlinux.bin.lzma" BOARD="$(1)" \
		compile loader.$(2)
endef

#
# rtl819xd profiles
#
# 98c move default linux 60000
ifeq ($(CONFIG_TARGET_rtkmips_rtl8198c),y)
# linun partition offset = 0x6000 
# hw setting parttion offset = 0x20000
ifeq ($(CONFIG_MTD_NAND_RTK),y)
$(eval $(call SingleProfile,AP,ttyS0,38400,root=/dev/mtdblock3,0x80500000,800000,0))
else
$(eval $(call SingleProfile,AP,ttyS0,38400,root=/dev/mtdblock2,0x80500000,60000,20000))
endif
endif

ifeq ($(CONFIG_TARGET_rtkmips_rtl8954e),y)
# linun partition offset = 0x6000
# hw setting parttion offset = 0x20000
ifeq ($(CONFIG_MTD_NAND_RTK),y)
$(eval $(call SingleProfile,AP,ttyS0,38400,root=/dev/mtdblock3,0x80500000,800000,0))
else
$(eval $(call SingleProfile,AP,ttyS0,38400,root=/dev/mtdblock2,0x80500000,60000,20000))
endif
endif 

ifeq ($(CONFIG_TARGET_rtkmipsel_rtl8197f),y)
# linun partition offset = 0x6000
# hw setting parttion offset = 0x20000
ifeq ($(CONFIG_MTD_NAND_RTK),y)
$(eval $(call SingleProfile,AP,ttyS0,38400,root=/dev/mtdblock3,0x80500000,800000,0))
else
$(eval $(call SingleProfile,AP,ttyS0,38400,root=/dev/mtdblock2,0x80500000,60000,20000))
endif
endif 


#

# RAMFS
define Image/Build/Initramfs
	$(call Image/Build/Profile/$(PROFILE)/initramfs)
endef

# SQUASHFS
ifeq ($(CONFIG_MTD_NAND_RTK),y)
define Image/Build
	dd if=$(KDIR)/root.squashfs of=$(KDIR)/root.squashfs-4k bs=$(BlockSize) conv=sync
	$(call add_jffs2_mark,$(KDIR)/root.squashfs-4k)
	$(call Image/Build/Profile/$(PROFILE)/squashfs)
endef
else
define Image/Build	
	dd if=$(KDIR)/root.squashfs of=$(KDIR)/root.squashfs-4k bs=4k conv=sync
	dd if=$(KDIR)/root.squashfs of=$(KDIR)/root.squashfs-64k bs=64k conv=sync
	$(call add_jffs2_mark,$(KDIR)/root.squashfs-4k)
	$(call add_jffs2_mark,$(KDIR)/root.squashfs-64k)
	$(call Image/Build/Profile/$(PROFILE)/squashfs)
endef
endif

$(eval $(call BuildImage))

Does it output any images at all, what is the header? is there 'squashfs' or 'squashfs-ro' in the menuconfig?

I thought you'd just leave the

profile name as it was and just replace linux with linux-ro.

I'll try if the build works for me.

Alright. I will be waiting for your feedback

The build is not working for me, even without the change, probably missing dependencies or wrong version of some tools etc.

autoreconf: running: /home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/bin/automake --add-missing
Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at /home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/bin/automake line 4160.
autoreconf: /home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/bin/automake failed with exit status: 255
(cd /home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/build_dir/host/mklibs-0.1.35/; if [ -x configure ]; then cp -fpR /home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/scripts/config.{guess,sub} /home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/build_dir/host/mklibs-0.1.35// &&  /bin/bash ./configure CC="gcc" CFLAGS="-O2 -I/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/include -I/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/tools/mklibs/include" CPPFLAGS="-I/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/include" LDFLAGS="-L/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/lib " SHELL="/bin/bash" --target=x86_64-linux-gnu --host=x86_64-linux-gnu --build=x86_64-linux-gnu --program-prefix="" --program-suffix="" --prefix=/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host --exec-prefix=/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host --sysconfdir=/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/etc --localstatedir=/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/var --sbindir=/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/host/bin ; fi )
configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."
Makefile:35: recipe for target '/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/build_dir/host/mklibs-0.1.35/.configured' failed
make[3]: *** [/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/build_dir/host/mklibs-0.1.35/.configured] Error 1
make[3]: Leaving directory '/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/tools/mklibs'
tools/Makefile:159: recipe for target 'tools/mklibs/compile' failed
make[2]: *** [tools/mklibs/compile] Error 2
make[2]: Leaving directory '/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk'
tools/Makefile:158: recipe for target '/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/target-mipsel_24kec_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyyynyyyyyyyynyyyynnyyyynnyynnnyyyy' failed
make[1]: *** [/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/staging_dir/target-mipsel_24kec_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyyynyyyyyyyynyyyynnyyyynnyynnnyyyy] Error 2
make[1]: Leaving directory '/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk'
/home/sebastian/openwrt/rtktest/openwrt_rtk/rtk_openwrt_sdk/include/toplevel.mk:171: recipe for target 'world' failed
make: *** [world] Error 2

However the only change I made to the original files was replacing linux with linux-ro at one position (i.e. just adding 3 bytes to the file).

I guess this is a tough one. Thanks for your help. I will try and keep checking for other options.

Did you have any success with flashing?

Since you said you were able to build the image from source, just change that one line in the Makefile to

 define Image/Build/Profile/$(1)/squashfs
	$(call Image/BuildLoader,loader-$(SUBTARGET)-$(1),bin,$(call mkcmdline,$(1),$(2),$(3),$(6),$(7)),$(5))

	cvimg-$(SUBTARGET) linux-ro $(KDIR)/loader-$(SUBTARGET)-$(1).bin $(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin $(5) $(6)
	dd if=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux.bin of=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-linux_4k.bin bs=4k conv=sync
	...

or did you get any build errors from that?

I also have a DWR-953 which is based on Realtek, would be interesting to see whether the image is accepted by the stock firmware. :slightly_smiling_face:

Hello. Sorry for the late reply. I did not have any success in Flashing unfortunately.

Can anyone please provide me with the flash dump as I cannot unbrick the device??
Please

dump_DWR_M921_1.1.51_25Q64JVSIQ

1 Like

To flash it you have to enter the recovery mode. Press the reset button, then the power button and release the reset after 10 seconds. Connect the router to the PC via ethernet (to one of the yellow ports of the router), go to connection settings and set the static ip for your PC (the router IP will be 192.168.1.6, so you will have to chose another one, for example 192.168.1.10). Then open a browser and enter to 192.168.1.6. You will se a firmware upload page. That is it. I recommend to use a UART bridge and connect to the UART interface that is close to the SoC (the baudrate is 38400 for this router), then you will be able to see the logs of the router. That is useful for troubleshooting and making OpenWRT work on the device, because is very probably that it wont work with the image you have (it will boot, but will have some issues with wifi, lte module, etc). I have the same router and I will be trying to make it work and share the progress here. Sorry for the bad english.

1 Like

Hello
this model of modem supported using openwrt?
D-link DWR-M921
i saw DWR-921, but i think its different than my modem, right?

Thanks.

hi
plz help me i want dump dlink router 4G
model : DWR-M920 plz

Hi
i have problem with my dwr-m921

i buy Dlink (dwr-m921 A2 ) modem , and i want update it, the installed firmware version on modem was 1.1.51 and i download from dlink website accidentally version 1.1.36 and install it on the modem,
now the the modem refuse to update, i try 10 times uploading different versions but still 1.1.36
how to back the previous version or how can I update to higher version.

Hello, I want a dump file for the DWR-M921 4G device

any update ?