Skip to content

Commit

Permalink
Add hwprops to set serial number
Browse files Browse the repository at this point in the history
hwprops on early init take /proc/cpuinfo Serial number
and export it to /default.prop ro.serialno property
  • Loading branch information
nopy committed Feb 22, 2012
1 parent 123dbe9 commit de5f92f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
3 changes: 2 additions & 1 deletion betelgeuse.mk
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ PRODUCT_COPY_FILES += \

PRODUCT_PACKAGES := \
make_ext4fs \
com.android.future.usb.accessory
com.android.future.usb.accessory \
hwprops

PRODUCT_PROPERTY_OVERRIDES := \
ro.opengles.version=131072 \
Expand Down
32 changes: 32 additions & 0 deletions hwprops/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2010 Ricardo Cerqueira
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.



LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := hwprops.c

LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
LOCAL_STATIC_LIBRARIES := libcutils libc

LOCAL_MODULE := hwprops
LOCAL_FORCE_STATIC_EXECUTABLE := true

include $(BUILD_EXECUTABLE)

64 changes: 64 additions & 0 deletions hwprops/hwprops.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2011 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/mount.h>

/* Set serialnumber properties on star devices, since they're
* not exported by the bootloader to cmdline as expected */


/* Ugly hack is ugly...
*
* There's a very narrow window in which the hardware properties
* can be written, since init sets them immediately after launching
* the property service, and they can only be set once.
* So our only chance to overwrite them is to set them during that
* launch, by inserting them into default.prop */

int main() {
FILE *fp;
char buf[256];
char serial[32];

if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
return 0;

while(fgets(buf, 256, fp) != NULL) {
if (strstr(buf, "Serial") != NULL) {
strtok(buf, ":");
strncpy(serial, strtok(NULL, " "), 32);
}
}
fclose(fp);

if (serial == NULL)
return 0;

mount("rootfs", "/", "rootfs", MS_REMOUNT|0, NULL);

if ((fp = fopen("/default.prop", "a")) == NULL)
return 0;
sprintf(buf, "ro.serialno=%s", serial);
fputs(buf, fp);
fclose(fp);

//mount("rootfs","/","rootfs",MS_REMOUNT|MS_RDONLY,NULL);

return 0;
}
6 changes: 6 additions & 0 deletions init.betelgeuse.rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import init.nv_dev_board.usb.rc

on early-init
start hwprops

mount debugfs debugfs /sys/kernel/debug

export EXTERNAL_STORAGE /mnt/sdcard
Expand Down Expand Up @@ -140,6 +142,10 @@ service tf_daemon /system/bin/tf_daemon -storageDir /data/tf
group shell
oneshot

service hwprops /sbin/hwprops
disabled
oneshot

#Create data directory and start service
on property:tf.enable=y
mkdir /data/tf
Expand Down

0 comments on commit de5f92f

Please sign in to comment.