OpenWrt Forum Archive

Topic: How to include configuration files into firmware image?

The content of this topic has been archived on 25 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I created my own firmware image for my WRT54g, and I also have my own configuration files (like firewall.user, ssh public key, things in /etc/config/ and so on...).
Now I want to know: How can I include ALL these files into a firmware image?
I just want to flash the image and then everthing is done already, no need to transfer any files or setting up a telnet/ssh-password...

Thanks in advance!

In the build-systems topdir create a files/ directory and put the files there (e.g. files/etc/config/testconfig). Then rebuild the image.

or alternatively define your own package, with a ./files subdirectory, that does not compile anything but has the standard install commands that come in BIN, DATA  etc. variety so that the rights get set right. You can also indicate there what other packages need to be present or even include commands to remove, rename, link etc.
Put it in the package directory, give it a name like zzz_something so it comes last and overwrites earlier stuff. A bit more complicated and a bit more powerful.
I maintain that way firmware for a series of units that are all customized a bit differently but can start from the same basic OpenWrt

Here is an excerpt from a Makefile of an  imaginary package called zzz-MARS so you can edit it. The files it refers to are in .trunk/package/zzz-MARS/files

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=zzz-MARS
PKG_RELEASE:=1
PKG_VERSION:=1.0.0

include $(INCLUDE_DIR)/package.mk

define Package/zzz-MARS
  SECTION:=net
  CATEGORY:=Base system
  TITLE:=Customization of OpenWrt image
  DEPENDS:=@LINUX_2_6 +iproute2 +ntpclient +tc +hostapd-mini +hostapd-utils +iw \
    +crda
endef

define Package/zzz-MARS/description
<Some Descriptive Text>.
endef

define Build/Compile
    rm -rf $(PKG_INSTALL_DIR)
    mkdir -p $(PKG_INSTALL_DIR)
endef

define Package/zzz-MARS/install
    $(INSTALL_DIR) $(1)/sbin
    $(INSTALL_BIN) ./files/wifi $(1)/sbin/
    $(INSTALL_DIR) $(1)/etc
    $(INSTALL_DATA) ./files/profile $(1)/etc
    $(INSTALL_DATA) ./files/dnsmasq.conf $(1)/etc
    rm -f $(1)/etc/hotplug.d/iface/20-ntpclient
endef

$(eval $(call BuildPackage,zzz-MARS))

(Last edited by doddel on 12 Nov 2009, 16:15)

Hi,

I created the files directory and added a couple of config files (build_dir/files) in a structure (etc/config/..), and I can see them in the installed image, but they seem to be read-only.
I am using squashfs (read-only), but I did'ent expect my config files to be read-only as well.
How do I make them writable? Or should I put them in some other directory

Cheers
-Anders

Sorry, think it was because the disk was full..
Now it seem to work.

Hi, very useful, "build-systems topdir" is same place for run "make" smile (luckily I have the unsquashfs 4 to check any result before flash). Regards.

Hmm.. still something wierd with my image...
Some config files are not overwritten with my files, ex. /etc/config/wireless is keeping the original (same as if reset the device).
But all the other files look okay.
And even if I change /etc/config/wireless it after flash and reboot, the old config comes back.
The /etc/config/wireless is not readonly and I can save them.. but after reboot it changes back.
But only that file..

Why?

Cheers
-Anders

Oh...
Can't find a SQUASHFS superblock on .....

Hmm.. thats why... I guess.. smile
Wonder what this means.. googling.. wink

carlberg wrote:

Oh...
Can't find a SQUASHFS superblock on .....

Hmm.. thats why... I guess.. smile
Wonder what this means.. googling.. wink

Hi, after compiling you have a .squashfs file (.bin is a mix of .vmlinux and .squashfs), on trunk it's squashfs v4.x (same that Ubuntu repositories). I only use it to check, the modifications are best left to the installation scripts for no fuss with symbolic links to devices and access permissions to files (and big-endian and little-endian etc.). Regards.

Well, I need help. neutral
I have tried using unsquashfs on my image and on the .squashfs file, but it just say:
Can't find a SQUASHFS superblock on ...

so I thought I take a working image and see what unsquashfs should say on a ok image.
But no matter which file I run unsquashfs on, it says that it cant find superblock.
I even removed my .config file from image builder and build a totally new image, same thing.

I am missing something, but what? hmm
What is the correct command I should use to check what is wrong with my image? and on which file?
Has this something todo with the kernel version?

(Last edited by carlberg on 28 Jan 2012, 14:00)

Hi, if no match squashfs version, the message is that you say.
Squashfs version need be the same (4.2 on trunk), and on Ubuntu I have Squashfs-tools 1:4.2.1.
Try with: "unsquashfs file.squashfs", i.e. with my router it's "unsquashfs openwrt-ar71xx-generic-root.squashfs" (on trunk/bin/ar71xx after compiling).
For older versions you can find the squashfs code (usually lzma-version), it's a bit more complicated but not impossible.
Regards.

Ok, updated squashfs-tools to 4.2 (ubuntu) and ran: unsquashfs -s xxx.squashfs

output:
Found a valid SQUASHFS 4:0 superblock on openwrt-ar71xx-generic-root.squashfs.
Creation or last append time Sat Jan 28 17:07:56 2012
Filesystem size 2603.17 Kbytes (2.54 Mbytes)
Compression xz
Block size 262144
Filesystem is exportable via NFS
Inodes are compressed
Data is compressed
Fragments are compressed
Always_use_fragments option is not specified
Xattrs are not stored
Duplicates are removed
Number of fragments 25
Number of inodes 1410
Number of ids 1

And it all looks good, right?

Still, when I flash using this image, one of the config files (wireless) goes back to some old config from maybe a previous image I have flashed with long time ago.
But only this file. And even if I change it, after reboot the old config is back.
I even tried deleting the wireless file and rebooted, and then to my supprise another wireless files took it's place, still not the file I have put in the files structure in the image.

I looked in my log to find errors or warnings, and I found this.. dont know if it has anything todo with my problem..
OpenWrt kern.warn kernel: [    0.500000] mtd: partition "kernel" must either start or end on erase block boundary or be smaller than an erase block -- forcing read-only
OpenWrt kern.notice kernel: [    0.510000] 0x0000000f4000-0x0000003f0000 : "rootfs"

Can old stuff from a previous image flash stick on the router somehow?

Hi,
> Can old stuff from a previous image flash stick on the router somehow?
No, all is erased (AFAIK). Bin are a mix (vmlinux, squashfs and jffs2) and .squashfs becomes /rom on your router. Perhaps some initial configuration script is creating the file (maybe a bug), in my case there is no problem with wireless (that I put on trunk/files/etc/config before compiling).
A patch could be: create a wireless file with your settings, i.e. wireless.mimeo, put a command on rc.local for re-write wireless with your file and restart wireless. At least until you discover where the fault. Regards.

The discussion might have continued from here.