// now the cmdline tag
        tag->hdr.tag = ATAG_CMDLINE;
-       // must be at least +3!! 1 for the null and 2 for the ???
-       tag->hdr.size = (strlen(cmdline) + 3 + sizeof(struct tag_header)) >> 2;
-       //tag->hdr.size = (strlen(cmdline) + 10 + sizeof(struct tag_header)) >> 2;
+       // tag header, zero-terminated string and round size to 32-bit words
+       tag->hdr.size = (sizeof (struct tag_header) + strlen (cmdline) + 1 + 3) >> 2;
        strcpy(tag->u.cmdline.cmdline,cmdline);
        tag = tag_next(tag);
 
        initrd[strlen(initrd)-1]=0;
        
        fgets(cmd,200,stream);
-       cmd[strlen(cmd)-1]=0;
+       if (cmd[strlen(cmd)-1] == 0x0a)
+       {
+               cmd[strlen(cmd)-1]=0;
+               if (cmd[strlen(cmd)-2] == 0x0d)
+                       cmd[strlen(cmd)-2]=0;
+       }
 
        fclose(stream);